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

[PATCH 1/2] complete: zsh: trivial simplification

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 27, 2013, 20:34 UTC
Message-ID
<1367094846-9830-2-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1367094846-9830-1-git-send-email-felipe.contreras@gmail.com>
There should be no functional changes.

The only reason I wrapped this code around a sub-function is because zsh did the same in it's bashcompinit script in order to declare the special variable 'words' as hidden, but only in this context.

There's no need for that any more since we access __git_main directly, so 'words' is not modified, so there's no need for the sub-function.

In zsh mode the array indexes are different though.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index cf8116d..93d8f42 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -72,14 +72,14 @@ __gitcomp_file ()
 _git ()
 {
 	local _ret=1
-	() {
-		emulate -L ksh
-		local cur cword prev
-		cur=${words[CURRENT-1]}
-		prev=${words[CURRENT-2]}
-		let cword=CURRENT-1
-		__${service}_main
-	}
+	local cur cword prev
+
+	cur=${words[CURRENT]}
+	prev=${words[CURRENT-1]}
+	let cword=CURRENT-1
+
+	emulate ksh -c __${service}_main
+
 	let _ret && _default -S '' && _ret=0
 	return _ret
 }
-- 
1.8.2.1.1031.g2ee5873
Previous: Felipe ContrerasNext: Felipe Contreras
Message 2 of 5 in “completion: zsh: nice stuff”
  1. 0/2 completion: zsh: nice stuffFelipe Contreras, Apr 27, 2013
  2. 1/2 complete: zsh: trivial simplificationFelipe Contreras, Apr 27, 2013
  3. 2/2 complete: zsh: use zsh completion for the main cmdFelipe Contreras, Apr 27, 2013
  4. Junio C HamanoApr 27, 2013
  5. Felipe ContrerasApr 27, 2013

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.