Skip to content

Commit 3646b1a

Browse files
felipecgitster
authored andcommitted
completion: zsh: improve bash script loading
It's better to check in multiple locations, so the user doesn't have to. And update the documentation. Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 734b2f0 commit 3646b1a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

contrib/completion/git-completion.zsh

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
#
55
# Copyright (c) 2012-2013 Felipe Contreras <[email protected]>
66
#
7-
# You need git's bash completion script installed somewhere, by default on the
8-
# same directory as this script.
7+
# You need git's bash completion script installed somewhere, by default it
8+
# would be the location bash-completion uses.
99
#
10-
# If your script is on ~/.git-completion.sh instead, you can configure it on
11-
# your ~/.zshrc:
10+
# If your script is somewhere else, you can configure it on your ~/.zshrc:
1211
#
1312
# zstyle ':completion:*:*:git:*' script ~/.git-completion.sh
1413
#
15-
# The recommended way to install this script is to copy to
16-
# '~/.zsh/completion/_git', and then add the following to your ~/.zshrc file:
14+
# The recommended way to install this script is to copy to '~/.zsh/_git', and
15+
# then add the following to your ~/.zshrc file:
1716
#
18-
# fpath=(~/.zsh/completion $fpath)
17+
# fpath=(~/.zsh $fpath)
1918

2019
complete ()
2120
{
@@ -27,7 +26,19 @@ zstyle -T ':completion:*:*:git:*' tag-order && \
2726
zstyle ':completion:*:*:git:*' tag-order 'common-commands'
2827

2928
zstyle -s ":completion:*:*:git:*" script script
30-
test -z "$script" && script="$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
29+
if [ -z "$script" ]; then
30+
local -a locations
31+
local e
32+
locations=(
33+
'/etc/bash_completion.d/git' # fedora, old debian
34+
'/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
35+
'/usr/share/bash-completion/git' # gentoo
36+
$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
37+
)
38+
for e in $locations; do
39+
test -f $e && script="$e" && break
40+
done
41+
fi
3142
ZSH_VERSION='' . "$script"
3243

3344
__gitcomp ()

0 commit comments

Comments
 (0)