From: Danek Duvall <duvall@comfychair.org>
To: "Štěpán Němec" <stepnem@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: completing a comma-separated pair of values
Date: Sat, 5 Mar 2011 06:15:40 -0800 [thread overview]
Message-ID: <20110305141540.GB18627@lorien.comfychair.org> (raw)
In-Reply-To: <87lj0tordv.fsf@gmail.com>
Štěpán Němec wrote:
> Could you prehaps share the result of your endeavor with us? I remember
> needing it in the past (not pair exactly, but comma-separated list of
> values) and I believe it would be nice to have such functionality among
> Zsh completion functions.
Here's the function I ended up with:
_zfs_keysource_props() {
local -a suf
local expl
compset -P "*,"
compset -S ",*" || suf=(-S ,)
if [[ $words[$CURRENT] == *,* ]]; then
_alternative "zfs-keylocator-prompt:\"prompt\" locator:(prompt)" \
"zfs-keylocator-file:file locator:_path_files"
else
_description format expl "keysource format"
compadd $suf -q "$expl[@]" "$@" raw hex passphrase
fi
}
The only problem is that (I think) this may need to be completed in a
longer series of comma-separated values:
-o foo=bar,keysource=passphrase,prompt,baz=foo
I think that if I make the test a little more sophisticated (do I have just
one comma after keysource= in the current word), then I might be able to
get that behavior.
If all you want is a comma-separated list of values (or key/value pairs),
then take a look at _values. I have this kind of thing scattered
throughout the functions I've written:
'-p:property:_values -s , "property" $proplist'
where proplist is either something simple like
proplist=( "prop1" "prop2" "prop3" ... )
or richer like
proplist=(
"prop1:desc1:_completion ..."
"prop2:desc2:_completion ..."
"prop3:desc3:_completion ..."
)
Danek
next prev parent reply other threads:[~2011-03-05 14:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-03 23:00 Danek Duvall
2011-03-03 23:27 ` Mikael Magnusson
2011-03-03 23:58 ` Danek Duvall
2011-03-05 1:00 ` Danek Duvall
2011-03-05 9:20 ` Štěpán Němec
2011-03-05 14:15 ` Danek Duvall [this message]
2011-03-06 22:28 ` Oliver Kiddle
2011-03-06 22:59 ` Danek Duvall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110305141540.GB18627@lorien.comfychair.org \
--to=duvall@comfychair.org \
--cc=stepnem@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).