git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH for maint] git-completion: fix zsh support

From
Jonathan Nieder <jrnieder@gmail.com>
Date
May 6, 2011, 05:27 UTC
Message-ID
<20110506052744.GA15132@elie>
In-Reply-To
<7v7ha44ej8.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
> Jonathan Nieder <jrnieder@gmail.com> writes:
Show 10 quoted lines
>> Maybe simplest would be to use Szeder's fix + make the zsh version of
>> _get_comp_words_by_ref not overwrite "words" at all?
>
> I do not use zsh myself, but it appears to me that these three-patch
> series can graduate and if real zsh users find problems after using it
> they can be fixed independenty in-tree.
>
> Would that risk too many patch ping-pong among zsh users on 'master'?
> The "don't declare 'local words' in zsh" patch seems to be the right
> work-around for the peculiar semantics of "words" array, at least to me.

Gábor's patches already work. I don't think they will cause breakage or patch ping-pong.

I was trying to imagine Felipe's objection and all I could think of was that it is not so appealing that _get_comp_words_by_ref is not actually writing to "words". For example, the following on top of sg/completion-updates (= 3bee6a4) will print a greeting and the words being completed when you press tab, rather than <foo> <bar> <baz>:

-- >8 --
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -469,7 +469,8 @@ _get_comp_words_by_ref ()
 			prev=${COMP_WORDS[COMP_CWORD-1]}
 			;;
 		words)
-			words=("${COMP_WORDS[@]}")
+			words=(foo bar baz)
+			echo >&2 Greetings
 			;;
 		cword)
 			cword=$COMP_CWORD
@@ -2614,6 +2615,9 @@ _git ()
 
 	local cur cword prev
 	_get_comp_words_by_ref -n =: cur words cword prev
+
+	printf >&2 "WORDS: <%s>\n" "${words[@]}"
+
 	while [ $c -lt $cword ]; do
 		i="${words[c]}"
 		case "$i" in
-- 8< --

In practice it works great since "words" already has the right
content, but maybe the "typeset -h" suggestion was motivated by a
desire to have something easier to explain.

I don't think that's a very strong reason to prevent the fix from
graduating, though I suppose I would be happy to see something like
the following on top at some point.

-- 8< --
Subject: completion: do not pretend to assign to special variable $words on zsh

The special variable $words already has essentially the same meaning
as bash's COMP_WORDS on zsh.  While assigning one to the other appears
to work okay, as a no-op, that is actually an illusion --- the value
of $words can be changed in the _get_comp_words_by_ref function where
it is assigned, but after that function returns, $words is back to
normal.

Guard against future breakage by adding a comment mentioning this and
removing the redundant assignment.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 contrib/completion/git-completion.bash |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 10c1b83..8dfd97f 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -469,7 +469,10 @@ _get_comp_words_by_ref ()
 			prev=${COMP_WORDS[COMP_CWORD-1]}
 			;;
 		words)
-			words=("${COMP_WORDS[@]}")
+			# Nothing to do --- zsh's $words already contains
+			# the list of words being completed (and if we
+			# try to assign to it, the value wouldn't propagate
+			# from this function anyway).
 			;;
 		cword)
 			cword=$COMP_CWORD
-- 
1.7.5.1
Previous: Junio C HamanoNext: Felipe Contreras
Message 8 of 14 in “git-completion: fix zsh support”
  1. git-completion: fix zsh supportFelipe Contreras, May 5, 2011
  2. Junio C HamanoMay 5, 2011
  3. Felipe ContrerasMay 5, 2011
  4. SZEDER GáborMay 5, 2011
  5. git-completion: fix zsh supportFelipe Contreras, May 5, 2011
  6. Jonathan NiederMay 5, 2011
  7. Junio C HamanoMay 6, 2011
  8. Jonathan NiederMay 6, 2011
  9. Felipe ContrerasMay 6, 2011
  10. Felipe ContrerasMay 6, 2011
  11. Jonathan NiederMay 6, 2011
  12. Jonathan NiederMay 6, 2011
  13. Felipe ContrerasMay 9, 2011
  14. Jonathan NiederMay 6, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.