threads / patch / 42394

patch, 11 partscompletion: bash: remove old wrappers

Subject: [PATCH 02/11] completion: bash: remove old wrappers

## tl;dr

12 messages between May 20, 2016 and May 20, 2016. Diffs are folded; open one to read it.

replies: 11people: 1as markdown or json

Felipe Contreras· May 20, 2016, 04:58 UTC · lore

[PATCH 00/11] Completion fixes and improvements

Hi,

Here's a bunch of patches I've been using for a long time. I don't recall if I've sent some of these before.

Here they are in case anybody is interested.
Cheers.
Felipe Contreras (11):
  completion: add missing fetch options
  completion: bash: remove old wrappers
  completion: bash: remove zsh wrapper
  completion: zsh: don't hide ourselves
  completion: remove zsh hack
  completion: zsh: trivial cleanups
  completion: bash: cleanup cygwin check
  completion: zsh: improve main function selection
  completion: zsh: fix for directories with spaces
  completion: prompt: fix for Zsh
  Revert "Update documentation occurrences of filename .sh"
 contrib/completion/git-completion.bash | 86 +++-------------------------------
 contrib/completion/git-completion.zsh  | 26 ++++------
 contrib/completion/git-prompt.sh       |  8 ++--
 3 files changed, 20 insertions(+), 100 deletions(-)
-- 
2.8.0+fc1
Felipe Contreras· May 20, 2016, 04:58 UTC · re: Felipe Contreras · lore

[PATCH 01/11] completion: add missing fetch options

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 2 ++
 1 file changed, 2 insertions(+)
Show changes to contrib/completion/git-completion.bash +2 −0
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index e3918c8..ecdf742 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1225,6 +1225,8 @@ __git_fetch_recurse_submodules="yes on-demand no"
 __git_fetch_options="
 	--quiet --verbose --append --upload-pack --force --keep --depth=
 	--tags --no-tags --all --prune --dry-run --recurse-submodules=
+	--no-recurse-submodules --unshallow --update-shallow --multiple
+	--submodule-prefix= --update-head-ok --progress
 "
 
 _git_fetch ()
-- 
2.8.0+fc1
Felipe Contreras· May 20, 2016, 04:58 UTC · re: Felipe Contreras · lore
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 12 ------------
 1 file changed, 12 deletions(-)
Show changes to contrib/completion/git-completion.bash +0 −12
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index ecdf742..5e2e590 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2754,18 +2754,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.8.0+fc1
Felipe Contreras· May 20, 2016, 04:58 UTC · re: Felipe Contreras · lore

[PATCH 03/11] completion: bash: remove zsh wrapper

It has been deprecated for more than three years. It's time to move on.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 64 ----------------------------------
 1 file changed, 64 deletions(-)
Show changes to contrib/completion/git-completion.bash +0 −64
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 5e2e590..9cbae6f 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2672,70 +2672,6 @@ __gitk_main ()
 	__git_complete_revlist
 }
 
-if [[ -n ${ZSH_VERSION-} ]]; 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_nl ()
-	{
-		emulate -L zsh
-
-		local IFS=$'\n'
-		compset -P '*[=:]'
-		compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
-	}
-
-	__gitcomp_file ()
-	{
-		emulate -L zsh
-
-		local IFS=$'\n'
-		compset -P '*[=:]'
-		compadd -Q -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
-	return
-fi
-
 __git_func_wrap ()
 {
 	local cur words cword prev
-- 
2.8.0+fc1
Felipe Contreras· May 20, 2016, 04:58 UTC · re: Felipe Contreras · lore

[PATCH 04/11] completion: zsh: don't hide ourselves

There's no need to hide the fact that we are on zsh any more.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to contrib/completion/git-completion.zsh +1 −1
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index e255413..475705a 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -39,7 +39,7 @@ if [ -z "$script" ]; then
 		test -f $e && script="$e" && break
 	done
 fi
-ZSH_VERSION='' . "$script"
+. "$script"
 
 __gitcomp ()
 {
-- 
2.8.0+fc1
Felipe Contreras· May 20, 2016, 04:58 UTC · re: Felipe Contreras · lore

[PATCH 05/11] completion: remove zsh hack

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(-)
Show changes to 2 files +1 −6

contrib/completion/git-completion.bash, contrib/completion/git-completion.zsh

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 9cbae6f..6c338ae 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2684,6 +2684,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 475705a..e10df7d 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -16,12 +16,6 @@
 #
 #  fpath=(~/.zsh $fpath)
 
-complete ()
-{
-	# do nothing
-	return 0
-}
-
 zstyle -T ':completion:*:*:git:*' tag-order && \
 	zstyle ':completion:*:*:git:*' tag-order 'common-commands'
 
-- 
2.8.0+fc1
Felipe Contreras· May 20, 2016, 04:58 UTC · re: Felipe Contreras · lore

[PATCH 06/11] completion: zsh: trivial cleanups

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

Also, we don't need to split files by ':' or '='; that's only for words.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
Show changes to contrib/completion/git-completion.zsh +3 −7
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index e10df7d..317b8eb 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -65,26 +65,22 @@ __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'
-	compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
+	compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0
 }
 
 __gitcomp_file ()
 {
 	emulate -L zsh
 
-	local IFS=$'\n'
-	compset -P '*[=:]'
-	compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
+	compadd -Q -p "${2-}" -f -- ${(f)1} && _ret=0
 }
 
 __git_zsh_bash_func ()
-- 
2.8.0+fc1
Felipe Contreras· May 20, 2016, 04:58 UTC · re: Felipe Contreras · lore

[PATCH 07/11] completion: bash: cleanup cygwin check

Avoid Yoda conditions, use test, and cleaner statement.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Show changes to contrib/completion/git-completion.bash +1 −2
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6c338ae..398f3a7 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2698,6 +2698,5 @@ __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
+test "$(uname -o 2>/dev/null)" = "Cygwin" &&
 __git_complete git.exe __git_main
-fi
-- 
2.8.0+fc1
Felipe Contreras· May 20, 2016, 04:58 UTC · re: Felipe Contreras · lore

[PATCH 08/11] completion: zsh: improve main function selection

Sometimes we want to use the function directly (e.g. _git_checkout), for example when zsh has the option 'complete_aliases', this way, we can do something like:

  compdef _git gco=git_checkout
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Show changes to contrib/completion/git-completion.zsh +3 −1
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 317b8eb..1f786cc 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -204,8 +204,10 @@ _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}
 	fi
 
 	let _ret && _default && _ret=0
-- 
2.8.0+fc1
Felipe Contreras· May 20, 2016, 04:58 UTC · re: Felipe Contreras · lore

[PATCH 09/11] completion: zsh: fix for directories with spaces

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to contrib/completion/git-completion.zsh +1 −1
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 1f786cc..28eaaed 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -24,7 +24,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.8.0+fc1
Felipe Contreras· May 20, 2016, 04:58 UTC · re: Felipe Contreras · lore

[PATCH 10/11] completion: prompt: fix for Zsh

We can add colour in Zsh without the need of pcmode.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-prompt.sh | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
Show changes to contrib/completion/git-prompt.sh +5 −3
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 64219e6..0da14ee 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -502,9 +502,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.8.0+fc1
Felipe Contreras· May 20, 2016, 04:58 UTC · re: Felipe Contreras · lore

[PATCH 11/11] Revert "Update documentation occurrences of filename .sh"

The original code was correct: the example location ~/.git-completion.sh is correct, because it's not only used by Bash. And zstyle command in Zsh should use that same location; the Bash script.

This reverts commit 0e5ed7cca3c51c821c2bb0465617e75d994f432f.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 4 ++--
 contrib/completion/git-completion.zsh  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
Show changes to 2 files +3 −3

contrib/completion/git-completion.bash, contrib/completion/git-completion.zsh

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 398f3a7..3224ae1 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -17,9 +17,9 @@
 #
 # To use these routines:
 #
-#    1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
+#    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
 #    2) Add the following line to your .bashrc/.zshrc:
-#        source ~/.git-completion.bash
+#        source ~/.git-completion.sh
 #    3) Consider changing your PS1 to also show the current branch,
 #       see git-prompt.sh for details.
 #
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 28eaaed..6075111 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.sh
 #
 # The recommended way to install this script is to copy to '~/.zsh/_git', and
 # then add the following to your ~/.zshrc file:
-- 
2.8.0+fc1

← back to recent threads