Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Completer help wanted
- X-seq: zsh-users 13794
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-users <zsh-users@xxxxxxxxxx>
- Subject: Re: Completer help wanted
- Date: Sat, 31 Jan 2009 21:23:43 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=SRfwe5btdWk6f3A5VzAKUEat6wW6on9ahydaN5PMlGU=; b=C6V5XrV6UcO5C9m+O5FwZK5RFIcQ1K1bRxVTSWyhxu6/BCHis4DGkNua38mEiEapMG u23/R6ZNoKc1sE9rtIfWjEXtR2/rqx6p8NlobjE66Ltl7gN3UnhIjQHAcDwhs5d239mb Hq0oVTWUrzDZqY48egLagvX/Yi9oEQ+VofgLs=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=eFTGSiclSYmssYXVikIT9GXcu1j9RMRYtH+PuFwJfdYg5SiMLHVomO0ISdKgzGWkqz H7WYnA2DS/TfAiy4FFxYdWfVq5MHwSGSrLaWHZtM05iHROGWuBSFaNjdvvUfEY9mMWwx AeXg05txXqFyEq/0/+JSCZLxsj2oXWiIxjxgY=
- In-reply-to: <20090131200745.41bc6e4a@pws-pc>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <237967ef0901311055x29df9793u2f95e01bb0eff060@xxxxxxxxxxxxxx> <20090131200745.41bc6e4a@pws-pc>
2009/1/31 Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>:
> 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.
Thanks, I think I got it working as well as I need it to. You meant compset
for -P, which took me a few seconds to realize. Here's what I got:
#compdef -value-,USE,-default-
local flags PORTDIR space
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)"}#* - *}%% - *}#*:} )
if [[ -n $compstate[quote] ]]; then
space=' '
else
space='\ '
fi
compset -P "* "
compadd -S $space $flags
Is there some more automagic way to handle the quoting?
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author