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

PATCH: Re: Problem with _arguments and invalid options



Andrej Borsenkow wrote:

> Currently, invalid (not listed in description) options are not handled very
> nicely. Here is half-hearted example of sudo completion:
> 
> _arguments \
> 	'-V[show version]' \
> 	'-l[list commands]' \
> 	'-h[show help]' \
> 	'-v[validate timestamp file]' \
> 	'-k[remove timestamp file]' \
> 	'-b[run command in background]' \
> 	'-r:Kerberos realm:' \
> 	'-p:prompt:' \
> 	'-u:user name:_users' \
> 	'-s[run SHELL]' \
> 	'-H[set HOME environment variable]' \
> 	'*::complete command and/or arguments:_normal'
> 
> And now
> 
> bor@itsrm2:~/.zsh.d/completion%> sudo -z TAB
> bor@itsrm2:~/.zsh.d/completion%> sudo -z _normal: bad option: -z [33]
> _
> --- file
> _sudo     _umount

That was really caused by the call to `whence' in `_normal'.

> What's worse - if a command does not list `-s', but you *do* give `-s' - it
> seems to be propagated downward and interpreted by _arguments itself (or some
> other function, dunno). Just remove definition for -s from above and try:
> 
> bor@itsrm2:~/.zsh.d/completion%> sudo -u nTAB
> bor@itsrm2:~/.zsh.d/completion%> sudo -u n
> --- user
> nerv     nobody   nuucp
> 
> but
> 
> bor@itsrm2:~/.zsh.d/completion%> sudo -s -u nTAB
> B-e-e-p
> 
> and
> 
> bor@itsrm2:~/.zsh.d/completion%> sudo -s -u TAB
> bor@itsrm2:~/.zsh.d/completion%> sudo -s -u _
> --- file
> _sudo     _umount

(Your first example behaved in the same way, btw.)

Yes, this is intentional: if `_arguments' finds a string that doesn't
look like an option to it, it interprets it as the first argument. Hm, 
I'd like to hear some more comments about this: should we change
`_arguments' to (completely) ignore all strings starting with `-' it
doesn't know? Might be wrong for some commands. And there is the
problem that `_arguments' can handle options starting with `+' and we
probably don't want it to skip over all strings starting with a plus
sign.
Hm. We could make `_arguments' support an option that gives a pattern
and make it ignore all strings on the line matching that pattern. But
how would we decide if we should use the option for a particular
command or not?

Bye
 Sven

diff -u oldcompletion/Core/_normal Completion/Core/_normal
--- oldcompletion/Core/_normal	Mon Sep 13 13:13:15 1999
+++ Completion/Core/_normal	Mon Sep 13 13:18:18 1999
@@ -30,7 +30,7 @@
   if zmodload -e parameter; then
     cmd2="$commands[$command]"
   else
-    cmd2=$(whence -p $command)
+    cmd2=$(whence -p - $command)
   fi
 fi
 

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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