completion: start moving to the new zsh completion

Zsh's bash completion emulation is buggy, not properly maintained, and we have some workarounds in place for different bugs that appeared in various versions. Since I'm the only one that has worked on that code lately[1], it might make snese to use the code I wrote specifically for git. The advantages are: 1) Less workarounds * No need to hack __get_comp_words_by_ref * No need to hack IFS or words 2) Improved features * 'git show master' now properly adds a space at the end (IFS bug) * 'git checkout --conflict=' now properly returns the sub-items (missing feature) 3) Consolidated code * It's all now in a single chunk, and it's basically the same as git-completion.zsh Since there's some interest in moving the zsh-specific code out of this script, lets go ahead and warn the users that they should be using git-completion.zsh. [1] http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=history;f=Completion/bashcompinit 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 d8b453149cdd0f900f2add9d891594cec37e3a56
1 file changed +61 -43
contrib/completion/git-completion.bash
+61 -43
@@ -23,10 +23,6 @@
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
25
26 -if [[ -n ${ZSH_VERSION-} ]]; then
27 - autoload -U +X bashcompinit && bashcompinit
28 -fi
29 -
26 case "$COMP_WORDBREAKS" in
27 *:*) : great ;;
28 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
@@ -169,7 +165,6 @@ __git_reassemble_comp_words_by_ref()
165 }
166
167 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
172 -if [[ -z ${ZSH_VERSION:+set} ]]; then
168 _get_comp_words_by_ref ()
169 {
170 local exclude cur_ words_ cword_
@@ -197,32 +192,6 @@ _get_comp_words_by_ref ()
192 shift
193 done
194 }
200 -else
201 -_get_comp_words_by_ref ()
202 -{
203 - while [ $# -gt 0 ]; do
204 - case "$1" in
205 - cur)
206 - cur=${COMP_WORDS[COMP_CWORD]}
207 - ;;
208 - prev)
209 - prev=${COMP_WORDS[COMP_CWORD-1]}
210 - ;;
211 - words)
212 - words=("${COMP_WORDS[@]}")
213 - ;;
214 - cword)
215 - cword=$COMP_CWORD
216 - ;;
217 - -n)
218 - # assume COMP_WORDBREAKS is already set sanely
219 - shift
220 - ;;
221 - esac
222 - shift
223 - done
224 -}
225 -fi
195 fi
196
197 # Generates completion reply with compgen, appending a space to possible
@@ -2430,20 +2399,69 @@ __gitk_main ()
2399 __git_complete_revlist
2400 }
2401
2433 -__git_func_wrap ()
2434 -{
2435 - if [[ -n ${ZSH_VERSION-} ]]; then
2436 - emulate -L bash
2437 - setopt KSH_TYPESET
2402 +if [[ -n ${ZSH_VERSION-} ]]; then
2403 + echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2404
2439 - # workaround zsh's bug that leaves 'words' as a special
2440 - # variable in versions < 4.3.12
2441 - typeset -h words
2405 + __gitcomp ()
2406 + {
2407 + emulate -L zsh
2408
2443 - # workaround zsh's bug that quotes spaces in the COMPREPLY
2444 - # array if IFS doesn't contain spaces.
2445 - typeset -h IFS
2446 - fi
2409 + local cur_="${3-$cur}"
2410 +
2411 + case "$cur_" in
2412 + --*=)
2413 + ;;
2414 + *)
2415 + local c IFS=$' \t\n'
2416 + local -a array
2417 + for c in ${=1}; do
2418 + c="$c${4-}"
2419 + case $c in
2420 + --*=*|*.) ;;
2421 + *) c="$c " ;;
2422 + esac
2423 + array+=("$c")
2424 + done
2425 + compset -P '*[=:]'
2426 + compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2427 + ;;
2428 + esac
2429 + }
2430 +
2431 + __gitcomp_nl ()
2432 + {
2433 + emulate -L zsh
2434 +
2435 + local IFS=$'\n'
2436 + compset -P '*[=:]'
2437 + compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2438 + }
2439 +
2440 + __git_zsh_helper ()
2441 + {
2442 + emulate -L ksh
2443 + local cur cword prev
2444 + cur=${words[CURRENT-1]}
2445 + prev=${words[CURRENT-2]}
2446 + let cword=CURRENT-1
2447 + __${service}_main
2448 + }
2449 +
2450 + _git ()
2451 + {
2452 + emulate -L zsh
2453 + local _ret=1
2454 + __git_zsh_helper
2455 + let _ret && _default -S '' && _ret=0
2456 + return _ret
2457 + }
2458 +
2459 + compdef _git git gitk
2460 + return
2461 +fi
2462 +
2463 +__git_func_wrap ()
2464 +{
2465 local cur words cword prev
2466 _get_comp_words_by_ref -n =: cur words cword prev
2467 $1