From a32564e0ae87686702570f3f942977bc9280f178 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sat, 24 Oct 2020 07:12:23 -0500 Subject: gitfast: update to latest upstream and more (#9382) --- plugins/gitfast/_git | 126 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 87 insertions(+), 39 deletions(-) (limited to 'plugins/gitfast/_git') diff --git a/plugins/gitfast/_git b/plugins/gitfast/_git index 78a6dbb3d..46d10d6f9 100644 --- a/plugins/gitfast/_git +++ b/plugins/gitfast/_git @@ -2,25 +2,24 @@ # zsh completion wrapper for git # -# Copyright (c) 2012-2013 Felipe Contreras +# Copyright (c) 2012-2020 Felipe Contreras # -# You need git's bash completion script installed somewhere, by default it -# would be the location bash-completion uses. +# 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. # -# If your script is somewhere else, you can configure it on your ~/.zshrc: +# For example, create a directory '~/.zsh/', copy this file to '~/.zsh/_git', +# and then add the following to your ~/.zshrc file: # -# zstyle ':completion:*:*:git:*' script ~/.git-completion.zsh +# fpath=(~/.zsh $fpath) # -# The recommended way to install this script is to copy to '~/.zsh/_git', and -# then add the following to your ~/.zshrc file: +# You need git's bash completion script installed. By default bash-completion's +# 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: +# +# zstyle ':completion:*:*:git:*' script ~/.git-completion.bash # -# fpath=(~/.zsh $fpath) - -complete () -{ - # do nothing - return 0 -} zstyle -T ':completion:*:*:git:*' tag-order && \ zstyle ':completion:*:*:git:*' tag-order 'common-commands' @@ -30,16 +29,17 @@ if [ -z "$script" ]; then local -a locations 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 + "$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash + "$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 done fi -ZSH_VERSION='' . "$script" +GIT_SOURCING_ZSH_COMPLETION=y . "$script" __gitcomp () { @@ -50,13 +50,35 @@ __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 - --*=*|*.) ;; + --*=|*.) ;; *) c="$c " ;; esac array+=("$c") @@ -71,35 +93,57 @@ __gitcomp_direct () { emulate -L zsh - local IFS=$'\n' compset -P '*[=:]' - compadd -Q -- ${=1} && _ret=0 + compadd -Q -S '' -- ${(f)1} && _ret=0 } __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 + compset -P '*[=:]' + compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0 +} + +__gitcomp_file_direct () +{ + emulate -L zsh + + compadd -f -- ${(f)1} && _ret=0 } __gitcomp_file () { emulate -L zsh - local IFS=$'\n' - compset -P '*[=:]' - compadd -Q -p "${2-}" -f -- ${=1} && _ret=0 + compadd -f -p "${2-}" -- ${(f)1} && _ret=0 +} + +_git_zsh () +{ + __gitcomp "v1.0" +} + +__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 () @@ -108,14 +152,12 @@ __git_zsh_bash_func () 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 } @@ -140,9 +182,11 @@ __git_zsh_cmd_common () push:'update remote refs along with associated objects' rebase:'forward-port local commits to the updated upstream head' reset:'reset current HEAD to the specified state' + restore:'restore working tree files' rm:'remove files from the working tree and from the index' show:'show various types of objects' status:'show the working tree status' + switch:'switch branches' tag:'create, list, delete or verify a tag object signed with GPG') _describe -t common-commands 'common commands' list && _ret=0 } @@ -150,8 +194,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 () @@ -189,10 +234,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 v1.2.3-70-g09d2 From 66f9fdabc1d08374c3eef212928f81ff32e2241e Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sat, 24 Oct 2020 09:33:43 -0500 Subject: gitfast: improve command aliases (#9385) So that compdefs with dashes work as well as underscores: compdef _git gc=git_commit Or: compdef _git gc=git-commit The official Zsh Git completion uses dashes, and this way people don't have to change their existing definitions. Signed-off-by: Felipe Contreras --- plugins/gitfast/_git | 2 ++ 1 file changed, 2 insertions(+) (limited to 'plugins/gitfast/_git') diff --git a/plugins/gitfast/_git b/plugins/gitfast/_git index 46d10d6f9..6ca63ed87 100644 --- a/plugins/gitfast/_git +++ b/plugins/gitfast/_git @@ -275,6 +275,8 @@ _git () 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 v1.2.3-70-g09d2 From d05544562532fdf4d5f4a4d4eba01f4263e17cc7 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 27 Oct 2020 04:14:39 -0600 Subject: gitfast: fetch latest fixes from git-completion (#9390) Signed-off-by: Felipe Contreras --- plugins/gitfast/_git | 33 ++++++++++++++++++++------------- plugins/gitfast/git-completion.bash | 6 ++---- 2 files changed, 22 insertions(+), 17 deletions(-) (limited to 'plugins/gitfast/_git') diff --git a/plugins/gitfast/_git b/plugins/gitfast/_git index 6ca63ed87..aaea581d5 100644 --- a/plugins/gitfast/_git +++ b/plugins/gitfast/_git @@ -27,19 +27,26 @@ 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 "$HOME/.local/share/bash-completion/completions/git" - "$(pkg-config --variable=completionsdir bash-completion)"/git - '/usr/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 done fi + +local old_complete="$functions[complete]" +functions[complete]=: GIT_SOURCING_ZSH_COMPLETION=y . "$script" +functions[complete]="$old_complete" __gitcomp () { @@ -105,26 +112,26 @@ __gitcomp_nl () compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0 } -__gitcomp_nl_append () +__gitcomp_file () { emulate -L zsh - compset -P '*[=:]' - compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0 + compadd -f -p "${2-}" -- ${(f)1} && _ret=0 } -__gitcomp_file_direct () +__gitcomp_direct_append () { - emulate -L zsh - - compadd -f -- ${(f)1} && _ret=0 + __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 () diff --git a/plugins/gitfast/git-completion.bash b/plugins/gitfast/git-completion.bash index 76ba7e79f..b93706d17 100644 --- a/plugins/gitfast/git-completion.bash +++ b/plugins/gitfast/git-completion.bash @@ -3585,7 +3585,6 @@ __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 \ @@ -3607,8 +3606,7 @@ if ! git --list-cmds=main >/dev/null 2>&1; then { case "$1" in --list-cmds=*) - IFS=, read -r -a cmds <<< "${1##--list-cmds=}" - for x in ${cmds[@]}; do + while read -r -d ',' x; do case "$x" in nohelpers) ;; @@ -3620,7 +3618,7 @@ if ! git --list-cmds=main >/dev/null 2>&1; then echo ${__git_cmds[$x]} ;; esac - done + done <<< "${1##--list-cmds=}," return ;; esac -- cgit v1.2.3-70-g09d2 From e92a4667cbd65e9567dc962b5a482e10f319596a Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 19 Nov 2020 12:45:19 -0600 Subject: feat(gitfast): update to git-completion 1.2 (#9458) Signed-off-by: Felipe Contreras --- plugins/gitfast/_git | 129 ++++++++++++++++++------------------ plugins/gitfast/git-completion.bash | 73 +++++++++++--------- plugins/gitfast/update | 2 +- 3 files changed, 108 insertions(+), 96 deletions(-) (limited to 'plugins/gitfast/_git') diff --git a/plugins/gitfast/_git b/plugins/gitfast/_git index aaea581d5..988f5b1c6 100644 --- a/plugins/gitfast/_git +++ b/plugins/gitfast/_git @@ -45,71 +45,49 @@ fi local old_complete="$functions[complete]" functions[complete]=: +COMP_WORDBREAKS=':' GIT_SOURCING_ZSH_COMPLETION=y . "$script" functions[complete]="$old_complete" +__gitcompadd () +{ + compadd -Q -p "${2-}" -S "${3- }" ${@[4,-1]} -- ${=1} && _ret=0 +} + __gitcomp () { emulate -L zsh local cur_="${3-$cur}" - 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 - --*=|*.) ;; - *) c="$c " ;; - esac - array+=("$c") - done - compset -P '*[=:]' - compadd -Q -S '' -p "${2-}" -a -- array && _ret=0 - ;; - esac -} + [[ "$cur_" == *= ]] && return -__gitcomp_direct () -{ - emulate -L zsh + local c IFS=$' \t\n' sfx + for c in ${=1}; do + if [[ $c == "--" ]]; then + [[ "$cur_" == --no-* ]] && continue + __gitcompadd "--no-..." + break + fi - compset -P '*[=:]' - compadd -Q -S '' -- ${(f)1} && _ret=0 + if [[ -z "${4-}" ]]; then + case $c in + *=) c="${c%=}"; sfx="=" ;; + *.) sfx="" ;; + *) sfx=" " ;; + esac + else + sfx="$4" + fi + __gitcompadd "$c" "${2-}" "$sfx" -q + done } __gitcomp_nl () { emulate -L zsh - compset -P '*[=:]' - compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0 + IFS=$'\n' __gitcompadd "$1" "${2-}" "${4- }" } __gitcomp_file () @@ -119,9 +97,14 @@ __gitcomp_file () compadd -f -p "${2-}" -- ${(f)1} && _ret=0 } -__gitcomp_direct_append () +__gitcomp_direct () { - __gitcomp_direct "$@" + __gitcomp_nl "$1" "" "" "" +} + +__gitcomp_file_direct () +{ + __gitcomp_file "$1" "" } __gitcomp_nl_append () @@ -129,25 +112,30 @@ __gitcomp_nl_append () __gitcomp_nl "$@" } -__gitcomp_file_direct () +__gitcomp_direct_append () { - __gitcomp_file "$1" "" + __gitcomp_direct "$@" } _git_zsh () { - __gitcomp "v1.0" + __gitcomp "v1.2" } __git_complete_command () { emulate -L zsh + compset -P '*[=:]' + local command="$1" local completion_func="_git_${command//-/_}" if (( $+functions[$completion_func] )); then emulate ksh -c $completion_func return 0 + elif emulate ksh -c "__git_support_parseopt_helper $command"; then + emulate ksh -c "__git_complete_common $command" + return 0 else return 1 fi @@ -218,24 +206,27 @@ __git_zsh_main () { local curcontext="$curcontext" state state_descr line typeset -A opt_args - local -a orig_words + local -a orig_words __git_C_args orig_words=( ${words[@]} ) _arguments -C \ - '(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \ - '(-p --paginate)--no-pager[do not pipe git output into a pager]' \ - '--git-dir=-[set the path to the repository]: :_directories' \ - '--bare[treat the repository as a bare repository]' \ + '(-p --paginate -P --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \ + '(-p --paginate -P --no-pager)'{-P,--no-pager}'[do not pipe git output into a pager]' \ + '(--bare)--git-dir=[set the path to the repository]: :_directories' \ + '(--git-dir)--bare[treat the repository as a bare repository]' \ '(- :)--version[prints the git suite version]' \ - '--exec-path=-[path to where your core git programs are installed]:: :_directories' \ - '--html-path[print the path where git''s HTML documentation is installed]' \ - '--info-path[print the path where the Info files are installed]' \ - '--man-path[print the manpath (see `man(1)`) for the man pages]' \ - '--work-tree=-[set the path to the working tree]: :_directories' \ - '--namespace=-[set the git namespace]' \ + '--exec-path=[path to where your core git programs are installed]: :_directories' \ + '(- :)--exec-path[print the path where your core git programs are installed]' \ + '(- :)--html-path[print the path where git''s HTML documentation is installed]' \ + '(- :)--info-path[print the path where the Info files are installed]' \ + '(- :)--man-path[print the manpath (see `man(1)`) for the man pages]' \ + '--work-tree=[set the path to the working tree]: :_directories' \ + '--namespace=[set the git namespace]:' \ '--no-replace-objects[do not use replacement refs to replace git objects]' \ '(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \ + '*-C[run as if git was started in the given path]: :_directories' \ + '*-c[pass a configuration parameter to the command]: :->config' \ '(-): :->command' \ '(-)*:: :->arg' && return @@ -249,15 +240,23 @@ __git_zsh_main () let _ret || break done ;; + (config) + compset -P '*[=:]' + emulate ksh -c __git_complete_config_variable_name_and_value + ;; (arg) local command="${words[1]}" __git_dir if (( $+opt_args[--bare] )); then __git_dir='.' else - __git_dir=${opt_args[--git-dir]} + __git_dir=${~opt_args[--git-dir]} fi + for x in ${(s.:.)opt_args[-C]}; do + __git_C_args+=('-C' ${~x}) + done + (( $+opt_args[--help] )) && command='help' words=( ${orig_words[@]} ) diff --git a/plugins/gitfast/git-completion.bash b/plugins/gitfast/git-completion.bash index b93706d17..4497a294f 100644 --- a/plugins/gitfast/git-completion.bash +++ b/plugins/gitfast/git-completion.bash @@ -45,11 +45,6 @@ # When set to "1" suggest all options, including options which are # typically hidden (e.g. '--allow-empty' for 'git commit'). -case "$COMP_WORDBREAKS" in -*:*) : great ;; -*) COMP_WORDBREAKS="$COMP_WORDBREAKS:" -esac - # Discovers the path to the git repository taking any '--git-dir=' and # '-C ' options into account and stores it in the $__git_repo_path # variable. @@ -347,7 +342,7 @@ __gitcomp () local cur_="${3-$cur}" case "$cur_" in - --*=) + *=) ;; --no-*) local c i=0 IFS=$' \t\n' @@ -519,7 +514,7 @@ __gitcomp_builtin () local incl="${2-}" local excl="${3-}" - local var=__gitcomp_builtin_"${cmd/-/_}" + local var=__gitcomp_builtin_"${cmd//-/_}" local options eval "options=\${$var-}" @@ -1231,26 +1226,44 @@ __git_pretty_aliases () # __git_aliased_command requires 1 argument __git_aliased_command () { - local word cmdline=$(__git config --get "alias.$1") - for word in $cmdline; do - case "$word" in - \!gitk|gitk) - echo "gitk" - return - ;; - \!*) : shell command alias ;; - -*) : option ;; - *=*) : setting env ;; - git) : git itself ;; - \(\)) : skip parens of shell function definition ;; - {) : skip start of shell helper function ;; - :) : skip null command ;; - \'*) : skip opening quote after sh -c ;; - *) - echo "$word" + local cur=$1 last list word cmdline + + while [[ -n "$cur" ]]; do + if [[ "$list" == *" $cur "* ]]; then + # loop detected return - esac + fi + + cmdline=$(__git config --get "alias.$cur") + list=" $cur $list" + last=$cur + cur= + + for word in $cmdline; do + case "$word" in + \!gitk|gitk) + cur="gitk" + break + ;; + \!*) : shell command alias ;; + -*) : option ;; + *=*) : setting env ;; + git) : git itself ;; + \(\)) : skip parens of shell function definition ;; + {) : skip start of shell helper function ;; + :) : skip null command ;; + \'*) : skip opening quote after sh -c ;; + *) + cur="$word" + break + esac + done done + + cur=$last + if [[ "$cur" != "$1" ]]; then + echo "$cur" + fi } # Check whether one of the given words is present on the command line, @@ -2723,10 +2736,10 @@ __git_complete_config_variable_name () return ;; branch.*) - local pfx="${cur%.*}." - cur_="${cur#*.}" + local pfx="${cur_%.*}." + cur_="${cur_#*.}" __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")" - __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx" + __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx:- }" return ;; guitool.*.*) @@ -2760,7 +2773,7 @@ __git_complete_config_variable_name () local pfx="${cur_%.*}." cur_="${cur_#*.}" __git_compute_all_commands - __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx" + __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx:- }" return ;; remote.*.*) @@ -2776,7 +2789,7 @@ __git_complete_config_variable_name () local pfx="${cur_%.*}." cur_="${cur_#*.}" __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "." - __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "$sfx" + __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx:- }" return ;; url.*.*) diff --git a/plugins/gitfast/update b/plugins/gitfast/update index d0947e7d8..5311065a1 100755 --- a/plugins/gitfast/update +++ b/plugins/gitfast/update @@ -1,7 +1,7 @@ #!/bin/sh url="https://raw.githubusercontent.com/felipec/git-completion" -version="1.0" +version="1.2" curl -s -o _git "${url}/v${version}/git-completion.zsh" && curl -s -o git-completion.bash "${url}/v${version}/git-completion.bash" && -- cgit v1.2.3-70-g09d2