git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v2 00/29] completion: zsh: latest patches
@ 2020-10-25  3:13 Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 01/29] completion: zsh: fix __gitcomp_direct() Felipe Contreras
                   ` (29 more replies)
  0 siblings, 30 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

Hi,

I've been carrying around these patches for quite some time, many have already
been sent, others I refactored to make them more clear.

But what is clear is that they are needed. I see a lot of people in different
forums (e.g. Stack Overflow, Oh-My-Zsh, etc.) getting bit by many of these
issues.

I've created an independent project to keep my sanity while maintaining these
patches, but for what it's worth, I've transplanted them to Git upstream.

https://github.com/felipec/git-completion

There's also a lot of information in the README apparently scattered
everywhere, but it's good to have in one place.

Cheers.


Felipe Contreras (29):
  completion: zsh: fix __gitcomp_direct()
  completion: zsh: fix name due to broken autoloading
  completion: zsh: fix bash script extension
  completion: zsh: reorganize install instructions
  completion: zsh: fix for directories with spaces
  completion: zsh: update slave script locations
  completion: prompt: fix color for Zsh
  completion: zsh: fix for command aliasing
  completion: bash: synchronize zsh wrapper
  completion: bash: remove zsh wrapper
  completion: zsh: fix completion for --no-.. options
  completion: fix conflict with bashcomp
  completion: zsh: add missing direct_append
  completion: zsh: fix splitting of words
  completion: zsh: simplify compadd functions
  completion: zsh: simplify direct compadd
  completion: zsh: trivial cleanup
  completion: zsh: simplify nl_append
  completion: zsh: simplify file_direct
  completion: zsh: shuffle functions around
  completion: zsh: refactor command completion
  completion: zsh: improve command tags
  completion: zsh: add alias descriptions
  completion: zsh: trivial simplification
  completion: zsh: add simple version check
  completion: bash: trivial cleanup
  completion: bash: cleanup cygwin check
  completion: bash: remove old compat wrappers
  Update copyright notices

 contrib/completion/git-completion.bash | 114 +++------------------
 contrib/completion/git-completion.zsh  | 132 ++++++++++++++++---------
 contrib/completion/git-prompt.sh       |  11 ++-
 t/t9902-completion.sh                  |   2 +-
 4 files changed, 105 insertions(+), 154 deletions(-)

-- 
2.29.0


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

* [PATCH v2 01/29] completion: zsh: fix __gitcomp_direct()
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 02/29] completion: zsh: fix name due to broken autoloading Felipe Contreras
                   ` (28 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

Many callers append a space suffix, but zsh automatically appends a
space, making the completion add two spaces, for example:

  git log ma<tab>

Will complete 'master  '.

Let's remove that extra space.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 2 +-
 contrib/completion/git-completion.zsh  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 0a96ad87e7..ec7dd12a41 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3498,7 +3498,7 @@ if [[ -n ${ZSH_VERSION-} ]] &&
 
 		local IFS=$'\n'
 		compset -P '*[=:]'
-		compadd -Q -- ${=1} && _ret=0
+		compadd -Q -- ${${=1}% } && _ret=0
 	}
 
 	__gitcomp_nl ()
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index ce47e86b60..2cefae943a 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -74,7 +74,7 @@ __gitcomp_direct ()
 
 	local IFS=$'\n'
 	compset -P '*[=:]'
-	compadd -Q -- ${=1} && _ret=0
+	compadd -Q -- ${${=1}% } && _ret=0
 }
 
 __gitcomp_nl ()
-- 
2.29.0


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

* [PATCH v2 02/29] completion: zsh: fix name due to broken autoloading
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 01/29] completion: zsh: fix __gitcomp_direct() Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 03/29] completion: zsh: fix bash script extension Felipe Contreras
                   ` (27 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras, Maxim Belsky,
	Johannes Schindelin

Commit 176f5adfdb wrongly changed the installation path to
'~/.zsh/git-completion.zsh', this ensures the script is not
automatically loaded.

The whole point of adding the script to the fpath variable is that it's
autoloaded after typing 'git<tab>', which won't happen unless it's named
_git.

I've changed the wording so it's crystal clear the name of the file
*must* be '_git'.

http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Autoloaded-files

Cc: Maxim Belsky <public.belsky@gmail.com>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 2cefae943a..6d451355fd 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -11,9 +11,11 @@
 #
 #  zstyle ':completion:*:*:git:*' script ~/.git-completion.zsh
 #
-# The recommended way to install this script is to make a copy of it in
-# ~/.zsh/ directory as ~/.zsh/git-completion.zsh and then add the following
-# to your ~/.zshrc file:
+# The recommended way to install this script is to make a copy of it as a
+# file named '_git' inside any directory in your fpath.
+#
+# For example, create a directory '~/.zsh/', copy this file to '~/.zsh/_git',
+# and then add the following to your ~/.zshrc file:
 #
 #  fpath=(~/.zsh $fpath)
 
-- 
2.29.0


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

* [PATCH v2 03/29] completion: zsh: fix bash script extension
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 01/29] completion: zsh: fix __gitcomp_direct() Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 02/29] completion: zsh: fix name due to broken autoloading Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 04/29] completion: zsh: reorganize install instructions Felipe Contreras
                   ` (26 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras,
	Peter van der Does

Commit 0e5ed7cca3 wrongly changed the extension of the bash script
to .zsh; the zstyle configuration is for the slave script (bash), not
the master one (zsh).

For example it could be:

  zstyle ':completion:*:*:git:*' script ~/.git-completion.bash

The extension doesn't really matter, but it confuses people into
thinking it's a zsh script; it's not.

Cc: Peter van der Does <peter@avirtualhome.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 6d451355fd..712ce2f4d1 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -9,7 +9,7 @@
 #
 # If your script is somewhere else, you can configure it on your ~/.zshrc:
 #
-#  zstyle ':completion:*:*:git:*' script ~/.git-completion.zsh
+#  zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
 #
 # The recommended way to install this script is to make a copy of it as a
 # file named '_git' inside any directory in your fpath.
-- 
2.29.0


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

* [PATCH v2 04/29] completion: zsh: reorganize install instructions
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (2 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 03/29] completion: zsh: fix bash script extension Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 05/29] completion: zsh: fix for directories with spaces Felipe Contreras
                   ` (25 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

Start with the most important thing; the proper location of this script,
then follow with the location of the slave script (git-completion.bash).

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 712ce2f4d1..05ccaac194 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -4,13 +4,6 @@
 #
 # Copyright (c) 2012-2013 Felipe Contreras <felipe.contreras@gmail.com>
 #
-# You need git's bash completion script installed somewhere, by default it
-# would be the location bash-completion uses.
-#
-# If your script is somewhere else, you can configure it on your ~/.zshrc:
-#
-#  zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
-#
 # The recommended way to install this script is to make a copy of it as a
 # file named '_git' inside any directory in your fpath.
 #
@@ -18,6 +11,15 @@
 # and then add the following to your ~/.zshrc file:
 #
 #  fpath=(~/.zsh $fpath)
+#
+# You need git's bash completion script installed. By default bash-completion's
+# location will be used (e.g. /usr/share/bash-completion/completions/git).
+#
+# If your bash completion script is somewhere else, you can specify the
+# location in your ~/.zshrc:
+#
+#  zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
+#
 
 complete ()
 {
-- 
2.29.0


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

* [PATCH v2 05/29] completion: zsh: fix for directories with spaces
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (3 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 04/29] completion: zsh: reorganize install instructions Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 06/29] completion: zsh: update slave script locations Felipe Contreras
                   ` (24 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 05ccaac194..5d6740c6ff 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -35,7 +35,7 @@ if [ -z "$script" ]; then
 	local -a locations
 	local e
 	locations=(
-		$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
+		"$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
 		'/etc/bash_completion.d/git' # fedora, old debian
 		'/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
 		'/usr/share/bash-completion/git' # gentoo
-- 
2.29.0


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

* [PATCH v2 06/29] completion: zsh: update slave script locations
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (4 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 05/29] completion: zsh: fix for directories with spaces Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 07/29] completion: prompt: fix color for Zsh Felipe Contreras
                   ` (23 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

Update the default locations of typical system bash-completion,
including the default bash-completion location for user scripts, and the
recommended way to find the system location (with pkg-config).

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 5d6740c6ff..ba41525373 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -13,7 +13,7 @@
 #  fpath=(~/.zsh $fpath)
 #
 # You need git's bash completion script installed. By default bash-completion's
-# location will be used (e.g. /usr/share/bash-completion/completions/git).
+# location will be used (e.g. pkg-config --variable=completionsdir bash-completion).
 #
 # If your bash completion script is somewhere else, you can specify the
 # location in your ~/.zshrc:
@@ -36,9 +36,10 @@ if [ -z "$script" ]; then
 	local e
 	locations=(
 		"$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
-		'/etc/bash_completion.d/git' # fedora, old debian
-		'/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
-		'/usr/share/bash-completion/git' # gentoo
+		"$HOME/.local/share/bash-completion/completions/git"
+		"$(pkg-config --variable=completionsdir bash-completion)"/git
+		'/usr/share/bash-completion/completions/git'
+		'/etc/bash_completion.d/git' # old debian
 		)
 	for e in $locations; do
 		test -f $e && script="$e" && break
-- 
2.29.0


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

* [PATCH v2 07/29] completion: prompt: fix color for Zsh
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (5 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 06/29] completion: zsh: update slave script locations Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 08/29] completion: zsh: fix for command aliasing Felipe Contreras
                   ` (22 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

We don't need PROMPT_COMMAND in Zsh; we are already using %F{color} %f,
which in turn use %{ and %}, which are the equivalent of Bash's
\[ and \].

We can use as many colors as we want and output directly into PS1
(or RPS1) without the risk of buffer wrapping issues.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-prompt.sh | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 16260bab73..54e123d632 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -97,7 +97,8 @@
 # If you would like a colored hint about the current dirty state, set
 # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
 # the colored output of "git status -sb" and are available only when
-# using __git_ps1 for PROMPT_COMMAND or precmd.
+# using __git_ps1 for PROMPT_COMMAND or precmd in Bash,
+# but always available in Zsh.
 #
 # If you would like __git_ps1 to do nothing in the case when the current
 # directory is set up to be ignored by git, then set
@@ -553,9 +554,11 @@ __git_ps1 ()
 
 	local z="${GIT_PS1_STATESEPARATOR-" "}"
 
-	# NO color option unless in PROMPT_COMMAND mode
-	if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
-		__git_ps1_colorize_gitstring
+	# NO color option unless in PROMPT_COMMAND mode or it's Zsh
+	if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
+		if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then
+			__git_ps1_colorize_gitstring
+		fi
 	fi
 
 	b=${b##refs/heads/}
-- 
2.29.0


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

* [PATCH v2 08/29] completion: zsh: fix for command aliasing
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (6 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 07/29] completion: prompt: fix color for Zsh Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 09/29] completion: bash: synchronize zsh wrapper Felipe Contreras
                   ` (21 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

A lot of people want to define aliases like gc='git commit', and zsh
allows that (when not using 'complete_aliases'), but we need to handle
services that call a function other than the main one.

With this patch we can do:

  compdef _git gc=git_commit

Additionally, add compatibility for Zsh Git functions which have the
form git-commit (with dash, not underscore).

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index ba41525373..17041d0b23 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -240,8 +240,12 @@ _git ()
 
 	if (( $+functions[__${service}_zsh_main] )); then
 		__${service}_zsh_main
-	else
+	elif (( $+functions[__${service}_main] )); then
 		emulate ksh -c __${service}_main
+	elif (( $+functions[_${service}] )); then
+		emulate ksh -c _${service}
+	elif ((	$+functions[_${service//-/_}] )); then
+		emulate ksh -c _${service//-/_}
 	fi
 
 	let _ret && _default && _ret=0
-- 
2.29.0


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

* [PATCH v2 09/29] completion: bash: synchronize zsh wrapper
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (7 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 08/29] completion: zsh: fix for command aliasing Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 10/29] completion: bash: remove " Felipe Contreras
                   ` (20 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

A function was missing.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index ec7dd12a41..40affd40e2 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3510,6 +3510,14 @@ if [[ -n ${ZSH_VERSION-} ]] &&
 		compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
 	}
 
+	__gitcomp_nl_append ()
+	{
+		emulate -L zsh
+
+		local IFS=$'\n'
+		compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
+	}
+
 	__gitcomp_file_direct ()
 	{
 		emulate -L zsh
-- 
2.29.0


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

* [PATCH v2 10/29] completion: bash: remove zsh wrapper
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (8 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 09/29] completion: bash: synchronize zsh wrapper Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 11/29] completion: zsh: fix completion for --no-.. options Felipe Contreras
                   ` (19 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

It has been deprecated for more than eight years now, it's never up to
date, and it's a hassle to maintain.

It's time to move on.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 92 +-------------------------
 1 file changed, 2 insertions(+), 90 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 40affd40e2..26d6ee20b0 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3458,96 +3458,8 @@ __gitk_main ()
 	__git_complete_revlist
 }
 
-if [[ -n ${ZSH_VERSION-} ]] &&
-   # Don't define these functions when sourced from 'git-completion.zsh',
-   # it has its own implementations.
-   [[ -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
-	echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
-
-	autoload -U +X compinit && compinit
-
-	__gitcomp ()
-	{
-		emulate -L zsh
-
-		local cur_="${3-$cur}"
-
-		case "$cur_" in
-		--*=)
-			;;
-		*)
-			local c IFS=$' \t\n'
-			local -a array
-			for c in ${=1}; do
-				c="$c${4-}"
-				case $c in
-				--*=*|*.) ;;
-				*) c="$c " ;;
-				esac
-				array[${#array[@]}+1]="$c"
-			done
-			compset -P '*[=:]'
-			compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
-			;;
-		esac
-	}
-
-	__gitcomp_direct ()
-	{
-		emulate -L zsh
-
-		local IFS=$'\n'
-		compset -P '*[=:]'
-		compadd -Q -- ${${=1}% } && _ret=0
-	}
-
-	__gitcomp_nl ()
-	{
-		emulate -L zsh
-
-		local IFS=$'\n'
-		compset -P '*[=:]'
-		compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
-	}
-
-	__gitcomp_nl_append ()
-	{
-		emulate -L zsh
-
-		local IFS=$'\n'
-		compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
-	}
-
-	__gitcomp_file_direct ()
-	{
-		emulate -L zsh
-
-		local IFS=$'\n'
-		compset -P '*[=:]'
-		compadd -f -- ${=1} && _ret=0
-	}
-
-	__gitcomp_file ()
-	{
-		emulate -L zsh
-
-		local IFS=$'\n'
-		compset -P '*[=:]'
-		compadd -p "${2-}" -f -- ${=1} && _ret=0
-	}
-
-	_git ()
-	{
-		local _ret=1 cur cword prev
-		cur=${words[CURRENT]}
-		prev=${words[CURRENT-1]}
-		let cword=CURRENT-1
-		emulate ksh -c __${service}_main
-		let _ret && _default && _ret=0
-		return _ret
-	}
-
-	compdef _git git gitk
+if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
+	echo "ERROR: this script is obsolete, please see git-completion.zsh" 1>&2
 	return
 fi
 
-- 
2.29.0


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

* [PATCH v2 11/29] completion: zsh: fix completion for --no-.. options
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (9 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 10/29] completion: bash: remove " Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 12/29] completion: fix conflict with bashcomp Felipe Contreras
                   ` (18 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

This was introduced in upstream's bash script, but never in zsh's:

  b221b5ab9b (completion: collapse extra --no-.. options)

It has been failing since v2.19.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 17041d0b23..c2a90beb8b 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -56,10 +56,32 @@ __gitcomp ()
 	case "$cur_" in
 	--*=)
 		;;
+	--no-*)
+		local c IFS=$' \t\n'
+		local -a array
+		for c in ${=1}; do
+			if [[ $c == "--" ]]; then
+				continue
+			fi
+			c="$c${4-}"
+			case $c in
+			--*=|*.) ;;
+			*) c="$c " ;;
+			esac
+			array+=("$c")
+		done
+		compset -P '*[=:]'
+		compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
+		;;
 	*)
 		local c IFS=$' \t\n'
 		local -a array
 		for c in ${=1}; do
+			if [[ $c == "--" ]]; then
+				c="--no-...${4-}"
+				array+=("$c ")
+				break
+			fi
 			c="$c${4-}"
 			case $c in
 			--*=*|*.) ;;
-- 
2.29.0


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

* [PATCH v2 12/29] completion: fix conflict with bashcomp
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (10 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 11/29] completion: zsh: fix completion for --no-.. options Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 13/29] completion: zsh: add missing direct_append Felipe Contreras
                   ` (17 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras, Mark Lodato

We don't want to override the 'complete()' function in zsh, which can be
used by bashcomp.

Reported-by: Mark Lodato <lodato@google.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 1 +
 contrib/completion/git-completion.zsh  | 6 ------
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 26d6ee20b0..6de0e7b482 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3475,6 +3475,7 @@ __git_func_wrap ()
 # This is NOT a public function; use at your own risk.
 __git_complete ()
 {
+	test -n "$ZSH_VERSION" && return
 	local wrapper="__git_wrap${2}"
 	eval "$wrapper () { __git_func_wrap $2 ; }"
 	complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index c2a90beb8b..1de9b9c80d 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -21,12 +21,6 @@
 #  zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
 #
 
-complete ()
-{
-	# do nothing
-	return 0
-}
-
 zstyle -T ':completion:*:*:git:*' tag-order && \
 	zstyle ':completion:*:*:git:*' tag-order 'common-commands'
 
-- 
2.29.0


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

* [PATCH v2 13/29] completion: zsh: add missing direct_append
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (11 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 12/29] completion: fix conflict with bashcomp Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 14/29] completion: zsh: fix splitting of words Felipe Contreras
                   ` (16 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

Commit 688077910b forgot to add the corresponding zsh function.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 1de9b9c80d..13c6bd5c12 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -98,6 +98,11 @@ __gitcomp_direct ()
 	compadd -Q -- ${${=1}% } && _ret=0
 }
 
+__gitcomp_direct_append ()
+{
+	__gitcomp_direct "$@"
+}
+
 __gitcomp_nl ()
 {
 	emulate -L zsh
-- 
2.29.0


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

* [PATCH v2 14/29] completion: zsh: fix splitting of words
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (12 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 13/29] completion: zsh: add missing direct_append Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 15/29] completion: zsh: simplify compadd functions Felipe Contreras
                   ` (15 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

Files don't need to be split by '=:', words do.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 13c6bd5c12..088bf7f759 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -117,6 +117,7 @@ __gitcomp_nl_append ()
 	emulate -L zsh
 
 	local IFS=$'\n'
+	compset -P '*[=:]'
 	compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
 }
 
@@ -125,7 +126,6 @@ __gitcomp_file_direct ()
 	emulate -L zsh
 
 	local IFS=$'\n'
-	compset -P '*[=:]'
 	compadd -f -- ${=1} && _ret=0
 }
 
@@ -134,7 +134,6 @@ __gitcomp_file ()
 	emulate -L zsh
 
 	local IFS=$'\n'
-	compset -P '*[=:]'
 	compadd -p "${2-}" -f -- ${=1} && _ret=0
 }
 
-- 
2.29.0


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

* [PATCH v2 15/29] completion: zsh: simplify compadd functions
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (13 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 14/29] completion: zsh: fix splitting of words Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 16/29] completion: zsh: simplify direct compadd Felipe Contreras
                   ` (14 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

We don't need to override IFS, zsh has a native way of splitting by new
lines: the expansion flag (f).

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 088bf7f759..2f20fe386a 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -93,9 +93,8 @@ __gitcomp_direct ()
 {
 	emulate -L zsh
 
-	local IFS=$'\n'
 	compset -P '*[=:]'
-	compadd -Q -- ${${=1}% } && _ret=0
+	compadd -Q -- ${${(f)1}% } && _ret=0
 }
 
 __gitcomp_direct_append ()
@@ -107,34 +106,30 @@ __gitcomp_nl ()
 {
 	emulate -L zsh
 
-	local IFS=$'\n'
 	compset -P '*[=:]'
-	compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
+	compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0
 }
 
 __gitcomp_nl_append ()
 {
 	emulate -L zsh
 
-	local IFS=$'\n'
 	compset -P '*[=:]'
-	compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
+	compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0
 }
 
 __gitcomp_file_direct ()
 {
 	emulate -L zsh
 
-	local IFS=$'\n'
-	compadd -f -- ${=1} && _ret=0
+	compadd -f -- ${(f)1} && _ret=0
 }
 
 __gitcomp_file ()
 {
 	emulate -L zsh
 
-	local IFS=$'\n'
-	compadd -p "${2-}" -f -- ${=1} && _ret=0
+	compadd -p "${2-}" -f -- ${(f)1} && _ret=0
 }
 
 __git_zsh_bash_func ()
-- 
2.29.0


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

* [PATCH v2 16/29] completion: zsh: simplify direct compadd
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (14 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 15/29] completion: zsh: simplify compadd functions Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 17/29] completion: zsh: trivial cleanup Felipe Contreras
                   ` (13 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

Instead of manually removing the suffix so zsh can add its own, we can
tell zsh to add no suffix, so we don't have to remove it.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 2f20fe386a..b955404fdd 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -94,7 +94,7 @@ __gitcomp_direct ()
 	emulate -L zsh
 
 	compset -P '*[=:]'
-	compadd -Q -- ${${(f)1}% } && _ret=0
+	compadd -Q -S '' -- ${(f)1} && _ret=0
 }
 
 __gitcomp_direct_append ()
-- 
2.29.0


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

* [PATCH v2 17/29] completion: zsh: trivial cleanup
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (15 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 16/29] completion: zsh: simplify direct compadd Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 18/29] completion: zsh: simplify nl_append Felipe Contreras
                   ` (12 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index b955404fdd..f0babc784a 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -129,7 +129,7 @@ __gitcomp_file ()
 {
 	emulate -L zsh
 
-	compadd -p "${2-}" -f -- ${(f)1} && _ret=0
+	compadd -f -p "${2-}" -- ${(f)1} && _ret=0
 }
 
 __git_zsh_bash_func ()
-- 
2.29.0


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

* [PATCH v2 18/29] completion: zsh: simplify nl_append
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (16 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 17/29] completion: zsh: trivial cleanup Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 19/29] completion: zsh: simplify file_direct Felipe Contreras
                   ` (11 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

It's exactly the same as __gitcomp_nl(), no need to duplicate code.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index f0babc784a..85365bd2f7 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -112,10 +112,7 @@ __gitcomp_nl ()
 
 __gitcomp_nl_append ()
 {
-	emulate -L zsh
-
-	compset -P '*[=:]'
-	compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0
+	__gitcomp_nl "$@"
 }
 
 __gitcomp_file_direct ()
-- 
2.29.0


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

* [PATCH v2 19/29] completion: zsh: simplify file_direct
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (17 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 18/29] completion: zsh: simplify nl_append Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 20/29] completion: zsh: shuffle functions around Felipe Contreras
                   ` (10 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

It's exactly the same as __gitcomp_file() with no prefix.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 85365bd2f7..aa484ad9ba 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -117,9 +117,7 @@ __gitcomp_nl_append ()
 
 __gitcomp_file_direct ()
 {
-	emulate -L zsh
-
-	compadd -f -- ${(f)1} && _ret=0
+	__gitcomp_file "$1" ''
 }
 
 __gitcomp_file ()
-- 
2.29.0


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

* [PATCH v2 20/29] completion: zsh: shuffle functions around
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (18 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 19/29] completion: zsh: simplify file_direct Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 21/29] completion: zsh: refactor command completion Felipe Contreras
                   ` (9 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

Just to have a nice order.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index aa484ad9ba..179e8ff07d 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -97,11 +97,6 @@ __gitcomp_direct ()
 	compadd -Q -S '' -- ${(f)1} && _ret=0
 }
 
-__gitcomp_direct_append ()
-{
-	__gitcomp_direct "$@"
-}
-
 __gitcomp_nl ()
 {
 	emulate -L zsh
@@ -110,21 +105,26 @@ __gitcomp_nl ()
 	compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0
 }
 
-__gitcomp_nl_append ()
+__gitcomp_file ()
 {
-	__gitcomp_nl "$@"
+	emulate -L zsh
+
+	compadd -f -p "${2-}" -- ${(f)1} && _ret=0
 }
 
-__gitcomp_file_direct ()
+__gitcomp_direct_append ()
 {
-	__gitcomp_file "$1" ''
+	__gitcomp_direct "$@"
 }
 
-__gitcomp_file ()
+__gitcomp_nl_append ()
 {
-	emulate -L zsh
+	__gitcomp_nl "$@"
+}
 
-	compadd -f -p "${2-}" -- ${(f)1} && _ret=0
+__gitcomp_file_direct ()
+{
+	__gitcomp_file "$1" ""
 }
 
 __git_zsh_bash_func ()
-- 
2.29.0


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

* [PATCH v2 21/29] completion: zsh: refactor command completion
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (19 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 20/29] completion: zsh: shuffle functions around Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 22/29] completion: zsh: improve command tags Felipe Contreras
                   ` (8 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 179e8ff07d..702ce8db25 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -127,20 +127,32 @@ __gitcomp_file_direct ()
 	__gitcomp_file "$1" ""
 }
 
+__git_complete_command ()
+{
+	emulate -L zsh
+
+	local command="$1"
+	local completion_func="_git_${command//-/_}"
+	if (( $+functions[$completion_func] )); then
+		emulate ksh -c $completion_func
+		return 0
+	else
+		return 1
+	fi
+}
+
 __git_zsh_bash_func ()
 {
 	emulate -L ksh
 
 	local command=$1
 
-	local completion_func="_git_${command//-/_}"
-	declare -f $completion_func >/dev/null && $completion_func && return
+	__git_complete_command "$command" && return
 
 	local expansion=$(__git_aliased_command "$command")
 	if [ -n "$expansion" ]; then
 		words[1]=$expansion
-		completion_func="_git_${expansion//-/_}"
-		declare -f $completion_func >/dev/null && $completion_func
+		__git_complete_command "$expansion"
 	fi
 }
 
-- 
2.29.0


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

* [PATCH v2 22/29] completion: zsh: improve command tags
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (20 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 21/29] completion: zsh: refactor command completion Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 23/29] completion: zsh: add alias descriptions Felipe Contreras
                   ` (7 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

There's no need to use _alternative and repeat a lot of the code.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 702ce8db25..2016e8c1b7 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -228,10 +228,13 @@ __git_zsh_main ()
 
 	case $state in
 	(command)
-		_alternative \
-                         'alias-commands:alias:__git_zsh_cmd_alias' \
-                         'common-commands:common:__git_zsh_cmd_common' \
-                         'all-commands:all:__git_zsh_cmd_all' && _ret=0
+		_tags common-commands alias-commands all-commands
+		while _tags; do
+			_requested common-commands && __git_zsh_cmd_common
+			_requested alias-commands && __git_zsh_cmd_alias
+			_requested all-commands && __git_zsh_cmd_all
+			let _ret || break
+		done
 		;;
 	(arg)
 		local command="${words[1]}" __git_dir
-- 
2.29.0


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

* [PATCH v2 23/29] completion: zsh: add alias descriptions
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (21 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 22/29] completion: zsh: improve command tags Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 24/29] completion: zsh: trivial simplification Felipe Contreras
                   ` (6 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 2016e8c1b7..d90eb6863b 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -189,8 +189,9 @@ __git_zsh_cmd_common ()
 __git_zsh_cmd_alias ()
 {
 	local -a list
-	list=(${${${(0)"$(git config -z --get-regexp '^alias\.')"}#alias.}%$'\n'*})
-	_describe -t alias-commands 'aliases' list $* && _ret=0
+	list=(${${(0)"$(git config -z --get-regexp '^alias\.*')"}#alias.})
+	list=(${(f)"$(printf "%s:alias for '%s'\n" ${(f@)list})"})
+	_describe -t alias-commands 'aliases' list && _ret=0
 }
 
 __git_zsh_cmd_all ()
-- 
2.29.0


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

* [PATCH v2 24/29] completion: zsh: trivial simplification
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (22 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 23/29] completion: zsh: add alias descriptions Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 25/29] completion: zsh: add simple version check Felipe Contreras
                   ` (5 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

From upstream bash simplification:

  d9ee1e0617 (completion: simplify inner 'case' pattern in __gitcomp())

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index d90eb6863b..1b2a43150d 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -78,7 +78,7 @@ __gitcomp ()
 			fi
 			c="$c${4-}"
 			case $c in
-			--*=*|*.) ;;
+			--*=|*.) ;;
 			*) c="$c " ;;
 			esac
 			array+=("$c")
-- 
2.29.0


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

* [PATCH v2 25/29] completion: zsh: add simple version check
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (23 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 24/29] completion: zsh: trivial simplification Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 26/29] completion: bash: trivial cleanup Felipe Contreras
                   ` (4 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

A lot of people are confused about which completion script they are
using; Zsh's Git script, or Git's Zsh script.

Add a simple helper so they can type 'git zsh<tab>' and find out if they
are running the correct one: this.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 1b2a43150d..9fc9f2db21 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -127,6 +127,11 @@ __gitcomp_file_direct ()
 	__gitcomp_file "$1" ""
 }
 
+_git_zsh ()
+{
+	__gitcomp "v1.0"
+}
+
 __git_complete_command ()
 {
 	emulate -L zsh
-- 
2.29.0


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

* [PATCH v2 26/29] completion: bash: trivial cleanup
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (24 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 25/29] completion: zsh: add simple version check Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 27/29] completion: bash: cleanup cygwin check Felipe Contreras
                   ` (3 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

There's no need to set a variable we are not going to use.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6de0e7b482..68e0acb232 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -416,14 +416,13 @@ __gitcomp_builtin ()
 	local options
 	eval "options=\${$var-}"
 
-	local completion_helper
-	if [ "$GIT_COMPLETION_SHOW_ALL" = "1" ]; then
-		completion_helper="--git-completion-helper-all"
-	else
-		completion_helper="--git-completion-helper"
-	fi
-
 	if [ -z "$options" ]; then
+		local completion_helper
+		if [ "$GIT_COMPLETION_SHOW_ALL" = "1" ]; then
+			completion_helper="--git-completion-helper-all"
+		else
+			completion_helper="--git-completion-helper"
+		fi
 		# leading and trailing spaces are significant to make
 		# option removal work correctly.
 		options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
-- 
2.29.0


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

* [PATCH v2 27/29] completion: bash: cleanup cygwin check
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (25 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 26/29] completion: bash: trivial cleanup Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 28/29] completion: bash: remove old compat wrappers Felipe Contreras
                   ` (2 subsequent siblings)
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

Avoid Yoda conditions, and use $OSTYPE.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 68e0acb232..ac1835cb30 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3500,6 +3500,6 @@ __git_complete gitk __gitk_main
 # when the user has tab-completed the executable name and consequently
 # included the '.exe' suffix.
 #
-if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
-__git_complete git.exe __git_main
+if [ "$OSTYPE" = cygwin ]; then
+	__git_complete git.exe __git_main
 fi
-- 
2.29.0


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

* [PATCH v2 28/29] completion: bash: remove old compat wrappers
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (26 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 27/29] completion: bash: cleanup cygwin check Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-25  3:13 ` [PATCH v2 29/29] Update copyright notices Felipe Contreras
  2020-10-27 20:14 ` [PATCH v2 00/29] completion: zsh: latest patches Junio C Hamano
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

It's been eight years, more than enough time to move on.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index ac1835cb30..26538efb80 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3481,18 +3481,6 @@ __git_complete ()
 		|| complete -o default -o nospace -F $wrapper $1
 }
 
-# wrapper for backwards compatibility
-_git ()
-{
-	__git_wrap__git_main
-}
-
-# wrapper for backwards compatibility
-_gitk ()
-{
-	__git_wrap__gitk_main
-}
-
 __git_complete git __git_main
 __git_complete gitk __gitk_main
 
-- 
2.29.0


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

* [PATCH v2 29/29] Update copyright notices
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (27 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 28/29] completion: bash: remove old compat wrappers Felipe Contreras
@ 2020-10-25  3:13 ` Felipe Contreras
  2020-10-27 20:14 ` [PATCH v2 00/29] completion: zsh: latest patches Junio C Hamano
  29 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-25  3:13 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 2 +-
 t/t9902-completion.sh                 | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 9fc9f2db21..d25f8691ef 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -2,7 +2,7 @@
 
 # zsh completion wrapper for git
 #
-# Copyright (c) 2012-2013 Felipe Contreras <felipe.contreras@gmail.com>
+# Copyright (c) 2012-2020 Felipe Contreras <felipe.contreras@gmail.com>
 #
 # The recommended way to install this script is to make a copy of it as a
 # file named '_git' inside any directory in your fpath.
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 7b7bc6e4bd..caf4e9101f 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (c) 2012 Felipe Contreras
+# Copyright (c) 2012-2020 Felipe Contreras
 #
 
 test_description='test bash completion'
-- 
2.29.0


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

* Re: [PATCH v2 00/29] completion: zsh: latest patches
  2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
                   ` (28 preceding siblings ...)
  2020-10-25  3:13 ` [PATCH v2 29/29] Update copyright notices Felipe Contreras
@ 2020-10-27 20:14 ` Junio C Hamano
  2020-10-28  1:48   ` Felipe Contreras
  29 siblings, 1 reply; 32+ messages in thread
From: Junio C Hamano @ 2020-10-27 20:14 UTC (permalink / raw)
  To: Felipe Contreras; +Cc: git, SZEDER Gábor

Felipe Contreras <felipe.contreras@gmail.com> writes:

> I've been carrying around these patches for quite some time, many have already
> been sent, others I refactored to make them more clear.
>
> But what is clear is that they are needed. I see a lot of people in different
> forums (e.g. Stack Overflow, Oh-My-Zsh, etc.) getting bit by many of these
> issues.

Is this "v2" an update to the 14-patch series you have a late reply to?

There is a tiny zsh completion patch in flight, but hopefully it can
be rebased on this series and graduate together, provided if zsh
users on the list find the topic as a whole agreeable.

Thanks.

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

* Re: [PATCH v2 00/29] completion: zsh: latest patches
  2020-10-27 20:14 ` [PATCH v2 00/29] completion: zsh: latest patches Junio C Hamano
@ 2020-10-28  1:48   ` Felipe Contreras
  0 siblings, 0 replies; 32+ messages in thread
From: Felipe Contreras @ 2020-10-28  1:48 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git, SZEDER Gábor

On Tue, Oct 27, 2020 at 2:14 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Felipe Contreras <felipe.contreras@gmail.com> writes:
>
> > I've been carrying around these patches for quite some time, many have already
> > been sent, others I refactored to make them more clear.
> >
> > But what is clear is that they are needed. I see a lot of people in different
> > forums (e.g. Stack Overflow, Oh-My-Zsh, etc.) getting bit by many of these
> > issues.
>
> Is this "v2" an update to the 14-patch series you have a late reply to?
>
> There is a tiny zsh completion patch in flight, but hopefully it can
> be rebased on this series and graduate together, provided if zsh
> users on the list find the topic as a whole agreeable.

Yes. That v1 should be dropped, this v2 supersedes that, but I'll send
v3 in a moment.

-- 
Felipe Contreras

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

end of thread, other threads:[~2020-10-28 22:41 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-25  3:13 [PATCH v2 00/29] completion: zsh: latest patches Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 01/29] completion: zsh: fix __gitcomp_direct() Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 02/29] completion: zsh: fix name due to broken autoloading Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 03/29] completion: zsh: fix bash script extension Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 04/29] completion: zsh: reorganize install instructions Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 05/29] completion: zsh: fix for directories with spaces Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 06/29] completion: zsh: update slave script locations Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 07/29] completion: prompt: fix color for Zsh Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 08/29] completion: zsh: fix for command aliasing Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 09/29] completion: bash: synchronize zsh wrapper Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 10/29] completion: bash: remove " Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 11/29] completion: zsh: fix completion for --no-.. options Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 12/29] completion: fix conflict with bashcomp Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 13/29] completion: zsh: add missing direct_append Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 14/29] completion: zsh: fix splitting of words Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 15/29] completion: zsh: simplify compadd functions Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 16/29] completion: zsh: simplify direct compadd Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 17/29] completion: zsh: trivial cleanup Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 18/29] completion: zsh: simplify nl_append Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 19/29] completion: zsh: simplify file_direct Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 20/29] completion: zsh: shuffle functions around Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 21/29] completion: zsh: refactor command completion Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 22/29] completion: zsh: improve command tags Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 23/29] completion: zsh: add alias descriptions Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 24/29] completion: zsh: trivial simplification Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 25/29] completion: zsh: add simple version check Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 26/29] completion: bash: trivial cleanup Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 27/29] completion: bash: cleanup cygwin check Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 28/29] completion: bash: remove old compat wrappers Felipe Contreras
2020-10-25  3:13 ` [PATCH v2 29/29] Update copyright notices Felipe Contreras
2020-10-27 20:14 ` [PATCH v2 00/29] completion: zsh: latest patches Junio C Hamano
2020-10-28  1:48   ` Felipe Contreras

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).