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

[PATCH v6 3/3] completion: add new zsh completion

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Oct 22, 2012, 01:45 UTC
Message-ID
<1350870342-22653-4-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1350870342-22653-1-git-send-email-felipe.contreras@gmail.com>

It seems there's always issues with zsh's bash completion emulation. I've tried to fix as many as I could and most of the fixes are already in the latest version of zsh, but still, there are issues.

There is no point in going through all that pain; the emulation is easy to achieve, and this patch works better than zsh's emulation.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
v5:
 * Even more simplification by using __gitcompadd
v4:
 * Simplification updates for the latest bash completion
v3:
 * Simplification
 * Avoid COMPREPLY; call compadd directly
 * Fix _get_comp_words_by_ref
 contrib/completion/git-completion.zsh | 48 +++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 contrib/completion/git-completion.zsh
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
new file mode 100644
index 0000000..ae9c532
--- /dev/null
+++ b/contrib/completion/git-completion.zsh
@@ -0,0 +1,48 @@
+#compdef git gitk
+
+# zsh completion wrapper for git
+#
+# You need git's bash completion script installed somewhere, by default on the
+# same directory as this script.
+#
+# If your script is on ~/.git-completion.sh instead, you can configure it on
+# your ~/.zshrc:
+#
+#  zstyle ':completion:*:*:git:*' script ~/.git-completion.sh
+#
+# The recommended way to install this script is to copy to
+# '~/.zsh/completion/_git', and then add the following to your ~/.zshrc file:
+#
+#  fpath=(~/.zsh/completion $fpath)
+
+complete ()
+{
+	# do nothing
+	return 0
+}
+
+zstyle -s ":completion:*:*:git:*" script script
+test -z "$script" && script="$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
+ZSH_VERSION='' . "$script"
+
+__gitcompadd ()
+{
+	compadd -Q -S "$4" -P "${(M)cur#*[=:]}" -p "$2" -- ${=1} && _ret=0
+}
+
+_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
+	}
+	let _ret && _default -S '' && _ret=0
+	return _ret
+}
+
+_git
-- 
1.8.0
Previous: SZEDER GáborNext: Felipe Contreras
Message 7 of 8 in “completion: refactor and zsh wrapper”
  1. 0/3 completion: refactor and zsh wrapperFelipe Contreras, Oct 22, 2012
  2. 1/3 completion: get rid of empty COMPREPLY assignmentsFelipe Contreras, Oct 22, 2012
  3. 2/3 completion: add new __gitcompadd helperFelipe Contreras, Oct 22, 2012
  4. SZEDER GáborOct 30, 2012
  5. Felipe ContrerasOct 30, 2012
  6. SZEDER GáborOct 31, 2012
  7. 3/3 completion: add new zsh completionFelipe Contreras, Oct 22, 2012
  8. Felipe ContrerasOct 30, 2012

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.