# [PATCH] Abort early if not being sourced under bash.

3 messages from 2008-02-08 to 2008-02-08. Participants: Ville Skyttä, Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/11974

## Ville Skyttä, 2008-02-08 21:10

Subject: [PATCH] Abort early if not being sourced under bash.
Message-ID: <200802082310.34398.ville.skytta@iki.fi>
URL: https://gitlist.dev/e/200802082310.34398.ville.skytta%40iki.fi

```
Subject: [PATCH] Abort early if not being sourced under bash.

This way, the file can be safely sourced from profile files shared with
non-bash shells, eg. dropped into /etc/profile.d like directories.

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
---
 contrib/completion/git-completion.bash |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 4ea727b..3cde9f4 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -45,6 +45,8 @@
 #       git@vger.kernel.org
 #
 
+[ -z "$BASH_VERSION" ] && return
+
 __gitdir ()
 {
 	if [ -z "$1" ]; then
-- 
1.5.3.8

```

## Johannes Schindelin, 2008-02-08 21:14

Subject: Re: [PATCH] Abort early if not being sourced under bash.
Message-ID: <alpine.LSU.1.00.0802082113410.11591@racer.site>
URL: https://gitlist.dev/e/alpine.LSU.1.00.0802082113410.11591%40racer.site
In-Reply-To: <200802082310.34398.ville.skytta@iki.fi>

```
Hi,

On Fri, 8 Feb 2008, Ville Skyttä wrote:

> Subject: [PATCH] Abort early if not being sourced under bash.

Please do not repeat the subject.  And prepend "git-completion: " so 
people can see from the subject already what this patch is about.

As for the patch, yeah, I think it should go in.

Ciao,
Dscho
```

## Junio C Hamano, 2008-02-08 21:31

Subject: Re: [PATCH] Abort early if not being sourced under bash.
Message-ID: <7vprv7i19f.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vprv7i19f.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <200802082310.34398.ville.skytta@iki.fi>

```
Ville Skyttä <ville.skytta@iki.fi> writes:

> Subject: [PATCH] Abort early if not being sourced under bash.
>
> This way, the file can be safely sourced from profile files shared with
> non-bash shells, eg. dropped into /etc/profile.d like directories.
>
> Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
> ---
>  contrib/completion/git-completion.bash |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 4ea727b..3cde9f4 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -45,6 +45,8 @@
>  #       git@vger.kernel.org
>  #
>  
> +[ -z "$BASH_VERSION" ] && return
> +
>  __gitdir ()
>  {
>  	if [ -z "$1" ]; then

I do not particularly sympathize with the /etc/profile.d/
argument.  Ditros can and should put a small script in there
that checks what /bin/sh it really is running and source the
real thing from elsewhere, perhaps /usr/share/git-core/,
appropriately.

However, even if you did so, there is another issue.  One of my
hosts have a bash that does not know the "complete" command, and
logging into the host I get twenty-or-so "bash: complete:
command not found".

So

	if bash "complete" would not work for this shell
        then
        	__git_ps1 () { : dummy; }
		return
	fi

at the beginning may be needed even if you know we are running
bash.

Then people can safely say:

	PS1=': \h \W$(__git_ps1 "/%s"); '

(or whatever git-completion.bash suggests these days) in their
start-up script.

```
