Skip to content

Commit 5a3a484

Browse files
committed
Merge branch 'ml/completion-zsh'
* ml/completion-zsh: completion: make compatible with zsh
2 parents a7b60f0 + 06f44c3 commit 5a3a484

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

contrib/completion/git-completion.bash

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
# 2) Added the following line to your .bashrc:
2222
# source ~/.git-completion.sh
2323
#
24+
# Or, add the following lines to your .zshrc:
25+
# autoload bashcompinit
26+
# bashcompinit
27+
# source ~/.git-completion.sh
28+
#
2429
# 3) Consider changing your PS1 to also show the current branch:
2530
# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
2631
#
@@ -138,11 +143,12 @@ __git_ps1_show_upstream ()
138143
# get the upstream from the "git-svn-id: ..." in a commit message
139144
# (git-svn uses essentially the same procedure internally)
140145
local svn_upstream=($(git log --first-parent -1 \
141-
--grep="^git-svn-id: \(${svn_url_pattern:2}\)" 2>/dev/null))
146+
--grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
142147
if [[ 0 -ne ${#svn_upstream[@]} ]]; then
143148
svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
144149
svn_upstream=${svn_upstream%@*}
145-
for ((n=1; "$n" <= "${#svn_remote[@]}"; ++n)); do
150+
local n_stop="${#svn_remote[@]}"
151+
for ((n=1; n <= n_stop; ++n)); do
146152
svn_upstream=${svn_upstream#${svn_remote[$n]}}
147153
done
148154

@@ -2339,6 +2345,11 @@ _git ()
23392345
{
23402346
local i c=1 command __git_dir
23412347

2348+
if [[ -n $ZSH_VERSION ]]; then
2349+
emulate -L bash
2350+
setopt KSH_TYPESET
2351+
fi
2352+
23422353
while [ $c -lt $COMP_CWORD ]; do
23432354
i="${COMP_WORDS[c]}"
23442355
case "$i" in
@@ -2372,17 +2383,22 @@ _git ()
23722383
fi
23732384

23742385
local completion_func="_git_${command//-/_}"
2375-
declare -F $completion_func >/dev/null && $completion_func && return
2386+
declare -f $completion_func >/dev/null && $completion_func && return
23762387

23772388
local expansion=$(__git_aliased_command "$command")
23782389
if [ -n "$expansion" ]; then
23792390
completion_func="_git_${expansion//-/_}"
2380-
declare -F $completion_func >/dev/null && $completion_func
2391+
declare -f $completion_func >/dev/null && $completion_func
23812392
fi
23822393
}
23832394

23842395
_gitk ()
23852396
{
2397+
if [[ -n $ZSH_VERSION ]]; then
2398+
emulate -L bash
2399+
setopt KSH_TYPESET
2400+
fi
2401+
23862402
__git_has_doubledash && return
23872403

23882404
local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -2417,3 +2433,29 @@ if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
24172433
complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
24182434
|| complete -o default -o nospace -F _git git.exe
24192435
fi
2436+
2437+
if [[ -n $ZSH_VERSION ]]; then
2438+
shopt () {
2439+
local option
2440+
if [ $# -ne 2 ]; then
2441+
echo "USAGE: $0 (-q|-s|-u) <option>" >&2
2442+
return 1
2443+
fi
2444+
case "$2" in
2445+
nullglob)
2446+
option="$2"
2447+
;;
2448+
*)
2449+
echo "$0: invalid option: $2" >&2
2450+
return 1
2451+
esac
2452+
case "$1" in
2453+
-q) setopt | grep -q "$option" ;;
2454+
-u) unsetopt "$option" ;;
2455+
-s) setopt "$option" ;;
2456+
*)
2457+
echo "$0: invalid flag: $1" >&2
2458+
return 1
2459+
esac
2460+
}
2461+
fi

0 commit comments

Comments
 (0)