Skip to content

Commit a9064b2

Browse files
committed
Merge branch 'fc/zsh-completion'
* fc/zsh-completion: completion: start moving to the new zsh completion completion: add new zsh completion
2 parents b893e88 + d8b4531 commit a9064b2

File tree

2 files changed

+139
-43
lines changed

2 files changed

+139
-43
lines changed

contrib/completion/git-completion.bash

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
# 3) Consider changing your PS1 to also show the current branch,
2424
# see git-prompt.sh for details.
2525

26-
if [[ -n ${ZSH_VERSION-} ]]; then
27-
autoload -U +X bashcompinit && bashcompinit
28-
fi
29-
3026
case "$COMP_WORDBREAKS" in
3127
*:*) : great ;;
3228
*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
@@ -169,7 +165,6 @@ __git_reassemble_comp_words_by_ref()
169165
}
170166

171167
if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
172-
if [[ -z ${ZSH_VERSION:+set} ]]; then
173168
_get_comp_words_by_ref ()
174169
{
175170
local exclude cur_ words_ cword_
@@ -197,32 +192,6 @@ _get_comp_words_by_ref ()
197192
shift
198193
done
199194
}
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
226195
fi
227196

228197
# Generates completion reply with compgen, appending a space to possible
@@ -2430,20 +2399,69 @@ __gitk_main ()
24302399
__git_complete_revlist
24312400
}
24322401

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
24382404

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
24422408

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+
{
24472465
local cur words cword prev
24482466
_get_comp_words_by_ref -n =: cur words cword prev
24492467
$1

contrib/completion/git-completion.zsh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)