Merge branch 'fc/zsh-completion'
Zsh autocompletion (in contrib/) update. * fc/zsh-completion: (29 commits) zsh: update copyright notices completion: bash: remove old compat wrappers completion: bash: cleanup cygwin check completion: bash: trivial cleanup completion: zsh: add simple version check completion: zsh: trivial simplification completion: zsh: add alias descriptions completion: zsh: improve command tags completion: zsh: refactor command completion completion: zsh: shuffle functions around completion: zsh: simplify file_direct completion: zsh: simplify nl_append completion: zsh: trivial cleanup completion: zsh: simplify direct compadd completion: zsh: simplify compadd functions completion: zsh: fix splitting of words completion: zsh: add missing direct_append completion: fix conflict with bashcomp completion: zsh: fix completion for --no-.. options completion: bash: remove zsh wrapper ...maint
commit
4560eae44f
|
@ -416,14 +416,13 @@ __gitcomp_builtin ()
|
||||||
local options
|
local options
|
||||||
eval "options=\${$var-}"
|
eval "options=\${$var-}"
|
||||||
|
|
||||||
|
if [ -z "$options" ]; then
|
||||||
local completion_helper
|
local completion_helper
|
||||||
if [ "$GIT_COMPLETION_SHOW_ALL" = "1" ]; then
|
if [ "$GIT_COMPLETION_SHOW_ALL" = "1" ]; then
|
||||||
completion_helper="--git-completion-helper-all"
|
completion_helper="--git-completion-helper-all"
|
||||||
else
|
else
|
||||||
completion_helper="--git-completion-helper"
|
completion_helper="--git-completion-helper"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$options" ]; then
|
|
||||||
# leading and trailing spaces are significant to make
|
# leading and trailing spaces are significant to make
|
||||||
# option removal work correctly.
|
# option removal work correctly.
|
||||||
options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
|
options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
|
||||||
|
@ -3464,88 +3463,8 @@ __gitk_main ()
|
||||||
__git_complete_revlist
|
__git_complete_revlist
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ -n ${ZSH_VERSION-} ]] &&
|
if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
|
||||||
# Don't define these functions when sourced from 'git-completion.zsh',
|
echo "ERROR: this script is obsolete, please see git-completion.zsh" 1>&2
|
||||||
# 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_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
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -3567,18 +3486,6 @@ __git_complete ()
|
||||||
|| complete -o default -o nospace -F $wrapper $1
|
|| 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 git __git_main
|
||||||
__git_complete gitk __gitk_main
|
__git_complete gitk __gitk_main
|
||||||
|
|
||||||
|
@ -3586,6 +3493,6 @@ __git_complete gitk __gitk_main
|
||||||
# when the user has tab-completed the executable name and consequently
|
# when the user has tab-completed the executable name and consequently
|
||||||
# included the '.exe' suffix.
|
# included the '.exe' suffix.
|
||||||
#
|
#
|
||||||
if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
|
if [ "$OSTYPE" = cygwin ]; then
|
||||||
__git_complete git.exe __git_main
|
__git_complete git.exe __git_main
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -2,27 +2,24 @@
|
||||||
|
|
||||||
# zsh completion wrapper for git
|
# 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>
|
||||||
#
|
#
|
||||||
# You need git's bash completion script installed somewhere, by default it
|
# The recommended way to install this script is to make a copy of it as a
|
||||||
# would be the location bash-completion uses.
|
# 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:
|
||||||
|
#
|
||||||
|
# fpath=(~/.zsh $fpath)
|
||||||
|
#
|
||||||
|
# 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
|
# zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
|
||||||
#
|
#
|
||||||
# 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:
|
|
||||||
#
|
|
||||||
# fpath=(~/.zsh $fpath)
|
|
||||||
# autoload -Uz compinit && compinit
|
|
||||||
|
|
||||||
complete ()
|
|
||||||
{
|
|
||||||
# do nothing
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
zstyle -T ':completion:*:*:git:*' tag-order && \
|
zstyle -T ':completion:*:*:git:*' tag-order && \
|
||||||
zstyle ':completion:*:*:git:*' tag-order 'common-commands'
|
zstyle ':completion:*:*:git:*' tag-order 'common-commands'
|
||||||
|
@ -30,18 +27,26 @@ zstyle -T ':completion:*:*:git:*' tag-order && \
|
||||||
zstyle -s ":completion:*:*:git:*" script script
|
zstyle -s ":completion:*:*:git:*" script script
|
||||||
if [ -z "$script" ]; then
|
if [ -z "$script" ]; then
|
||||||
local -a locations
|
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=(
|
locations=(
|
||||||
$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
|
"$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
|
||||||
'/etc/bash_completion.d/git' # fedora, old debian
|
"$HOME/.local/share/bash-completion/completions/git"
|
||||||
'/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
|
"$bash_completion/git"
|
||||||
'/usr/share/bash-completion/git' # gentoo
|
'/etc/bash_completion.d/git' # old debian
|
||||||
)
|
)
|
||||||
for e in $locations; do
|
for e in $locations; do
|
||||||
test -f $e && script="$e" && break
|
test -f $e && script="$e" && break
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local old_complete="$functions[complete]"
|
||||||
|
functions[complete]=:
|
||||||
GIT_SOURCING_ZSH_COMPLETION=y . "$script"
|
GIT_SOURCING_ZSH_COMPLETION=y . "$script"
|
||||||
|
functions[complete]="$old_complete"
|
||||||
|
|
||||||
__gitcomp ()
|
__gitcomp ()
|
||||||
{
|
{
|
||||||
|
@ -52,13 +57,35 @@ __gitcomp ()
|
||||||
case "$cur_" in
|
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 c IFS=$' \t\n'
|
||||||
local -a array
|
local -a array
|
||||||
for c in ${=1}; do
|
for c in ${=1}; do
|
||||||
|
if [[ $c == "--" ]]; then
|
||||||
|
c="--no-...${4-}"
|
||||||
|
array+=("$c ")
|
||||||
|
break
|
||||||
|
fi
|
||||||
c="$c${4-}"
|
c="$c${4-}"
|
||||||
case $c in
|
case $c in
|
||||||
--*=*|*.) ;;
|
--*=|*.) ;;
|
||||||
*) c="$c " ;;
|
*) c="$c " ;;
|
||||||
esac
|
esac
|
||||||
array+=("$c")
|
array+=("$c")
|
||||||
|
@ -73,44 +100,57 @@ __gitcomp_direct ()
|
||||||
{
|
{
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
|
|
||||||
local IFS=$'\n'
|
|
||||||
compset -P '*[=:]'
|
compset -P '*[=:]'
|
||||||
compadd -Q -- ${=1} && _ret=0
|
compadd -Q -S '' -- ${(f)1} && _ret=0
|
||||||
}
|
}
|
||||||
|
|
||||||
__gitcomp_nl ()
|
__gitcomp_nl ()
|
||||||
{
|
{
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
|
|
||||||
local IFS=$'\n'
|
|
||||||
compset -P '*[=:]'
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
__gitcomp_file_direct ()
|
|
||||||
{
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
local IFS=$'\n'
|
|
||||||
compset -P '*[=:]'
|
|
||||||
compadd -f -- ${=1} && _ret=0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__gitcomp_file ()
|
__gitcomp_file ()
|
||||||
{
|
{
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
|
|
||||||
local IFS=$'\n'
|
compadd -f -p "${2-}" -- ${(f)1} && _ret=0
|
||||||
compset -P '*[=:]'
|
}
|
||||||
compadd -p "${2-}" -f -- ${=1} && _ret=0
|
|
||||||
|
__gitcomp_direct_append ()
|
||||||
|
{
|
||||||
|
__gitcomp_direct "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
__gitcomp_nl_append ()
|
||||||
|
{
|
||||||
|
__gitcomp_nl "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
__gitcomp_file_direct ()
|
||||||
|
{
|
||||||
|
__gitcomp_file "$1" ""
|
||||||
|
}
|
||||||
|
|
||||||
|
_git_zsh ()
|
||||||
|
{
|
||||||
|
__gitcomp "v1.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 ()
|
__git_zsh_bash_func ()
|
||||||
|
@ -119,14 +159,12 @@ __git_zsh_bash_func ()
|
||||||
|
|
||||||
local command=$1
|
local command=$1
|
||||||
|
|
||||||
local completion_func="_git_${command//-/_}"
|
__git_complete_command "$command" && return
|
||||||
declare -f $completion_func >/dev/null && $completion_func && return
|
|
||||||
|
|
||||||
local expansion=$(__git_aliased_command "$command")
|
local expansion=$(__git_aliased_command "$command")
|
||||||
if [ -n "$expansion" ]; then
|
if [ -n "$expansion" ]; then
|
||||||
words[1]=$expansion
|
words[1]=$expansion
|
||||||
completion_func="_git_${expansion//-/_}"
|
__git_complete_command "$expansion"
|
||||||
declare -f $completion_func >/dev/null && $completion_func
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,8 +201,9 @@ __git_zsh_cmd_common ()
|
||||||
__git_zsh_cmd_alias ()
|
__git_zsh_cmd_alias ()
|
||||||
{
|
{
|
||||||
local -a list
|
local -a list
|
||||||
list=(${${${(0)"$(git config -z --get-regexp '^alias\.')"}#alias.}%$'\n'*})
|
list=(${${(0)"$(git config -z --get-regexp '^alias\.*')"}#alias.})
|
||||||
_describe -t alias-commands 'aliases' list $* && _ret=0
|
list=(${(f)"$(printf "%s:alias for '%s'\n" ${(f@)list})"})
|
||||||
|
_describe -t alias-commands 'aliases' list && _ret=0
|
||||||
}
|
}
|
||||||
|
|
||||||
__git_zsh_cmd_all ()
|
__git_zsh_cmd_all ()
|
||||||
|
@ -202,10 +241,13 @@ __git_zsh_main ()
|
||||||
|
|
||||||
case $state in
|
case $state in
|
||||||
(command)
|
(command)
|
||||||
_alternative \
|
_tags common-commands alias-commands all-commands
|
||||||
'alias-commands:alias:__git_zsh_cmd_alias' \
|
while _tags; do
|
||||||
'common-commands:common:__git_zsh_cmd_common' \
|
_requested common-commands && __git_zsh_cmd_common
|
||||||
'all-commands:all:__git_zsh_cmd_all' && _ret=0
|
_requested alias-commands && __git_zsh_cmd_alias
|
||||||
|
_requested all-commands && __git_zsh_cmd_all
|
||||||
|
let _ret || break
|
||||||
|
done
|
||||||
;;
|
;;
|
||||||
(arg)
|
(arg)
|
||||||
local command="${words[1]}" __git_dir
|
local command="${words[1]}" __git_dir
|
||||||
|
@ -236,8 +278,12 @@ _git ()
|
||||||
|
|
||||||
if (( $+functions[__${service}_zsh_main] )); then
|
if (( $+functions[__${service}_zsh_main] )); then
|
||||||
__${service}_zsh_main
|
__${service}_zsh_main
|
||||||
else
|
elif (( $+functions[__${service}_main] )); then
|
||||||
emulate ksh -c __${service}_main
|
emulate ksh -c __${service}_main
|
||||||
|
elif (( $+functions[_${service}] )); then
|
||||||
|
emulate ksh -c _${service}
|
||||||
|
elif (( $+functions[_${service//-/_}] )); then
|
||||||
|
emulate ksh -c _${service//-/_}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
let _ret && _default && _ret=0
|
let _ret && _default && _ret=0
|
||||||
|
|
|
@ -97,7 +97,8 @@
|
||||||
# If you would like a colored hint about the current dirty state, set
|
# 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
|
# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
|
||||||
# the colored output of "git status -sb" and are available only when
|
# 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
|
# 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
|
# directory is set up to be ignored by git, then set
|
||||||
|
@ -553,10 +554,12 @@ __git_ps1 ()
|
||||||
|
|
||||||
local z="${GIT_PS1_STATESEPARATOR-" "}"
|
local z="${GIT_PS1_STATESEPARATOR-" "}"
|
||||||
|
|
||||||
# NO color option unless in PROMPT_COMMAND mode
|
# NO color option unless in PROMPT_COMMAND mode or it's Zsh
|
||||||
if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
|
if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
|
||||||
|
if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then
|
||||||
__git_ps1_colorize_gitstring
|
__git_ps1_colorize_gitstring
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
b=${b##refs/heads/}
|
b=${b##refs/heads/}
|
||||||
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
|
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# Copyright (c) 2012 Felipe Contreras
|
# Copyright (c) 2012-2020 Felipe Contreras
|
||||||
#
|
#
|
||||||
|
|
||||||
test_description='test bash completion'
|
test_description='test bash completion'
|
||||||
|
|
Loading…
Reference in New Issue