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

Re: Problem with _arguments



"Nikolai Weibull" wrote:
> Say that I have
> 
> #compdef craptastic
> 
> _arguments \
>   '-s[omething]:with an argument' \
>   '*:directory:_directories'
> 
> Then, at least with my setup, if I have the following command line and
> press <Tab> I get:
> 
> % craptastic -s <Tab>
> ::: with an argument :::
> 
> but if I have the following and press <Tab> I get:
> 
> % craptastic src -s <Tab>
> ::: with an argument :::
> ::: directory :::
> 
> Why is directory all of a sudden a viable option here?

   _arguments [ -nswWACRS ] [ -O name ] [ -M matchspec ] [ : ] spec ...
          This function can be used to give a complete  specification  for
          completion  for  a  command whose arguments follow standard UNIX
          option and argument conventions.

"Standard UNIX option and argument conventions" are that all options
come before all non-option arguments.  The GNU extension that they can
occur in any order is not supported.  So -s is an argument following the
argument src.  _arguments thinks src, -s and the argument you're now
completing are normal arguments and hence completes directories.

Offers to add the option for the GNU extension as an option to
_arguments to be applied if POSIXLY_CORRECT isn't set will be gladly
accepted.  Volunteer must like murky code with limited comments.  The
ability to spend hours puzzling over why individual lines are written
the way they are would be an advantage.

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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