* [PATCH] Refactor git-completion to allow ZSH usage of PS1 functions
@ 2011-04-26 13:24 Marius Storm-Olsen
2011-04-26 17:21 ` Junio C Hamano
0 siblings, 1 reply; 11+ messages in thread
From: Marius Storm-Olsen @ 2011-04-26 13:24 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: git, Marius Storm-Olsen
The PS1 functions in git-completion are simple functions which
work just as well for ZSH as for Bash. So, refactoring them out
allows ZSH users to also use them, 'standardizing' the prompt\
for Git.
The only thing not supported by ZSH is the
__git_ps1_show_upstream
function, so this functionality is simply forced disabled there.
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
This patch is mainly just moving the two functions
__gitdir
__git_ps1
out into a new file. However, the most "nasty" is the way this
file is then included from the original git-completion.bash
file, with
GIT_COMPLETION_BASH_ONLY=1
source $(dirname ${BASH_SOURCE[0]})/git-prompt-functions
where the variable ensures that only Bash will include the
__git_ps1_show_upstream
function call, and then the PS1 functions are loaded via a
dirname'd BASH_SOURCE[0]. I am by no means a Bash guru, so
others will have to evaluate the compatability of using this
technique outside of Bash on Linux. Relying on $0 at least,
does not work.
Someone will also have to verify the RPM part at the bottom.
contrib/completion/git-completion.bash | 117 +-----------------------
contrib/completion/git-prompt-functions | 149 +++++++++++++++++++++++++++++++
git.spec.in | 1 +
3 files changed, 153 insertions(+), 114 deletions(-)
create mode 100755 contrib/completion/git-prompt-functions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 840ae38..417cb0a 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -82,25 +82,6 @@ case "$COMP_WORDBREAKS" in
*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
esac
-# __gitdir accepts 0 or 1 arguments (i.e., location)
-# returns location of .git repo
-__gitdir ()
-{
- if [ -z "${1-}" ]; then
- if [ -n "${__git_dir-}" ]; then
- echo "$__git_dir"
- elif [ -d .git ]; then
- echo .git
- else
- git rev-parse --git-dir 2>/dev/null
- fi
- elif [ -d "$1/.git" ]; then
- echo "$1/.git"
- else
- echo "$1"
- fi
-}
-
# stores the divergence from upstream in $p
# used by GIT_PS1_SHOWUPSTREAM
__git_ps1_show_upstream ()
@@ -220,101 +201,9 @@ __git_ps1_show_upstream ()
}
-
-# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
-# returns text to add to bash PS1 prompt (includes branch name)
-__git_ps1 ()
-{
- local g="$(__gitdir)"
- if [ -n "$g" ]; then
- local r=""
- local b=""
- if [ -f "$g/rebase-merge/interactive" ]; then
- r="|REBASE-i"
- b="$(cat "$g/rebase-merge/head-name")"
- elif [ -d "$g/rebase-merge" ]; then
- r="|REBASE-m"
- b="$(cat "$g/rebase-merge/head-name")"
- else
- if [ -d "$g/rebase-apply" ]; then
- if [ -f "$g/rebase-apply/rebasing" ]; then
- r="|REBASE"
- elif [ -f "$g/rebase-apply/applying" ]; then
- r="|AM"
- else
- r="|AM/REBASE"
- fi
- elif [ -f "$g/MERGE_HEAD" ]; then
- r="|MERGING"
- elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
- r="|CHERRY-PICKING"
- elif [ -f "$g/BISECT_LOG" ]; then
- r="|BISECTING"
- fi
-
- b="$(git symbolic-ref HEAD 2>/dev/null)" || {
-
- b="$(
- case "${GIT_PS1_DESCRIBE_STYLE-}" in
- (contains)
- git describe --contains HEAD ;;
- (branch)
- git describe --contains --all HEAD ;;
- (describe)
- git describe HEAD ;;
- (* | default)
- git describe --tags --exact-match HEAD ;;
- esac 2>/dev/null)" ||
-
- b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
- b="unknown"
- b="($b)"
- }
- fi
-
- local w=""
- local i=""
- local s=""
- local u=""
- local c=""
- local p=""
-
- if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
- if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
- c="BARE:"
- else
- b="GIT_DIR!"
- fi
- elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
- if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
- if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
- git diff --no-ext-diff --quiet --exit-code || w="*"
- if git rev-parse --quiet --verify HEAD >/dev/null; then
- git diff-index --cached --quiet HEAD -- || i="+"
- else
- i="#"
- fi
- fi
- fi
- if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
- git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
- fi
-
- if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
- if [ -n "$(git ls-files --others --exclude-standard)" ]; then
- u="%"
- fi
- fi
-
- if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
- __git_ps1_show_upstream
- fi
- fi
-
- local f="$w$i$s$u"
- printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
- fi
-}
+# load the __git_ps1 functionality
+GIT_COMPLETION_BASH_ONLY=1
+source $(dirname ${BASH_SOURCE[0]})/git-prompt-functions
# __gitcomp_1 requires 2 arguments
__gitcomp_1 ()
diff --git a/contrib/completion/git-prompt-functions b/contrib/completion/git-prompt-functions
new file mode 100755
index 0000000..89d9449
--- /dev/null
+++ b/contrib/completion/git-prompt-functions
@@ -0,0 +1,149 @@
+#!bash
+#
+# bash/zsh prompt functions for core Git.
+#
+# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
+#
+# This code was originially in git-completion.bash. However,
+# since this code works just fine also for ZSH, it was refactored
+# out, to allow ZSH users to source only the prompt functionality,
+# given that ZSH already comes with git completion of its own.
+#
+# Bash users might consider setting
+# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
+# while the ZSH equivalent would be
+# PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
+#
+# You may set the following values to tweak the output of the
+# __git_ps1() function:
+#
+# GIT_PS1_SHOWDIRTYSTATE=true
+# Reports if in a dirty state
+# '*' means modified file(s)
+# '+' means added file(s)
+#
+# GIT_PS1_SHOWSTASHSTATE=true
+# Reports the current stash state
+#
+# GIT_PS1_SHOWUNTRACKEDFILES=true
+# Reports if there are untracked files in the repo
+#
+# GIT_PS1_SHOWUPSTREAM=auto
+# Places the divergence of repo against upstream, in variable 'p'
+# (Use $p in Bash prompts. Not available in ZSH prompts)
+#
+# See git-completion.bash for other details
+
+# __gitdir accepts 0 or 1 arguments (i.e., location)
+# returns location of .git repo
+__gitdir ()
+{
+ if [ -z "${1-}" ]; then
+ if [ -n "${__git_dir-}" ]; then
+ echo "$__git_dir"
+ elif [ -d .git ]; then
+ echo .git
+ else
+ git rev-parse --git-dir 2>/dev/null
+ fi
+ elif [ -d "$1/.git" ]; then
+ echo "$1/.git"
+ else
+ echo "$1"
+ fi
+}
+
+# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
+# returns text to add to bash PS1 prompt (includes branch name)
+__git_ps1 ()
+{
+ local g="$(__gitdir)"
+ if [ -n "$g" ]; then
+ local r=""
+ local b=""
+ if [ -f "$g/rebase-merge/interactive" ]; then
+ r="|REBASE-i"
+ b="$(cat "$g/rebase-merge/head-name")"
+ elif [ -d "$g/rebase-merge" ]; then
+ r="|REBASE-m"
+ b="$(cat "$g/rebase-merge/head-name")"
+ else
+ if [ -d "$g/rebase-apply" ]; then
+ if [ -f "$g/rebase-apply/rebasing" ]; then
+ r="|REBASE"
+ elif [ -f "$g/rebase-apply/applying" ]; then
+ r="|AM"
+ else
+ r="|AM/REBASE"
+ fi
+ elif [ -f "$g/MERGE_HEAD" ]; then
+ r="|MERGING"
+ elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
+ r="|CHERRY-PICKING"
+ elif [ -f "$g/BISECT_LOG" ]; then
+ r="|BISECTING"
+ fi
+
+ b="$(git symbolic-ref HEAD 2>/dev/null)" || {
+
+ b="$(
+ case "${GIT_PS1_DESCRIBE_STYLE-}" in
+ (contains)
+ git describe --contains HEAD ;;
+ (branch)
+ git describe --contains --all HEAD ;;
+ (describe)
+ git describe HEAD ;;
+ (* | default)
+ git describe --tags --exact-match HEAD ;;
+ esac 2>/dev/null)" ||
+
+ b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
+ b="unknown"
+ b="($b)"
+ }
+ fi
+
+ local w=""
+ local i=""
+ local s=""
+ local u=""
+ local c=""
+ local p=""
+
+ if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
+ if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
+ c="BARE:"
+ else
+ b="GIT_DIR!"
+ fi
+ elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
+ if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
+ if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
+ git diff --no-ext-diff --quiet --exit-code || w="*"
+ if git rev-parse --quiet --verify HEAD >/dev/null; then
+ git diff-index --cached --quiet HEAD -- || i="+"
+ else
+ i="#"
+ fi
+ fi
+ fi
+ if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
+ git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
+ fi
+
+ if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
+ if [ -n "$(git ls-files --others --exclude-standard)" ]; then
+ u="%"
+ fi
+ fi
+
+ if [ -n "${GIT_COMPLETION_BASH_ONLY-}" ] && [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
+ __git_ps1_show_upstream
+ fi
+ fi
+
+ local f="$w$i$s$u"
+ printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
+ fi
+}
diff --git a/git.spec.in b/git.spec.in
index 91c8462..c81385e 100644
--- a/git.spec.in
+++ b/git.spec.in
@@ -137,6 +137,7 @@ rm -rf $RPM_BUILD_ROOT%{_mandir}
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/bash_completion.d
install -m 644 -T contrib/completion/git-completion.bash $RPM_BUILD_ROOT%{_sysconfdir}/bash_completion.d/git
+install -m 644 -T contrib/completion/git-prompt-functions $RPM_BUILD_ROOT%{_sysconfdir}/bash_completion.d/git-prompt-functions
%clean
rm -rf $RPM_BUILD_ROOT
--
1.7.5.rc2.4.g4d8b3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] Refactor git-completion to allow ZSH usage of PS1 functions
2011-04-26 13:24 [PATCH] Refactor git-completion to allow ZSH usage of PS1 functions Marius Storm-Olsen
@ 2011-04-26 17:21 ` Junio C Hamano
2011-04-26 17:37 ` Marius Storm-Olsen
0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2011-04-26 17:21 UTC (permalink / raw)
To: Marius Storm-Olsen; +Cc: Shawn O. Pearce, git, Marius Storm-Olsen
I'd be very negative on splitting this file into more than one files.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Refactor git-completion to allow ZSH usage of PS1 functions
2011-04-26 17:21 ` Junio C Hamano
@ 2011-04-26 17:37 ` Marius Storm-Olsen
2011-04-26 19:15 ` Junio C Hamano
0 siblings, 1 reply; 11+ messages in thread
From: Marius Storm-Olsen @ 2011-04-26 17:37 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Marius Storm-Olsen, Shawn O. Pearce, git
Junio C Hamano said the following on 26.04.2011 12:21:
> I'd be very negative on splitting this file into more than one files.
The only other option would be duplication. Is that preferred?
I was hoping to more easily keep the implementations in sync, given
that the code is trivial enough for both shells to interpret. However,
having two separate implementations would allow for more advanced
options in the ZSH PSx handling, I guess.
--
.marius
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Refactor git-completion to allow ZSH usage of PS1 functions
2011-04-26 17:37 ` Marius Storm-Olsen
@ 2011-04-26 19:15 ` Junio C Hamano
2011-04-26 20:28 ` [PATCH] Automatically autoload bashcompinit for ZSH, when needed Marius Storm-Olsen
0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2011-04-26 19:15 UTC (permalink / raw)
To: Marius Storm-Olsen; +Cc: Marius Storm-Olsen, Shawn O. Pearce, git
Marius Storm-Olsen <mstormo@gmail.com> writes:
> Junio C Hamano said the following on 26.04.2011 12:21:
>> I'd be very negative on splitting this file into more than one files.
>
> The only other option would be duplication. Is that preferred?
That is not the answer I was hoping to hear. Can't we think of a way to
share without duplication the common parts and have tweaks per two shell
implementations?
A conditional that says "Do this part only if I am zsh" in a single file
is fine. Makefile that concatenates the common one and specific one among
two would also be acceptable, even though it makes things more cumbersome
to the user. But no matter what you do, I would really prefer for the
user to have to copy just _one_ file, not two.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] Automatically autoload bashcompinit for ZSH, when needed
2011-04-26 19:15 ` Junio C Hamano
@ 2011-04-26 20:28 ` Marius Storm-Olsen
2011-04-26 20:47 ` Matthieu Moy
2011-04-27 1:11 ` Felipe Contreras
0 siblings, 2 replies; 11+ messages in thread
From: Marius Storm-Olsen @ 2011-04-26 20:28 UTC (permalink / raw)
To: Shawn O. Pearce, Junio C Hamano; +Cc: git, Marius Storm-Olsen
If bashcompinit has not already been autoloaded, do so
automatically, as it is required to properly parse the
git-completion file with ZSH.
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
Since I rebased the previous version, I didn't notice that some
effort had already gone into making git-completion.bash parsable
with ZSH.
I've therefore dropped everything from the previous patch, and
rather added some code to automatically do the required steps
for ZSH, should it not have been done already; as well as
simplified the 'documentation'.
My appologies for not more closely inspecting the recent changes
to the file.
contrib/completion/git-completion.bash | 19 +++++++++++--------
1 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 840ae38..35d1c9b 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1,6 +1,6 @@
#!bash
#
-# bash completion support for core Git.
+# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
@@ -18,16 +18,12 @@
# To use these routines:
#
# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
-# 2) Added the following line to your .bashrc:
-# source ~/.git-completion.sh
-#
-# Or, add the following lines to your .zshrc:
-# autoload bashcompinit
-# bashcompinit
+# 2) Added the following line to your .bashrc/.zshrc:
# source ~/.git-completion.sh
#
# 3) Consider changing your PS1 to also show the current branch:
-# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
+# Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
+# ZSH: PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
#
# The argument to __git_ps1 will be displayed only if you
# are currently in a git repository. The %s token will be
@@ -77,6 +73,13 @@
# git@vger.kernel.org
#
+if [[ -n ${ZSH_VERSION-} ]]; then
+ if ! bashcompinit >/dev/null 2>&1; then
+ autoload -U bashcompinit
+ bashcompinit
+ fi
+fi
+
case "$COMP_WORDBREAKS" in
*:*) : great ;;
*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
--
1.7.5.rc2.4.g4d8b3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] Automatically autoload bashcompinit for ZSH, when needed
2011-04-26 20:28 ` [PATCH] Automatically autoload bashcompinit for ZSH, when needed Marius Storm-Olsen
@ 2011-04-26 20:47 ` Matthieu Moy
2011-04-26 20:52 ` Marius Storm-Olsen
2011-04-27 1:11 ` Felipe Contreras
1 sibling, 1 reply; 11+ messages in thread
From: Matthieu Moy @ 2011-04-26 20:47 UTC (permalink / raw)
To: Marius Storm-Olsen
Cc: Shawn O. Pearce, Junio C Hamano, git, Marius Storm-Olsen
Marius Storm-Olsen <marius@storm-olsen.com> writes:
> -# 2) Added the following line to your .bashrc:
> +# 2) Added the following line to your .bashrc/.zshrc:
While you're there: shouldn't this be "Add", not "Added"?
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Automatically autoload bashcompinit for ZSH, when needed
2011-04-26 20:47 ` Matthieu Moy
@ 2011-04-26 20:52 ` Marius Storm-Olsen
2011-04-26 21:55 ` Junio C Hamano
0 siblings, 1 reply; 11+ messages in thread
From: Marius Storm-Olsen @ 2011-04-26 20:52 UTC (permalink / raw)
To: Matthieu Moy; +Cc: Shawn O. Pearce, Junio C Hamano, git, Marius Storm-Olsen
Agreed.
I'm away from my machines right now, so if anyone feels like rerolling the patch with that update, that'd be great.
Or Junio could just fix it up when/if picking it.
If not, I'll reroll later tonight.
Thanks!
--
.marius @ N900
----- Original message -----
> Marius Storm-Olsen <marius@storm-olsen.com> writes:
>
> > -# 2) Added the following line to your .bashrc:
>
> > +# 2) Added the following line to your .bashrc/.zshrc:
>
> While you're there: shouldn't this be "Add", not "Added"?
>
> --
> Matthieu Moy
> http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Automatically autoload bashcompinit for ZSH, when needed
2011-04-26 20:52 ` Marius Storm-Olsen
@ 2011-04-26 21:55 ` Junio C Hamano
0 siblings, 0 replies; 11+ messages in thread
From: Junio C Hamano @ 2011-04-26 21:55 UTC (permalink / raw)
To: Marius Storm-Olsen; +Cc: Matthieu Moy, Shawn O. Pearce, git, Marius Storm-Olsen
Marius Storm-Olsen <marius@storm-olsen.com> writes:
> Or Junio could just fix it up when/if picking it.
Surely, no problem.
I do not use zsh myself, so unless a real zsh user complains, I'll queue
it directly on 'master' as part of the batch for the first week.
Thanks.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Automatically autoload bashcompinit for ZSH, when needed
2011-04-26 20:28 ` [PATCH] Automatically autoload bashcompinit for ZSH, when needed Marius Storm-Olsen
2011-04-26 20:47 ` Matthieu Moy
@ 2011-04-27 1:11 ` Felipe Contreras
2011-04-27 1:22 ` Felipe Contreras
1 sibling, 1 reply; 11+ messages in thread
From: Felipe Contreras @ 2011-04-27 1:11 UTC (permalink / raw)
To: Marius Storm-Olsen
Cc: Shawn O. Pearce, Junio C Hamano, git, Marius Storm-Olsen
On Tue, Apr 26, 2011 at 11:28 PM, Marius Storm-Olsen
<marius@storm-olsen.com> wrote:
> If bashcompinit has not already been autoloaded, do so
> automatically, as it is required to properly parse the
> git-completion file with ZSH.
>
> Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
> ---
> +if [[ -n ${ZSH_VERSION-} ]]; then
> + if ! bashcompinit >/dev/null 2>&1; then
> + autoload -U bashcompinit
> + bashcompinit
> + fi
How about this instead?
autoload -UX bashcompinit && bashcompinit
--
Felipe Contreras
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Automatically autoload bashcompinit for ZSH, when needed
2011-04-27 1:11 ` Felipe Contreras
@ 2011-04-27 1:22 ` Felipe Contreras
2011-04-27 3:23 ` [PATCH v2] " Marius Storm-Olsen
0 siblings, 1 reply; 11+ messages in thread
From: Felipe Contreras @ 2011-04-27 1:22 UTC (permalink / raw)
To: Marius Storm-Olsen
Cc: Shawn O. Pearce, Junio C Hamano, git, Marius Storm-Olsen
On Wed, Apr 27, 2011 at 4:11 AM, Felipe Contreras
<felipe.contreras@gmail.com> wrote:
> On Tue, Apr 26, 2011 at 11:28 PM, Marius Storm-Olsen
> <marius@storm-olsen.com> wrote:
>> If bashcompinit has not already been autoloaded, do so
>> automatically, as it is required to properly parse the
>> git-completion file with ZSH.
>>
>> Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
>> ---
>
>> +if [[ -n ${ZSH_VERSION-} ]]; then
>> + if ! bashcompinit >/dev/null 2>&1; then
>> + autoload -U bashcompinit
>> + bashcompinit
>> + fi
>
> How about this instead?
> autoload -UX bashcompinit && bashcompinit
Er, autoload -U +X.
--
Felipe Contreras
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2] Automatically autoload bashcompinit for ZSH, when needed
2011-04-27 1:22 ` Felipe Contreras
@ 2011-04-27 3:23 ` Marius Storm-Olsen
0 siblings, 0 replies; 11+ messages in thread
From: Marius Storm-Olsen @ 2011-04-27 3:23 UTC (permalink / raw)
To: Shawn O. Pearce, Junio C Hamano, Felipe Contreras; +Cc: git, Marius Storm-Olsen
If bashcompinit has not already been autoloaded, do so
automatically, as it is required to properly parse the
git-completion file with ZSH.
Signed-off-by: Marius Storm-Olsen <mstormo@gmail.com>
---
Changes since v2:
-----------------
'Added' -> 'Add'
Simplified test for bashcompinit, as per advice from Felipe Contreras
contrib/completion/git-completion.bash | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 840ae38..9150ea6 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1,6 +1,6 @@
#!bash
#
-# bash completion support for core Git.
+# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
@@ -18,16 +18,12 @@
# To use these routines:
#
# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
-# 2) Added the following line to your .bashrc:
-# source ~/.git-completion.sh
-#
-# Or, add the following lines to your .zshrc:
-# autoload bashcompinit
-# bashcompinit
+# 2) Add the following line to your .bashrc/.zshrc:
# source ~/.git-completion.sh
#
# 3) Consider changing your PS1 to also show the current branch:
-# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
+# Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
+# ZSH: PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
#
# The argument to __git_ps1 will be displayed only if you
# are currently in a git repository. The %s token will be
@@ -77,6 +73,10 @@
# git@vger.kernel.org
#
+if [[ -n ${ZSH_VERSION-} ]]; then
+ autoload -U +X bashcompinit && bashcompinit
+fi
+
case "$COMP_WORDBREAKS" in
*:*) : great ;;
*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
--
1.7.5.rc2.4.g4d8b3
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2011-04-27 3:23 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-26 13:24 [PATCH] Refactor git-completion to allow ZSH usage of PS1 functions Marius Storm-Olsen
2011-04-26 17:21 ` Junio C Hamano
2011-04-26 17:37 ` Marius Storm-Olsen
2011-04-26 19:15 ` Junio C Hamano
2011-04-26 20:28 ` [PATCH] Automatically autoload bashcompinit for ZSH, when needed Marius Storm-Olsen
2011-04-26 20:47 ` Matthieu Moy
2011-04-26 20:52 ` Marius Storm-Olsen
2011-04-26 21:55 ` Junio C Hamano
2011-04-27 1:11 ` Felipe Contreras
2011-04-27 1:22 ` Felipe Contreras
2011-04-27 3:23 ` [PATCH v2] " Marius Storm-Olsen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).