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

Re: Completing possible elements of a comma-separated list



-----BEGIN PGP SIGNED MESSAGE-----
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 
case-insensitivity.

> > 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 ,";
    done
    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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/ay+CVDF3RdLzx4cRAi1hAJ4zddBRSA23EXXCPQZhc7IhzEKooACgwg2T
rGMDXOsX/KKZivHzFz2gRDs=
=1ACe
-----END PGP SIGNATURE-----



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