zsh-users
 help / color / mirror / code / Atom feed
* Completing multiple states with _arguments
@ 2010-11-09 22:49 Nikolai Weibull
  2010-11-10 10:20 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Nikolai Weibull @ 2010-11-09 22:49 UTC (permalink / raw)
  To: Zsh Users

Hi!

How do I deal with multiple states when completing with _arguments?

local context state line
typeset -A opt_args

_arguments \
  ':: :->something-optional-before-files' \
  '*:: :->file' && ret=0

# Now what?

The documentation doesn’t give an example, neither does the book, and
I was unable to find an example under Completion in the source tree.

I’m updating the git-diff completion (along with all the other git-*
completions), if you want a more specific example.  Git diff can take
two arguments that may be commits, trees, or blobs before it takes any
file arguments.

Thanks!


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

* Re: Completing multiple states with _arguments
  2010-11-09 22:49 Completing multiple states with _arguments Nikolai Weibull
@ 2010-11-10 10:20 ` Peter Stephenson
  2010-11-10 11:23   ` Nikolai Weibull
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2010-11-10 10:20 UTC (permalink / raw)
  To: Zsh Users

On Tue, 9 Nov 2010 23:49:41 +0100
Nikolai Weibull <now@bitwi.se> wrote:

> Hi!
> 
> How do I deal with multiple states when completing with _arguments?
> 
> local context state line
> typeset -A opt_args
> 
> _arguments \
>   ':: :->something-optional-before-files' \
>   '*:: :->file' && ret=0
> 
> # Now what?

Usually you would use "case $state ... esac" to handle the states, with
matches against something-optional-before-files, file, etc.  There are
quite a few uses of this if you search for $state in completion.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


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

* Re: Completing multiple states with _arguments
  2010-11-10 10:20 ` Peter Stephenson
@ 2010-11-10 11:23   ` Nikolai Weibull
  2010-11-10 12:11     ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Nikolai Weibull @ 2010-11-10 11:23 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh Users

On Wed, Nov 10, 2010 at 11:20, Peter Stephenson
<Peter.Stephenson@csr.com> wrote:
> On Tue, 9 Nov 2010 23:49:41 +0100
> Nikolai Weibull <now@bitwi.se> wrote:

>> How do I deal with multiple states when completing with _arguments?
>>
>> local context state line
>> typeset -A opt_args
>>
>> _arguments \
>>   ':: :->something-optional-before-files' \
>>   '*:: :->file' && ret=0
>>
>> # Now what?
>
> Usually you would use "case $state ... esac" to handle the states, with
> matches against something-optional-before-files, file, etc.  There are
> quite a few uses of this if you search for $state in completion.

No, no, $state is (something-optional-before-files file) in this case.

Is it as simple as

local s
for s in $state; do
  case $s in … esac
done

or do you need to deal with tags and such through _alternative or so?


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

* Re: Completing multiple states with _arguments
  2010-11-10 11:23   ` Nikolai Weibull
@ 2010-11-10 12:11     ` Peter Stephenson
  2010-11-10 12:37       ` Nikolai Weibull
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2010-11-10 12:11 UTC (permalink / raw)
  To: Zsh Users

On Wed, 10 Nov 2010 12:23:50 +0100
Nikolai Weibull <now@bitwi.se> wrote:
> >> local context state line
> >> typeset -A opt_args
> >>
> >> _arguments \
> >>   ':: :->something-optional-before-files' \
> >>   '*:: :->file' && ret=0
> >>
> >> # Now what?
> 
> Is it as simple as
> 
> local s
> for s in $state; do
>   case $s in … esac
> done
> 
> or do you need to deal with tags and such through _alternative or so?

I think you do need to set up tags here, at least most scripts do and I
haven't tried without.  However, that should all be standard: looping
over the states is fine, then use the usual _wanted stuff inside the
case and the tags get sorted out automatically, in principle.  There's
nothing to stop you using _alternative, either.

In short, just adding the loop over the state to the sort of stuff that
usually appears in the "case" here should be OK.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


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

* Re: Completing multiple states with _arguments
  2010-11-10 12:11     ` Peter Stephenson
@ 2010-11-10 12:37       ` Nikolai Weibull
  0 siblings, 0 replies; 5+ messages in thread
From: Nikolai Weibull @ 2010-11-10 12:37 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh Users

On Wed, Nov 10, 2010 at 13:11, Peter Stephenson
<Peter.Stephenson@csr.com> wrote:
> On Wed, 10 Nov 2010 12:23:50 +0100
> Nikolai Weibull <now@bitwi.se> wrote:
>> >> local context state line
>> >> typeset -A opt_args
>> >>
>> >> _arguments \
>> >>   ':: :->something-optional-before-files' \
>> >>   '*:: :->file' && ret=0
>> >>
>> >> # Now what?
>>
>> Is it as simple as
>>
>> local s
>> for s in $state; do
>>   case $s in … esac
>> done
>>
>> or do you need to deal with tags and such through _alternative or so?
>
> I think you do need to set up tags here, at least most scripts do and I
> haven't tried without.  However, that should all be standard: looping
> over the states is fine, then use the usual _wanted stuff inside the
> case and the tags get sorted out automatically, in principle.  There's
> nothing to stop you using _alternative, either.
>
> In short, just adding the loop over the state to the sort of stuff that
> usually appears in the "case" here should be OK.

OK, thank you.  I’ll report my findings.


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

end of thread, other threads:[~2010-11-10 12:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-09 22:49 Completing multiple states with _arguments Nikolai Weibull
2010-11-10 10:20 ` Peter Stephenson
2010-11-10 11:23   ` Nikolai Weibull
2010-11-10 12:11     ` Peter Stephenson
2010-11-10 12:37       ` Nikolai Weibull

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).