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

Re: Completing possible elements of a comma-separated list

Hash: SHA1

On Friday 19 September 2003 15:03, Oliver Kiddle wrote:
> Malte Starostik wrote:
> > I'm trying to write a completion for slptool. One of its commands is
> >     slptool findattrs <service> [attr ids]
> >
> > Now I'd like to continue completion with the same list of possible
> > matches, completing any id in the comma separated list independently of
> > each other against the list of available ids.
> Easiest way is probably to use:
>   _values -s , 'attribute id' $(slptool findattrs ...)
> Otherwise, you can use:
> local -a suf
> compset -P '*,'
> compset -S ',*' || suf=( -S , )
> compadd ... "$suf[@]" ...
> That'll make it ignore anything before the cursor up the last comma
> (and the same in reverse for after the cursor).

Thanks, these both work, the latter a little better as it accepts -M to get 

> > Also, would be nice if
> >     slptool findattrs example.acme u,p<TAB>
> > could complete to
> >     slptool findattrs example.acme username,password,
> > as well.
> That's harder. _sep_parts or _multi_parts might help you. Otherwise, you
> need to start using compadd -O and it gets complicated.

for _multi_parts I'd need to add all possible permutations I gather? Anyway, 
this Works For Me (TM):

    local -a attrs
    local parts
    attrs=($(slptool findattrs $words[2] | \
               perl -pi -e 's#\(([^()]+)=[^()]*\),?#$1\n#g'))
    parts="_sep_parts -M 'm:{a-zA-Z}={A-Za-z}'"
    repeat $[${#attrs}*5] do
        parts="$parts attrs ,";
    eval $parts

*5 is an arbitrary value that allows for listing attributes multiple times. 
Not that useful but allowed and it look like the list can be continued almost 
indefinately :-)
I only wonder why it seems to ignore -M ...

Thanks alot,
- -Malte
Version: GnuPG v1.2.3 (GNU/Linux)


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