Skip to content

Commit b5a4947

Browse files
mstormogitster
authored andcommitted
Automatically autoload bashcompinit for ZSH, when needed
If bashcompinit has not already been autoloaded, do so automatically, as it is required to properly parse the git-completion file with ZSH. Helped-by: Felipe Contreras Signed-off-by: Marius Storm-Olsen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec014ea commit b5a4947

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

contrib/completion/git-completion.bash

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!bash
22
#
3-
# bash completion support for core Git.
3+
# bash/zsh completion support for core Git.
44
#
55
# Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]>
66
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
@@ -18,16 +18,12 @@
1818
# To use these routines:
1919
#
2020
# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
21-
# 2) Added the following line to your .bashrc:
22-
# source ~/.git-completion.sh
23-
#
24-
# Or, add the following lines to your .zshrc:
25-
# autoload bashcompinit
26-
# bashcompinit
21+
# 2) Add the following line to your .bashrc/.zshrc:
2722
# source ~/.git-completion.sh
2823
#
2924
# 3) Consider changing your PS1 to also show the current branch:
30-
# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
25+
# Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
26+
# ZSH: PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
3127
#
3228
# The argument to __git_ps1 will be displayed only if you
3329
# are currently in a git repository. The %s token will be
@@ -77,6 +73,10 @@
7773
7874
#
7975

76+
if [[ -n ${ZSH_VERSION-} ]]; then
77+
autoload -U +X bashcompinit && bashcompinit
78+
fi
79+
8080
case "$COMP_WORDBREAKS" in
8181
*:*) : great ;;
8282
*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"

0 commit comments

Comments
 (0)