1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-22 13:50:09 +00:00

feat(gitfast): update to git-completion 1.2 (#9458)

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
This commit is contained in:
Felipe Contreras 2020-11-19 12:45:19 -06:00 committed by GitHub
parent ce836647e5
commit e92a4667cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 111 additions and 99 deletions

View file

@ -45,71 +45,49 @@ fi
local old_complete="$functions[complete]" local old_complete="$functions[complete]"
functions[complete]=: functions[complete]=:
COMP_WORDBREAKS=':'
GIT_SOURCING_ZSH_COMPLETION=y . "$script" GIT_SOURCING_ZSH_COMPLETION=y . "$script"
functions[complete]="$old_complete" functions[complete]="$old_complete"
__gitcompadd ()
{
compadd -Q -p "${2-}" -S "${3- }" ${@[4,-1]} -- ${=1} && _ret=0
}
__gitcomp () __gitcomp ()
{ {
emulate -L zsh emulate -L zsh
local cur_="${3-$cur}" local cur_="${3-$cur}"
case "$cur_" in [[ "$cur_" == *= ]] && return
--*=)
;; local c IFS=$' \t\n' sfx
--no-*)
local c IFS=$' \t\n'
local -a array
for c in ${=1}; do for c in ${=1}; do
if [[ $c == "--" ]]; then if [[ $c == "--" ]]; then
continue [[ "$cur_" == --no-* ]] && continue
fi __gitcompadd "--no-..."
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 break
fi fi
c="$c${4-}"
if [[ -z "${4-}" ]]; then
case $c in case $c in
--*=|*.) ;; *=) c="${c%=}"; sfx="=" ;;
*) c="$c " ;; *.) sfx="" ;;
*) sfx=" " ;;
esac esac
array+=("$c") else
sfx="$4"
fi
__gitcompadd "$c" "${2-}" "$sfx" -q
done done
compset -P '*[=:]'
compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
;;
esac
}
__gitcomp_direct ()
{
emulate -L zsh
compset -P '*[=:]'
compadd -Q -S '' -- ${(f)1} && _ret=0
} }
__gitcomp_nl () __gitcomp_nl ()
{ {
emulate -L zsh emulate -L zsh
compset -P '*[=:]' IFS=$'\n' __gitcompadd "$1" "${2-}" "${4- }"
compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0
} }
__gitcomp_file () __gitcomp_file ()
@ -119,14 +97,9 @@ __gitcomp_file ()
compadd -f -p "${2-}" -- ${(f)1} && _ret=0 compadd -f -p "${2-}" -- ${(f)1} && _ret=0
} }
__gitcomp_direct_append () __gitcomp_direct ()
{ {
__gitcomp_direct "$@" __gitcomp_nl "$1" "" "" ""
}
__gitcomp_nl_append ()
{
__gitcomp_nl "$@"
} }
__gitcomp_file_direct () __gitcomp_file_direct ()
@ -134,20 +107,35 @@ __gitcomp_file_direct ()
__gitcomp_file "$1" "" __gitcomp_file "$1" ""
} }
__gitcomp_nl_append ()
{
__gitcomp_nl "$@"
}
__gitcomp_direct_append ()
{
__gitcomp_direct "$@"
}
_git_zsh () _git_zsh ()
{ {
__gitcomp "v1.0" __gitcomp "v1.2"
} }
__git_complete_command () __git_complete_command ()
{ {
emulate -L zsh emulate -L zsh
compset -P '*[=:]'
local command="$1" local command="$1"
local completion_func="_git_${command//-/_}" local completion_func="_git_${command//-/_}"
if (( $+functions[$completion_func] )); then if (( $+functions[$completion_func] )); then
emulate ksh -c $completion_func emulate ksh -c $completion_func
return 0 return 0
elif emulate ksh -c "__git_support_parseopt_helper $command"; then
emulate ksh -c "__git_complete_common $command"
return 0
else else
return 1 return 1
fi fi
@ -218,24 +206,27 @@ __git_zsh_main ()
{ {
local curcontext="$curcontext" state state_descr line local curcontext="$curcontext" state state_descr line
typeset -A opt_args typeset -A opt_args
local -a orig_words local -a orig_words __git_C_args
orig_words=( ${words[@]} ) orig_words=( ${words[@]} )
_arguments -C \ _arguments -C \
'(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \ '(-p --paginate -P --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \
'(-p --paginate)--no-pager[do not pipe git output into a pager]' \ '(-p --paginate -P --no-pager)'{-P,--no-pager}'[do not pipe git output into a pager]' \
'--git-dir=-[set the path to the repository]: :_directories' \ '(--bare)--git-dir=[set the path to the repository]: :_directories' \
'--bare[treat the repository as a bare repository]' \ '(--git-dir)--bare[treat the repository as a bare repository]' \
'(- :)--version[prints the git suite version]' \ '(- :)--version[prints the git suite version]' \
'--exec-path=-[path to where your core git programs are installed]:: :_directories' \ '--exec-path=[path to where your core git programs are installed]: :_directories' \
'--html-path[print the path where git''s HTML documentation is installed]' \ '(- :)--exec-path[print the path where your core git programs are installed]' \
'--info-path[print the path where the Info files are installed]' \ '(- :)--html-path[print the path where git''s HTML documentation is installed]' \
'--man-path[print the manpath (see `man(1)`) for the man pages]' \ '(- :)--info-path[print the path where the Info files are installed]' \
'--work-tree=-[set the path to the working tree]: :_directories' \ '(- :)--man-path[print the manpath (see `man(1)`) for the man pages]' \
'--namespace=-[set the git namespace]' \ '--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]' \ '--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' \ '(- :)--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' \ '(-): :->command' \
'(-)*:: :->arg' && return '(-)*:: :->arg' && return
@ -249,15 +240,23 @@ __git_zsh_main ()
let _ret || break let _ret || break
done done
;; ;;
(config)
compset -P '*[=:]'
emulate ksh -c __git_complete_config_variable_name_and_value
;;
(arg) (arg)
local command="${words[1]}" __git_dir local command="${words[1]}" __git_dir
if (( $+opt_args[--bare] )); then if (( $+opt_args[--bare] )); then
__git_dir='.' __git_dir='.'
else else
__git_dir=${opt_args[--git-dir]} __git_dir=${~opt_args[--git-dir]}
fi fi
for x in ${(s.:.)opt_args[-C]}; do
__git_C_args+=('-C' ${~x})
done
(( $+opt_args[--help] )) && command='help' (( $+opt_args[--help] )) && command='help'
words=( ${orig_words[@]} ) words=( ${orig_words[@]} )

View file

@ -45,11 +45,6 @@
# When set to "1" suggest all options, including options which are # When set to "1" suggest all options, including options which are
# typically hidden (e.g. '--allow-empty' for 'git commit'). # 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=<path>' and # Discovers the path to the git repository taking any '--git-dir=<path>' and
# '-C <path>' options into account and stores it in the $__git_repo_path # '-C <path>' options into account and stores it in the $__git_repo_path
# variable. # variable.
@ -347,7 +342,7 @@ __gitcomp ()
local cur_="${3-$cur}" local cur_="${3-$cur}"
case "$cur_" in case "$cur_" in
--*=) *=)
;; ;;
--no-*) --no-*)
local c i=0 IFS=$' \t\n' local c i=0 IFS=$' \t\n'
@ -519,7 +514,7 @@ __gitcomp_builtin ()
local incl="${2-}" local incl="${2-}"
local excl="${3-}" local excl="${3-}"
local var=__gitcomp_builtin_"${cmd/-/_}" local var=__gitcomp_builtin_"${cmd//-/_}"
local options local options
eval "options=\${$var-}" eval "options=\${$var-}"
@ -1231,12 +1226,24 @@ __git_pretty_aliases ()
# __git_aliased_command requires 1 argument # __git_aliased_command requires 1 argument
__git_aliased_command () __git_aliased_command ()
{ {
local word cmdline=$(__git config --get "alias.$1") local cur=$1 last list word cmdline
while [[ -n "$cur" ]]; do
if [[ "$list" == *" $cur "* ]]; then
# loop detected
return
fi
cmdline=$(__git config --get "alias.$cur")
list=" $cur $list"
last=$cur
cur=
for word in $cmdline; do for word in $cmdline; do
case "$word" in case "$word" in
\!gitk|gitk) \!gitk|gitk)
echo "gitk" cur="gitk"
return break
;; ;;
\!*) : shell command alias ;; \!*) : shell command alias ;;
-*) : option ;; -*) : option ;;
@ -1247,10 +1254,16 @@ __git_aliased_command ()
:) : skip null command ;; :) : skip null command ;;
\'*) : skip opening quote after sh -c ;; \'*) : skip opening quote after sh -c ;;
*) *)
echo "$word" cur="$word"
return break
esac esac
done done
done
cur=$last
if [[ "$cur" != "$1" ]]; then
echo "$cur"
fi
} }
# Check whether one of the given words is present on the command line, # Check whether one of the given words is present on the command line,
@ -2723,10 +2736,10 @@ __git_complete_config_variable_name ()
return return
;; ;;
branch.*) branch.*)
local pfx="${cur%.*}." local pfx="${cur_%.*}."
cur_="${cur#*.}" cur_="${cur_#*.}"
__gitcomp_direct "$(__git_heads "$pfx" "$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 return
;; ;;
guitool.*.*) guitool.*.*)
@ -2760,7 +2773,7 @@ __git_complete_config_variable_name ()
local pfx="${cur_%.*}." local pfx="${cur_%.*}."
cur_="${cur_#*.}" cur_="${cur_#*.}"
__git_compute_all_commands __git_compute_all_commands
__gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx" __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx:- }"
return return
;; ;;
remote.*.*) remote.*.*)
@ -2776,7 +2789,7 @@ __git_complete_config_variable_name ()
local pfx="${cur_%.*}." local pfx="${cur_%.*}."
cur_="${cur_#*.}" cur_="${cur_#*.}"
__gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "." __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
__gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "$sfx" __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx:- }"
return return
;; ;;
url.*.*) url.*.*)

View file

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
url="https://raw.githubusercontent.com/felipec/git-completion" 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 "${url}/v${version}/git-completion.zsh" &&
curl -s -o git-completion.bash "${url}/v${version}/git-completion.bash" && curl -s -o git-completion.bash "${url}/v${version}/git-completion.bash" &&