zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] completion: don't treat '--' as an option called '-' with _arguments -s
@ 2014-05-08 12:45 m0viefreak
  2014-05-08 13:26 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: m0viefreak @ 2014-05-08 12:45 UTC (permalink / raw)
  To: zsh-workers; +Cc: m0viefreak

Assume the following:

  _foo() { _arguments -s '-a[opt]' '--[end of options]' }

Before this change:

  $ foo --<tab>

would complete to

  $ foo --a

which makes no sense. As a real-world example compare

  $ git diff --ca<tab>

It wrongly offers all the single letter options.

The reason is that the '--' is interpreted as a single letter
option called '-'. Then, with -s given, '-a' and '--' may be
combined to '-a-' or '--a'.

Instead, treat '--' specially and never consider it a single
letter option. This behavior then corresponds to the common
practice of 'end of options' and should be safe, since there
probably isn't any program in existence that actually
uses '--' as a single letter option called '-'.
---
 Src/Zle/computil.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index f5e6ba1..b11c39f 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -1500,9 +1500,11 @@ parse_cadef(char *nam, char **args)
 		nodopts++;
 
 	    /* If this is for single-letter option we also store a
-	     * pointer for the definition in the array for fast lookup. */
+	     * pointer for the definition in the array for fast lookup.
+	     * But don't treat '--' as a single option called '-' */
 
-	    if (single && name[1] && !name[2])
+
+	    if (single && name[1] && !name[2] && name[1] != '-')
 		ret->single[STOUC(name[1])] = opt;
 
 	    if (again == 1) {
@@ -2034,7 +2036,9 @@ ca_parse_line(Cadef d, int multi, int first)
 	    state.optbeg = state.argbeg = state.inopt = cur;
 	    state.argend = argend;
 	    state.singles = (d->single && (!pe || !*pe) &&
-			     state.curopt->name[1] && !state.curopt->name[2]);
+			     state.curopt->name[1] && !state.curopt->name[2] &&
+			     /* Don't treat '--' as a single option called '-' */
+			     state.curopt->name[1] != '-');
 
 	    if (!state.oargs[state.curopt->num])
 		state.oargs[state.curopt->num] = znewlinklist();
-- 
1.9.1.286.g5172cb3


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

* Re: [PATCH] completion: don't treat '--' as an option called '-' with _arguments -s
  2014-05-08 12:45 [PATCH] completion: don't treat '--' as an option called '-' with _arguments -s m0viefreak
@ 2014-05-08 13:26 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2014-05-08 13:26 UTC (permalink / raw)
  To: zsh-workers

On Thu, 08 May 2014 14:45:41 +0200
m0viefreak <m0viefreak.cm@googlemail.com> wrote:
> As a real-world example compare
> 
>   $ git diff --ca<tab>
> 
> It wrongly offers all the single letter options.

Aha!  I've been silently suffering this for ages and thinking "that
can't be right".  I've committed this (and run "git diff --cached" to
look...)

pws


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

end of thread, other threads:[~2014-05-08 13:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-08 12:45 [PATCH] completion: don't treat '--' as an option called '-' with _arguments -s m0viefreak
2014-05-08 13:26 ` Peter Stephenson

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