# [PATCH] completion: zsh: improve bash script loading

6 messages from 2013-05-29 to 2013-05-29. Participants: Felipe Contreras, Johannes Sixt, Junio C Hamano.
Thread: https://gitlist.dev/t/33965

## Felipe Contreras, 2013-05-29 03:24

Subject: [PATCH] completion: zsh: improve bash script loading
Message-ID: <1369797840-3103-1-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1369797840-3103-1-git-send-email-felipe.contreras%40gmail.com

```
It's better to check in multiple locations, so the user doesn't have to.

And update the documentation.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 2565d2e..9555cf8 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -4,18 +4,17 @@
 #
 # Copyright (c) 2012-2013 Felipe Contreras <felipe.contreras@gmail.com>
 #
-# You need git's bash completion script installed somewhere, by default on the
-# same directory as this script.
+# You need git's bash completion script installed somewhere, by default it
+# would be the location bash-completion uses.
 #
-# If your script is on ~/.git-completion.sh instead, you can configure it on
-# your ~/.zshrc:
+# If your script is somewhere else, you can configure it on your ~/.zshrc:
 #
 #  zstyle ':completion:*:*:git:*' script ~/.git-completion.sh
 #
-# The recommended way to install this script is to copy to
-# '~/.zsh/completion/_git', and then add the following to your ~/.zshrc file:
+# The recommended way to install this script is to copy to '~/.zsh/_git', and
+# then add the following to your ~/.zshrc file:
 #
-#  fpath=(~/.zsh/completion $fpath)
+#  fpath=(~/.zsh $fpath)
 
 complete ()
 {
@@ -27,7 +26,18 @@ zstyle -T ':completion:*:*:git:*' tag-order && \
 	zstyle ':completion:*:*:git:*' tag-order 'common-commands'
 
 zstyle -s ":completion:*:*:git:*" script script
-test -z "$script" && script="$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
+if [ -z "$script" ]; then
+	local -a locations
+	locations=(
+		'/etc/bash_completion.d/git' # fedora, old debian
+		'/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
+		'/usr/share/bash-completion/git' # gentoo
+		$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
+		)
+	for e in $locations; do
+		test -f $e && script="$e" && break
+	done
+fi
 ZSH_VERSION='' . "$script"
 
 __gitcomp ()
-- 
1.8.3.rc3.312.g47657de

```

## Johannes Sixt, 2013-05-29 06:17

Subject: Re: [PATCH] completion: zsh: improve bash script loading
Message-ID: <51A59D8E.1040502@viscovery.net>
URL: https://gitlist.dev/e/51A59D8E.1040502%40viscovery.net
In-Reply-To: <1369797840-3103-1-git-send-email-felipe.contreras@gmail.com>

```
Am 5/29/2013 5:24, schrieb Felipe Contreras:
> +if [ -z "$script" ]; then
> +	local -a locations
> +	locations=(
> +		'/etc/bash_completion.d/git' # fedora, old debian
> +		'/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
> +		'/usr/share/bash-completion/git' # gentoo
> +		$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
> +		)

Won't you need

	local e

here, or does it not matter?

> +	for e in $locations; do
> +		test -f $e && script="$e" && break
> +	done
> +fi

-- Hannes

```

## Felipe Contreras, 2013-05-29 06:30

Subject: Re: [PATCH] completion: zsh: improve bash script loading
Message-ID: <CAMP44s1UwYxS_sZSKTyEj5rhmrJ4gFkPc9z+eCL6WAaHXkY8eQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s1UwYxS_sZSKTyEj5rhmrJ4gFkPc9z%2BeCL6WAaHXkY8eQ%40mail.gmail.com
In-Reply-To: <51A59D8E.1040502@viscovery.net>

```
On Wed, May 29, 2013 at 1:17 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
> Am 5/29/2013 5:24, schrieb Felipe Contreras:
>> +if [ -z "$script" ]; then
>> +     local -a locations
>> +     locations=(
>> +             '/etc/bash_completion.d/git' # fedora, old debian
>> +             '/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
>> +             '/usr/share/bash-completion/git' # gentoo
>> +             $(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
>> +             )
>
> Won't you need
>
>         local e
>
> here, or does it not matter?

You are right, otherwise it would be in the user's shell.

-- 
Felipe Contreras

```

## Junio C Hamano, 2013-05-29 17:49

Subject: Re: [PATCH] completion: zsh: improve bash script loading
Message-ID: <7vr4gpu15c.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vr4gpu15c.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CAMP44s1UwYxS_sZSKTyEj5rhmrJ4gFkPc9z+eCL6WAaHXkY8eQ@mail.gmail.com>

```
Felipe Contreras <felipe.contreras@gmail.com> writes:

> On Wed, May 29, 2013 at 1:17 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
>> Am 5/29/2013 5:24, schrieb Felipe Contreras:
>>> +if [ -z "$script" ]; then
>>> +     local -a locations
>>> +     locations=(
>>> +             '/etc/bash_completion.d/git' # fedora, old debian
>>> +             '/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
>>> +             '/usr/share/bash-completion/git' # gentoo
>>> +             $(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
>>> +             )
>>
>> Won't you need
>>
>>         local e
>>
>> here, or does it not matter?
>
> You are right, otherwise it would be in the user's shell.

Has this changed since 0a04e187e669 (completion: zsh: improve bash
script loading, 2013-05-24) which I have on 'pu'?

If not, I can do this locally to save a roundtrip, if you want.

 contrib/completion/git-completion.zsh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 9555cf8..fac5e71 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -28,6 +28,7 @@ zstyle -T ':completion:*:*:git:*' tag-order && \
 zstyle -s ":completion:*:*:git:*" script script
 if [ -z "$script" ]; then
 	local -a locations
+	local e
 	locations=(
 		'/etc/bash_completion.d/git' # fedora, old debian
 		'/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian

```

## Felipe Contreras, 2013-05-29 19:30

Subject: Re: [PATCH] completion: zsh: improve bash script loading
Message-ID: <CAMP44s0VjXwOXhUvniui+yVJiH4Dwxtx=0431G2KrEdHtrGTDw@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s0VjXwOXhUvniui%2ByVJiH4Dwxtx%3D0431G2KrEdHtrGTDw%40mail.gmail.com
In-Reply-To: <7vr4gpu15c.fsf@alter.siamese.dyndns.org>

```
On Wed, May 29, 2013 at 12:49 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Felipe Contreras <felipe.contreras@gmail.com> writes:
>
>> On Wed, May 29, 2013 at 1:17 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
>>> Am 5/29/2013 5:24, schrieb Felipe Contreras:
>>>> +if [ -z "$script" ]; then
>>>> +     local -a locations
>>>> +     locations=(
>>>> +             '/etc/bash_completion.d/git' # fedora, old debian
>>>> +             '/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
>>>> +             '/usr/share/bash-completion/git' # gentoo
>>>> +             $(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
>>>> +             )
>>>
>>> Won't you need
>>>
>>>         local e
>>>
>>> here, or does it not matter?
>>
>> You are right, otherwise it would be in the user's shell.
>
> Has this changed since 0a04e187e669 (completion: zsh: improve bash
> script loading, 2013-05-24) which I have on 'pu'?

Other than this change, nope.

> If not, I can do this locally to save a roundtrip, if you want.

Great, let's do that.

-- 
Felipe Contreras

```

## Junio C Hamano, 2013-05-29 19:58

Subject: Re: [PATCH] completion: zsh: improve bash script loading
Message-ID: <7vbo7tsgml.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vbo7tsgml.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CAMP44s0VjXwOXhUvniui+yVJiH4Dwxtx=0431G2KrEdHtrGTDw@mail.gmail.com>

```
Felipe Contreras <felipe.contreras@gmail.com> writes:

>> Has this changed since 0a04e187e669 (completion: zsh: improve bash
>> script loading, 2013-05-24) which I have on 'pu'?
>
> Other than this change, nope.
>
>> If not, I can do this locally to save a roundtrip, if you want.
>
> Great, let's do that.

Done.  The diff from 0a04e187e669 looks like this:

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 9555cf8..fac5e71 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -28,6 +28,7 @@ zstyle -T ':completion:*:*:git:*' tag-order && \
 zstyle -s ":completion:*:*:git:*" script script
 if [ -z "$script" ]; then
 	local -a locations
+	local e
 	locations=(
 		'/etc/bash_completion.d/git' # fedora, old debian
 		'/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian

```
