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

Re: completing a comma-separated pair of values



Š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



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