zsh-workers
 help / color / mirror / code / Atom feed
* completing a comma-separated pair of values
@ 2011-03-03 23:00 Danek Duvall
  2011-03-03 23:27 ` Mikael Magnusson
  0 siblings, 1 reply; 8+ messages in thread
From: Danek Duvall @ 2011-03-03 23:00 UTC (permalink / raw)
  To: zsh-workers

I'm not sure if this is something I can do with the stock completion
widgets, and I can't think of any examples of this off the top of my head,
but what I need to be able to do is to complete a comma-separated pair of
values, where the order is important, and one side needs more complicated
completion (takes a path).  That is:

    property=value1,value2

I can almost get this with _values, but it requires the values to be in the
form <key>[<kvsep><value>], rather than <value>, and I can't simply make
the values keys.

Am I making any sense?  Do I have to write a copy of _values to do this?

Also, is there any way to make the "=" separator _values uses elide with
the "=" you type to finish (menu) completing?  For instance, if I have
properties prop1, prop2, and prop3, and I type:

    prop<TAB>

I get

    prop1=

and I can cycle through the three by hitting tab, but if I want to start
completing on the value of propN, I have to type something and the
backspace over it, rather than just hitting "=", like I would hit "/" if I
were completing through the directory heirarchy.

Thanks,
Danek


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: completing a comma-separated pair of values
  2011-03-03 23:00 completing a comma-separated pair of values Danek Duvall
@ 2011-03-03 23:27 ` Mikael Magnusson
  2011-03-03 23:58   ` Danek Duvall
  0 siblings, 1 reply; 8+ messages in thread
From: Mikael Magnusson @ 2011-03-03 23:27 UTC (permalink / raw)
  To: Danek Duvall, zsh-workers

On 4 March 2011 00:00, Danek Duvall <duvall@comfychair.org> wrote:
> I'm not sure if this is something I can do with the stock completion
> widgets, and I can't think of any examples of this off the top of my head,
> but what I need to be able to do is to complete a comma-separated pair of
> values, where the order is important, and one side needs more complicated
> completion (takes a path).  That is:
>
>    property=value1,value2
>
> I can almost get this with _values, but it requires the values to be in the
> form <key>[<kvsep><value>], rather than <value>, and I can't simply make
> the values keys.
>
> Am I making any sense?  Do I have to write a copy of _values to do this?

I'm about to go to bed and didn't read that carefully, but do you want
_dir_list -s , maybe?

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: completing a comma-separated pair of values
  2011-03-03 23:27 ` Mikael Magnusson
@ 2011-03-03 23:58   ` Danek Duvall
  2011-03-05  1:00     ` Danek Duvall
  0 siblings, 1 reply; 8+ messages in thread
From: Danek Duvall @ 2011-03-03 23:58 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-workers

On Fri, Mar 04, 2011 at 12:27:25AM +0100, Mikael Magnusson wrote:

> I'm about to go to bed and didn't read that carefully, but do you want
> _dir_list -s , maybe?

I'll have to approach that with a fresh brain, I think, but I'll take a
look.  It seems to me that it merely completes directories separated by a
separator character.  It doesn't help you if you want one of three
directories before the separator and either a particular directory or any
directory under another after the separator (and only one separator).  I'm
not completing directories, of course, but words, so it's not quite as
silly in real life as it sounds.  :)

I may have to roll my own with compadd and compset, but I was hoping to be
able to take advantage of _alternate for the second value, as it nicely
separates the two possibilities (fixed word vs path) with tags.  I'm sure
it's doable using the underlying bits, too, but I'm guessing this is going
to get complicated.

Thanks,
Danek


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: completing a comma-separated pair of values
  2011-03-03 23:58   ` Danek Duvall
@ 2011-03-05  1:00     ` Danek Duvall
  2011-03-05  9:20       ` Štěpán Němec
  0 siblings, 1 reply; 8+ messages in thread
From: Danek Duvall @ 2011-03-05  1:00 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-workers

On Thu, Mar 03, 2011 at 03:58:36PM -0800, Danek Duvall wrote:

> On Fri, Mar 04, 2011 at 12:27:25AM +0100, Mikael Magnusson wrote:
> 
> > I'm about to go to bed and didn't read that carefully, but do you want
> > _dir_list -s , maybe?
> 
> I'll have to approach that with a fresh brain, I think, but I'll take a
> look.

After some prodding by Oliver, I managed to get this to work, and it did
indeed look a bit like _dir_list.

Thanks,
Danek


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: completing a comma-separated pair of values
  2011-03-05  1:00     ` Danek Duvall
@ 2011-03-05  9:20       ` Štěpán Němec
  2011-03-05 14:15         ` Danek Duvall
  0 siblings, 1 reply; 8+ messages in thread
From: Štěpán Němec @ 2011-03-05  9:20 UTC (permalink / raw)
  To: Danek Duvall; +Cc: Mikael Magnusson, zsh-workers

Danek Duvall <duvall@comfychair.org> writes:

> After some prodding by Oliver, I managed to get this to work, and it did
> indeed look a bit like _dir_list.

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.

  Štěpán


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: completing a comma-separated pair of values
  2011-03-05  9:20       ` Štěpán Němec
@ 2011-03-05 14:15         ` Danek Duvall
  2011-03-06 22:28           ` Oliver Kiddle
  0 siblings, 1 reply; 8+ messages in thread
From: Danek Duvall @ 2011-03-05 14:15 UTC (permalink / raw)
  To: Štěpán Němec; +Cc: zsh-workers

Š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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: completing a comma-separated pair of values
  2011-03-05 14:15         ` Danek Duvall
@ 2011-03-06 22:28           ` Oliver Kiddle
  2011-03-06 22:59             ` Danek Duvall
  0 siblings, 1 reply; 8+ messages in thread
From: Oliver Kiddle @ 2011-03-06 22:28 UTC (permalink / raw)
  To: Danek Duvall, Štěpán Němec, zsh-workers

Danek Duvall wrote:
> 
> Here's the function I ended up with:
> 
> 	    if [[ $words[$CURRENT] == *,* ]]; then

I may have misunderstood this but you can use the return status of
compset -P directly so that you possibly don't need this. e.g:
	if compset -P '*,'; then

> The only problem is that (I think) this may need to be completed in a
> longer series of comma-separated values:

You can also do a while loop if there's no particular ordering to
things in the list: while compset -P '*,' Otherwise, use elif for each
component.

Oliver


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: completing a comma-separated pair of values
  2011-03-06 22:28           ` Oliver Kiddle
@ 2011-03-06 22:59             ` Danek Duvall
  0 siblings, 0 replies; 8+ messages in thread
From: Danek Duvall @ 2011-03-06 22:59 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers

Oliver Kiddle wrote:

> I may have misunderstood this but you can use the return status of
> compset -P directly so that you possibly don't need this. e.g:
> 	if compset -P '*,'; then

Indeed; thanks.  I've also added the optional number 1 to -P, which means
that it'll prevent you from trying to put a second comma on there and
continue completing.

> > The only problem is that (I think) this may need to be completed in a
> > longer series of comma-separated values:
> 
> You can also do a while loop if there's no particular ordering to things
> in the list: while compset -P '*,' Otherwise, use elif for each
> component.

There's an ordering to the arguments of keysource, but not to the list of
things that keysource is in.  So we could have

    foo=64,bar,keysource=passphrase,prompt,baz=true

or
    foo=64,keysource=passphrase,prompt,bar,baz=true

etc.  I want to complete the two comma-separated values after keysource=
with my function, but everything else in this list would be handled
naturally by _values, as if keysource took only a single argument.

Danek


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-03-06 22:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-03 23:00 completing a comma-separated pair of values Danek Duvall
2011-03-03 23:27 ` Mikael Magnusson
2011-03-03 23:58   ` Danek Duvall
2011-03-05  1:00     ` Danek Duvall
2011-03-05  9:20       ` Štěpán Němec
2011-03-05 14:15         ` Danek Duvall
2011-03-06 22:28           ` Oliver Kiddle
2011-03-06 22:59             ` Danek Duvall

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).