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

Minor issue about zparseopts



I have a function to which I want to pass one or more "filter words". I use
zparseopts for this to specify that -v can be used several times with
different arguments. Below is a simplified version of my function:

filter_stuff() {
    local filter
    local -a filters

    zparseopts -D -E v+:=v || return

    local n=1
    for filter in $v; do
       (( n++ % 2 == 0 )) && filters+=$filter
    done

    # Use $filters...
}

This works fine, I get my filter words in the array $filters. However, it
seems a bit inelegant to me.

1. Why is zparseopts implemented this way? the $v array has "-v" as odd
elements, and the arguments themselves as even elements. It seems a bit
redundant to include the "-v" elements, as I know what I specified the flag
to be.

2. Is there a more elegant way of extracting the "real arguments", i.e. the
even elements of the array, than the one I use above?


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