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

Re: Completer help wanted

On Sat, 31 Jan 2009 19:55:31 +0100
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> I want to write a _use that lets me complete USE=<tab> on gentoo. I already
> have a _gentoo_packages (which I didn't write) that does it for euse and
> other commands, with code that looks like this:
> _gentoo_packages_update_useflag(){
>     local flags PORTDIR
> 	var=PORTDIR
> 	[[ -z ${(P)var} && -r /etc/make.conf ]] &&
> 	    local $var="`. /etc/make.conf 2>/dev/null; echo ${(P)var}`"
> 	[[ -z ${(P)var} && -r /etc/make.globals ]] &&
> 	    local $var="`. /etc/make.globals 2>/dev/null; echo ${(P)var}`"
>     flags=( ${${(M)${(f)"$(<$PORTDIR/profiles/use.desc)"}:#* - *}%% - *}
>     ${${${(M)${(f)"$(<$PORTDIR/profiles/use.local.desc)"}#* - *}%% - *}#*:} )
>     compadd $flags
> }
> I would not be averse to copying it instead of calling it. This is what
> I got so far,
> #compdef -value-,USE,-default-
> _gentoo_packages useflag
> But it only completes one useflag and goes away. I want to complete several,
> and have them separated by spaces.

Without looking at this in any detail (which I'm not going to do), it
sounds like you're going to have to use "compadd -P <something>" to skip
over what's been added already so that it starts the completion afresh
each time.  The <something> probably ends in a space, possibly "* ".  It
sounds like you you also need space as a removable suffix (compadd -q -S
' ').

In a fully "compliant" completion function you would usually use _wanted
before the compadd to get tag support correct, but that's just the icing
on the cake.

Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/

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