Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Minor issue about zparseopts
- X-seq: zsh-users 19020
- From: Jesper Nygårds <jesper.nygards@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Minor issue about zparseopts
- Date: Tue, 19 Aug 2014 20:47:59 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=1tlJzS4fxBr/aAMYxQWF+kTsqJzH0jUTiYVP4o1tKEg=; b=KIl8/1PDgXfqjFSDaSDqvzDb35zk9C3TDKj4koH3D8NIR2ArcgD+RzJcn1bfKs3OA0 XaeVKotWDnURMcJawU4I8C+Ct8B3G9cn22X/i4OD1+OaJNCfjZyS9pnUueT6Dutqjtap GS7WIu3rp8XjAmj7uuPEcjZRKAOtLLRR8/FmdT+zntPO9GJJdzeeD0a9s+J1ASj86/0a AVn9w6ARG+hbyb1bb0qvDsvsEjJUqgxKk8+XFr1Tw79E03NNUS62b87cE46lPlICG4fK u8l499w98fk+YB70PnwkIh5HzzIGuVG8mc9MhSI0goOp0V81Q6DTu80dpGZbzAtlP4VW GTBw==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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