|
@@ -2,25 +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:
|
|
|
#
|
|
|
-# 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
|