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

Re: Complicated Completions

David Remahl wrote:
> Thanks for your help!
> I've now gotten started on something that I hope will work out...But  
> why doesn't this work? I have only written a small part of the  
> completion, for just the attach subcommand (verb). Try this:
> type: hdiutil attach abc.dmg <tab>
> Why doesn't it show the three switches -quiet, -debug and -verbose?

_arguments looks at the $words array and expects to find the command
name in the first element and other arguments thereafter. So in this
case, you need to add:
  shift 2 words
  (( CURRENT-=2 ))
before the call to _arguments.

Is it not possible for the -quiet, -debug and -verbose options to
appear before the .dmg file on the command-line though?

If so, you should be able to use just:

    shift words
    (( CURRENT-- ))
    _arguments \
       '(-quiet -debug)-verbose' \
       '(-verbose -debug)-quiet' \
       '(-quiet -verbose)-debug' \
       '1:disk image file:_files -g  "*.(dmg|img|smi|dmgz)"' && ret=0


I you are wondering why _xauth and _sccs don't need to shift the words
array, it is because they they have a previous call to
_arguments with this rule:
       '*::command:->subcmd' && ret=0

And the documentation for *::MESSAGE:ACTION spec says:

          With two colons before the MESSAGE, the words special array
          and the CURRENT special parameter are modified to refer only
          to the normal arguments when the ACTION is executed or

>      curcontext="${curcontext%:*:*}:xauth-${cmd}:"

don't forget to change xauth to hdiutil

>              if (( CURRENT == 3 )); then
>                  _arguments \
>                      '2:disk image file:_files -g "*.(dmg|img|smi|dmgz)"' && ret=0

If this does need to stay (if the switches can only be after the .dmg
file), then you can write it as:

  _wanted files expl 'disc image file' \
      _files -g "*.(dmg|img|smi|dmgz)" && ret=0

>                           _arguments \
>                               '(-quiet -debug)-verbose'
>                               '(-verbose -debug)-quiet'

Don't forget the backslash (\) at the end of each of these lines so
that it knows to continue on the next line. I expect you copied this
over from the alwaysargs array assignment where you don't need them.


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