completion: add new zsh completion

It seems there's always issues with zsh's bash completion emulation. I've tried to fix as many as I could[1], and most of the fixes are already in the latest version of zsh, but still, there are issues. There is no point going through all that pain; the emulation is easy to achieve, and this patch works better than zsh's bash completion emulation. [1] http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=commitdiff;h=23907bb840c80eef99eabba17e086e44c9b2d3fc Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Nov 18, 2012 at 12:08 UTC c9407860f47ec4cf1c64a2c2ca4ae0b451469658
1 file changed +78
contrib/completion/git-completion.zsh new
+78
@@ -0,0 +1,78 @@
1 +#compdef git gitk
2 +
3 +# zsh completion wrapper for git
4 +#
5 +# You need git's bash completion script installed somewhere, by default on the
6 +# same directory as this script.
7 +#
8 +# If your script is on ~/.git-completion.sh instead, you can configure it on
9 +# your ~/.zshrc:
10 +#
11 +# zstyle ':completion:*:*:git:*' script ~/.git-completion.sh
12 +#
13 +# The recommended way to install this script is to copy to
14 +# '~/.zsh/completion/_git', and then add the following to your ~/.zshrc file:
15 +#
16 +# fpath=(~/.zsh/completion $fpath)
17 +
18 +complete ()
19 +{
20 + # do nothing
21 + return 0
22 +}
23 +
24 +zstyle -s ":completion:*:*:git:*" script script
25 +test -z "$script" && script="$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
26 +ZSH_VERSION='' . "$script"
27 +
28 +__gitcomp ()
29 +{
30 + emulate -L zsh
31 +
32 + local cur_="${3-$cur}"
33 +
34 + case "$cur_" in
35 + --*=)
36 + ;;
37 + *)
38 + local c IFS=$' \t\n'
39 + local -a array
40 + for c in ${=1}; do
41 + c="$c${4-}"
42 + case $c in
43 + --*=*|*.) ;;
44 + *) c="$c " ;;
45 + esac
46 + array+=("$c")
47 + done
48 + compset -P '*[=:]'
49 + compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
50 + ;;
51 + esac
52 +}
53 +
54 +__gitcomp_nl ()
55 +{
56 + emulate -L zsh
57 +
58 + local IFS=$'\n'
59 + compset -P '*[=:]'
60 + compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
61 +}
62 +
63 +_git ()
64 +{
65 + local _ret=1
66 + () {
67 + emulate -L ksh
68 + local cur cword prev
69 + cur=${words[CURRENT-1]}
70 + prev=${words[CURRENT-2]}
71 + let cword=CURRENT-1
72 + __${service}_main
73 + }
74 + let _ret && _default -S '' && _ret=0
75 + return _ret
76 +}
77 +
78 +_git