From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16743 invoked by alias); 5 Mar 2011 14:15:52 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28862 Received: (qmail 16160 invoked from network); 5 Mar 2011 14:15:50 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at lorien.comfychair.org designates 173.8.144.98 as permitted sender) Date: Sat, 5 Mar 2011 06:15:40 -0800 From: Danek Duvall To: =?utf-8?B?xaB0xJtww6FuIE7Em21lYw==?= Cc: zsh-workers@zsh.org Subject: Re: completing a comma-separated pair of values Message-ID: <20110305141540.GB18627@lorien.comfychair.org> Mail-Followup-To: Danek Duvall , =?utf-8?B?xaB0xJtww6FuIE7Em21lYw==?= , zsh-workers@zsh.org References: <20110303230047.GA12871@lorien.comfychair.org> <20110303235836.GB12871@lorien.comfychair.org> <20110305010019.GA18627@lorien.comfychair.org> <87lj0tordv.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87lj0tordv.fsf@gmail.com> User-Agent: Mutt/1.5.20 (2010-04-22) Štěpán Němec wrote: > Could you prehaps share the result of your endeavor with us? I remember > needing it in the past (not pair exactly, but comma-separated list of > values) and I believe it would be nice to have such functionality among > Zsh completion functions. Here's the function I ended up with: _zfs_keysource_props() { local -a suf local expl compset -P "*," compset -S ",*" || suf=(-S ,) if [[ $words[$CURRENT] == *,* ]]; then _alternative "zfs-keylocator-prompt:\"prompt\" locator:(prompt)" \ "zfs-keylocator-file:file locator:_path_files" else _description format expl "keysource format" compadd $suf -q "$expl[@]" "$@" raw hex passphrase fi } The only problem is that (I think) this may need to be completed in a longer series of comma-separated values: -o foo=bar,keysource=passphrase,prompt,baz=foo I think that if I make the test a little more sophisticated (do I have just one comma after keysource= in the current word), then I might be able to get that behavior. If all you want is a comma-separated list of values (or key/value pairs), then take a look at _values. I have this kind of thing scattered throughout the functions I've written: '-p:property:_values -s , "property" $proplist' where proplist is either something simple like proplist=( "prop1" "prop2" "prop3" ... ) or richer like proplist=( "prop1:desc1:_completion ..." "prop2:desc2:_completion ..." "prop3:desc3:_completion ..." ) Danek