From 4ce2b5167bb63e7001e43ec5386528fb77c088fa Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sat, 24 Oct 2020 22:13:15 -0500 Subject: completion: zsh: fix __gitcomp_direct() Many callers append a space suffix, but zsh automatically appends a space, making the completion add two spaces, for example: git log ma Will complete 'master '. Let's remove that extra space. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 0a96ad8..ec7dd12 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 ce47e86..2cefae9 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 () -- cgit v0.10.2-6-g49f6 From 5eb25bcf0f89a40627b8c23af408af1892705372 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sat, 24 Oct 2020 22:13:16 -0500 Subject: completion: zsh: fix name due to broken autoloading 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', 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 Cc: Johannes Schindelin Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 2cefae9..6d45135 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) -- cgit v0.10.2-6-g49f6 From 2c7cdc55738257f050e2b83aa94766f50ed60e15 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sat, 24 Oct 2020 22:13:17 -0500 Subject: completion: zsh: fix bash script extension 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 Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 6d45135..712ce2f 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. -- cgit v0.10.2-6-g49f6 From cb9dcbdbe4b3cb5d13f75ac3282b048bcf7bcc45 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sat, 24 Oct 2020 22:13:18 -0500 Subject: completion: zsh: reorganize install instructions 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 Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 712ce2f..05ccaac 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -4,13 +4,6 @@ # # Copyright (c) 2012-2013 Felipe Contreras # -# 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 () { -- cgit v0.10.2-6-g49f6 From 44b37abb2aabdb49e9f44161b7eafba3f03e4da5 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sat, 24 Oct 2020 22:13:19 -0500 Subject: completion: zsh: fix for directories with spaces Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 05ccaac..5d6740c 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 -- cgit v0.10.2-6-g49f6 From 98fc2684a90bfb9edaae2cb8d5129b4ca7698ddc Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:06:49 -0600 Subject: completion: zsh: update slave script locations 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 Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 5d6740c..ccf384b 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: @@ -33,12 +33,16 @@ zstyle -T ':completion:*:*:git:*' tag-order && \ zstyle -s ":completion:*:*:git:*" script script if [ -z "$script" ]; then local -a locations - local e + local e bash_completion + + bash_completion=$(pkg-config --variable=completionsdir bash-completion 2>/dev/null) || + bash_completion='/usr/share/bash-completion/completions/' + 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" + "$bash_completion/git" + '/etc/bash_completion.d/git' # old debian ) for e in $locations; do test -f $e && script="$e" && break -- cgit v0.10.2-6-g49f6 From ea625a39fe5dfcaa3df0d1ee53a40008213acd59 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:06:50 -0600 Subject: completion: prompt: fix color for Zsh 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 Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index 16260ba..54e123d 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/} -- cgit v0.10.2-6-g49f6 From 81f717bb268e86eee5701b8199d8f030938a184c Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:06:51 -0600 Subject: completion: zsh: fix for command aliasing 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 Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index ccf384b..f524c60 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -243,8 +243,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 -- cgit v0.10.2-6-g49f6 From bed635664c4a60f4b19baff02f487aa4c0cd591e Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:06:52 -0600 Subject: completion: bash: synchronize zsh wrapper A function was missing. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index ec7dd12..40affd4 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 -- cgit v0.10.2-6-g49f6 From 162f1a5610fa4de331207c84a8c281088486e5a7 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:06:53 -0600 Subject: completion: bash: remove zsh wrapper 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 Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 40affd4..26d6ee2 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 -- cgit v0.10.2-6-g49f6 From aa1f1f8010db3ed9a35579f2e83c574650c41237 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:06:54 -0600 Subject: completion: zsh: fix completion for --no-.. options 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 Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index f524c60..e567062 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -59,10 +59,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 --*=*|*.) ;; -- cgit v0.10.2-6-g49f6 From 3791968bfe8485353f95e692c5a3891e4a02c5c4 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:06:55 -0600 Subject: completion: fix conflict with bashcomp We don't want to override the 'complete()' function in zsh, which can be used by bashcomp. Reported-by: Mark Lodato Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index e567062..b894cb5 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' @@ -48,7 +42,11 @@ if [ -z "$script" ]; then test -f $e && script="$e" && break done fi + +local old_complete="$functions[complete]" +functions[complete]=: GIT_SOURCING_ZSH_COMPLETION=y . "$script" +functions[complete]="$old_complete" __gitcomp () { -- cgit v0.10.2-6-g49f6 From a7804a11c16c8562c71b537170a4802a058b7dd6 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:06:56 -0600 Subject: completion: zsh: add missing direct_append Commit 688077910b forgot to add the corresponding zsh function. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index b894cb5..c5b8759 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -105,6 +105,11 @@ __gitcomp_direct () compadd -Q -- ${${=1}% } && _ret=0 } +__gitcomp_direct_append () +{ + __gitcomp_direct "$@" +} + __gitcomp_nl () { emulate -L zsh -- cgit v0.10.2-6-g49f6 From 94b2901cfe23c077207a563e544fd8dc11a832ce Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:06:57 -0600 Subject: completion: zsh: fix splitting of words Files don't need to be split by '=:', words do. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index c5b8759..d9ce5e1 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -124,6 +124,7 @@ __gitcomp_nl_append () emulate -L zsh local IFS=$'\n' + compset -P '*[=:]' compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0 } @@ -132,7 +133,6 @@ __gitcomp_file_direct () emulate -L zsh local IFS=$'\n' - compset -P '*[=:]' compadd -f -- ${=1} && _ret=0 } @@ -141,7 +141,6 @@ __gitcomp_file () emulate -L zsh local IFS=$'\n' - compset -P '*[=:]' compadd -p "${2-}" -f -- ${=1} && _ret=0 } -- cgit v0.10.2-6-g49f6 From 2f459b0060948299be4bfa00c21f574140dcbe63 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:06:58 -0600 Subject: completion: zsh: simplify compadd functions 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 Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index d9ce5e1..1ef02f9 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -100,9 +100,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 () @@ -114,34 +113,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 () -- cgit v0.10.2-6-g49f6 From ecaf798999c1cb730560668710584759151b6624 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:06:59 -0600 Subject: completion: zsh: simplify direct compadd 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 Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 1ef02f9..3689bcb 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -101,7 +101,7 @@ __gitcomp_direct () emulate -L zsh compset -P '*[=:]' - compadd -Q -- ${${(f)1}% } && _ret=0 + compadd -Q -S '' -- ${(f)1} && _ret=0 } __gitcomp_direct_append () -- cgit v0.10.2-6-g49f6 From 35e29fbce6bbddf9a74d85ec1541ef806b6f08a8 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:07:00 -0600 Subject: completion: zsh: trivial cleanup Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 3689bcb..234e427 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -136,7 +136,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 () -- cgit v0.10.2-6-g49f6 From cf6ce01660ada0286193025f7358c2d52bdb4fae Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:07:01 -0600 Subject: completion: zsh: simplify nl_append It's exactly the same as __gitcomp_nl(), no need to duplicate code. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 234e427..7126c75 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -119,10 +119,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 () -- cgit v0.10.2-6-g49f6 From 5d64fb20511270ffb2d939210a5afe66419f69ab Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:07:02 -0600 Subject: completion: zsh: simplify file_direct It's exactly the same as __gitcomp_file() with no prefix. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 7126c75..4834ebc 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -124,9 +124,7 @@ __gitcomp_nl_append () __gitcomp_file_direct () { - emulate -L zsh - - compadd -f -- ${(f)1} && _ret=0 + __gitcomp_file "$1" '' } __gitcomp_file () -- cgit v0.10.2-6-g49f6 From 46af9b371929c3c3c9cc0f5b4aa9bcb3089e6405 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:07:03 -0600 Subject: completion: zsh: shuffle functions around Just to have a nice order. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 4834ebc..60efddb 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -104,11 +104,6 @@ __gitcomp_direct () compadd -Q -S '' -- ${(f)1} && _ret=0 } -__gitcomp_direct_append () -{ - __gitcomp_direct "$@" -} - __gitcomp_nl () { emulate -L zsh @@ -117,21 +112,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 () -- cgit v0.10.2-6-g49f6 From 9a397ea5ad59e64ff6eebfd1d7dad43aac790e0a Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:07:04 -0600 Subject: completion: zsh: refactor command completion Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 60efddb..858864f 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -134,20 +134,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 } -- cgit v0.10.2-6-g49f6 From 9d760527addc576c87e9b0e66b63376e580b434a Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:07:05 -0600 Subject: completion: zsh: improve command tags There's no need to use _alternative and repeat a lot of the code. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 858864f..22d8e58 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -235,10 +235,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 -- cgit v0.10.2-6-g49f6 From 2769e567d140a51e4e6e426fe776005ae889e9b0 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:07:06 -0600 Subject: completion: zsh: add alias descriptions Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 22d8e58..1204a55 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -196,8 +196,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 () -- cgit v0.10.2-6-g49f6 From bbd7f45884ca379e3cd28bb5fb8e804bcfb3360c Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:07:07 -0600 Subject: completion: zsh: trivial simplification >From upstream bash simplification: d9ee1e0617 (completion: simplify inner 'case' pattern in __gitcomp()) Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 1204a55..2956b9d 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -85,7 +85,7 @@ __gitcomp () fi c="$c${4-}" case $c in - --*=*|*.) ;; + --*=|*.) ;; *) c="$c " ;; esac array+=("$c") -- cgit v0.10.2-6-g49f6 From 35a4170d8656b27d08458c3c381dd163199da4f3 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:07:08 -0600 Subject: completion: zsh: add simple version check 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' and find out if they are running the correct one: this. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 2956b9d..811d77c 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -134,6 +134,11 @@ __gitcomp_file_direct () __gitcomp_file "$1" "" } +_git_zsh () +{ + __gitcomp "v1.1" +} + __git_complete_command () { emulate -L zsh -- cgit v0.10.2-6-g49f6 From 5a364d2a18311de1791375731678ca13cde89f13 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:07:09 -0600 Subject: completion: bash: trivial cleanup There's no need to set a variable we are not going to use. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 26d6ee2..ed059f3 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 -- cgit v0.10.2-6-g49f6 From 8030684beb7af806909c3fa79d3d4017121a753c Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:07:10 -0600 Subject: completion: bash: cleanup cygwin check Avoid Yoda conditions, and use $OSTYPE. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index ed059f3..980ce73 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3499,6 +3499,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 -- cgit v0.10.2-6-g49f6 From 441ecdab37fefdacf32575a60aa523b2367c46f7 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:07:11 -0600 Subject: completion: bash: remove old compat wrappers It's been eight years, more than enough time to move on. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 980ce73..49a6ef4 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3480,18 +3480,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 -- cgit v0.10.2-6-g49f6 From af806a2c2417d21dc024bf013ec511765441e286 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 20:07:12 -0600 Subject: zsh: update copyright notices Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 811d77c..e0fda27 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 +# Copyright (c) 2012-2020 Felipe Contreras # # 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 7b7bc6e..caf4e91 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' -- cgit v0.10.2-6-g49f6