Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Filtering array on index



On 26 Oct 2018, at 02:59, Jesper Nygårds <jesper.nygards@xxxxxxxxx> wrote:
>The following doesn't quite do what I want, since I can find no way of
>specifying that I want the "-f" prefix removed from the elements in
>$overrides, before its elements are then removed from the $filter list:
>
>% filters=(); overrides=()
>% set -- -v one -v two -f one
>% zparseopts -D -E v+:-=filters f+:-=overrides
>% print -lr -- ${${filters#-v}:|overrides}
>one
>two
>
>(I wanted only "one" to be printed)

If the idea is to remove the overrides from the filters, shouldn't you have
wanted only 'two' printed?

If so, i guess this might qualify as 'compact':

  ${filters:#${~:-(${(j<|>)${(b)overrides/#-f/-v}})}}

Add (M) to the outer expansion if you want it the other way around

And if you still need the -v removed when you're done, just wrap the whole thing
in ${...#-v}

dana



Messages sorted by: Reverse Date, Date, Thread, Author