Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: _values and specifying -M to compadd
- X-seq: zsh-users 11873
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: _values and specifying -M to compadd
- Date: Mon, 24 Sep 2007 10:24:25 +0100
- In-reply-to: <20070924050450.GA32335@xxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20070924050450.GA32335@xxxxxxxxxxxxxxxxxxxxx>
Danek Duvall wrote:
> I've spent a couple of hours trying to figure out how to do this, but am
> stumped. I'm working on completion for the Solaris command pfexec, one
> option of which takes an argument of a fixed set of tokens, separated by
> commas, where each token may optionally be prefixed by a "!".
>
> I can do the simple
>
> _values -s , "descr" $tokens
>
> where $tokens was set earlier to be ( $tokens \!$^tokens ), but that's
> cheap, and it doubles the list of tokens, which isn't very nice looking.
> I'd like it to just ignore a "!" when it's there, a la setopt's ignoring of
> "no", but I can't figure out how to make that work with _values, which
> doesn't seem to give an option to pass options (specifically -M) on to
> compadd.
>
> Is there some other reasonably simple way of doing this, or will I have to
> invoke compadd directly?
_values is designed to be smart about the values of key/value pairs,
whereas you need something to be smart about the keys. (_values is
also a bit of a mess because the internals are delegated to a builtin
"compvalues" which is only documented in the C source.)
Actually, using compadd directly isn't that hairy here. I got this to work:
local expl
tokens=(apple banana cucumber date elephant)
# Ignore existing values
compset -P '*,'
# Ignore a leading !, maybe backslash-quoted
compset -P '\\#!'
# Use , as a (removable) separator
_wanted tokens expl 'desription for tokens' compadd -qS , -a tokens
The hairy bit is the pattern that removes a !. Since you need to
quote that with extendedglob, you'd expect things like 'apple,!banana'
and apple,\!banana to be equivalent, but actually for the first you need
to remove ! and for the second you need to remove \!. Previous
experience suggests investigation of this would lead to madness, so
I've just worked around it.
This ought to be enough to make a start. It would obviously get more
complicated if you need key/value pairs as well, but from your
description it sounds like you don't.
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author