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 <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
May 24, 2013 at 22:31 UTC
3646b1a5ab47e535a746da10e5461ba70a0b652d
1 file changed
+19
-8
contrib/completion/git-completion.zsh
+19
-8
@@ -4,18 +4,17 @@
4
#
5
# Copyright (c) 2012-2013 Felipe Contreras <felipe.contreras@gmail.com>
6
#
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.
9
#
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:
11
#
12
# zstyle ':completion:*:*:git:*' script ~/.git-completion.sh
13
#
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:
16
#
18
-# fpath=(~/.zsh/completion $fpath)
17
+# fpath=(~/.zsh $fpath)
18
19
complete ()
20
{
@@ -27,7 +26,19 @@ zstyle -T ':completion:*:*:git:*' tag-order && \
26
zstyle ':completion:*:*:git:*' tag-order 'common-commands'
27
28
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
42
ZSH_VERSION='' . "$script"
43
44
__gitcomp ()