mirror of
https://github.com/git/git
synced 2024-08-28 03:59:25 +00:00
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 ...
This commit is contained in:
commit
4560eae44f
|
@ -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
|
||||
|
@ -3464,88 +3463,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_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
|
||||
|
||||
|
@ -3567,18 +3486,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
|
||||
|
||||
|
@ -3586,6 +3493,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
|
||||
|
|
|
@ -2,27 +2,24 @@
|
|||
|
||||
# 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
|
||||
# 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:
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# 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 ':completion:*:*:git:*' tag-order 'common-commands'
|
||||
|
@ -30,18 +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
|
||||
'/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"
|
||||
"$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 ()
|
||||
{
|
||||
|
@ -52,13 +57,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")
|
||||
|
@ -73,44 +100,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
|
||||
}
|
||||
|
||||
__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
|
||||
compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0
|
||||
}
|
||||
|
||||
__gitcomp_file ()
|
||||
{
|
||||
emulate -L zsh
|
||||
|
||||
local IFS=$'\n'
|
||||
compset -P '*[=:]'
|
||||
compadd -p "${2-}" -f -- ${=1} && _ret=0
|
||||
compadd -f -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 ()
|
||||
|
@ -119,14 +159,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
|
||||
}
|
||||
|
||||
|
@ -163,8 +201,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 ()
|
||||
|
@ -202,10 +241,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
|
||||
|
@ -236,8 +278,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
|
||||
|
|
|
@ -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/}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2012 Felipe Contreras
|
||||
# Copyright (c) 2012-2020 Felipe Contreras
|
||||
#
|
||||
|
||||
test_description='test bash completion'
|
||||
|
|
Loading…
Reference in a new issue