# Re: git-PS1 bash prompt setting

4 messages from 2006-11-17 to 2006-11-19. Participants: Nicolas Vilz, Junio C Hamano, Sean.
Thread: https://gitlist.dev/t/43509

## Nicolas Vilz, 2006-11-17 08:38

Subject: Re: git-PS1 bash prompt setting
Message-ID: <20061117083801.GB11468@fry.bender.fht>
URL: https://gitlist.dev/e/20061117083801.GB11468%40fry.bender.fht
In-Reply-To: <20061116130111.921396df.seanlkml@sympatico.ca>

```
On Thu, Nov 16, 2006 at 01:01:11PM -0500, Sean wrote:

> [branch!repo/relative/path]$ 
> 
> Where "repo" is the basename of the path to the root of your repo.
> An example would look like this:
> 
> [master!linus-2.6/Documentation/vm]$ 
> 
> Cheers,
> Sean
> 
> 
> #!/bin/bash
> BR=$(git symbolic-ref HEAD 2>/dev/null) || { echo "$@" ; exit ; }
> BR=${BR#refs/heads/}
> REL=$(git rev-parse --show-prefix) 
> REL="${REL//%\/}"
> LOC="${PWD%/$REL}"
> echo "[$BR!${LOC/*\/}${REL:+/$REL}]$ "

Just a note:

this doesn't work with bash 3.2. I think they altered the way of
trimming variables in this version.

on systems with bash 3.2 installed, i get
[master!linus-2.6/vm/vm]$ 
with the example above.

on systems with bash 3.1, it works properly.

unfortunatelly, i am not so good in bash scripting, so it will take some
time for me to fix it.

Sincerly

```

## Sean, 2006-11-17 09:20

Subject: Re: git-PS1 bash prompt setting
Message-ID: <BAYC1-PASMTP0635A081EAC964E03599B4AEE80@CEZ.ICE>
URL: https://gitlist.dev/e/BAYC1-PASMTP0635A081EAC964E03599B4AEE80%40CEZ.ICE
In-Reply-To: <20061117083801.GB11468@fry.bender.fht>

```
On Fri, 17 Nov 2006 09:38:02 +0100
Nicolas Vilz <niv@iaglans.de> wrote:

> Just a note:
> 
> this doesn't work with bash 3.2. I think they altered the way of
> trimming variables in this version.
> 
> on systems with bash 3.2 installed, i get
> [master!linus-2.6/vm/vm]$ 
> with the example above.
> 
> on systems with bash 3.1, it works properly.

Sorry bout that, I knew it was a bit fragile.  Was rather
comical reading Junio's recent message about all the things not
to do if you want portable shell code and noticing my 6 line script
did 90% of them ;o)  Strange though, I downloaded Bash 3.2
and gave it a try and didn't see the problem here..

Wanna try this small change, to see if it helps? :

#!/bin/bash
BR=$(git symbolic-ref HEAD 2>/dev/null) || { echo "$@" ; exit ; }
BR=${BR#refs/heads/}
REL=$(git rev-parse --show-prefix)
REL="${REL%\/}"
LOC="${PWD%/$REL}"
echo "[$BR!${LOC/*\/}${REL:+/$REL}]$ "

```

## Nicolas Vilz, 2006-11-17 09:52

Subject: Re: git-PS1 bash prompt setting
Message-ID: <20061117095237.GD11468@fry.bender.fht>
URL: https://gitlist.dev/e/20061117095237.GD11468%40fry.bender.fht
In-Reply-To: <20061117042051.d2fbddb6.seanlkml@sympatico.ca>

```
On Fri, Nov 17, 2006 at 04:20:51AM -0500, Sean wrote:
> On Fri, 17 Nov 2006 09:38:02 +0100
> Nicolas Vilz <niv@iaglans.de> wrote:
> 
> > Just a note:
> > 
> > this doesn't work with bash 3.2. I think they altered the way of
> > trimming variables in this version.
> > 
> > on systems with bash 3.2 installed, i get
> > [master!linus-2.6/vm/vm]$ 
> > with the example above.
> > 
> > on systems with bash 3.1, it works properly.
> 
> Sorry bout that, I knew it was a bit fragile.  Was rather
> comical reading Junio's recent message about all the things not
> to do if you want portable shell code and noticing my 6 line script
> did 90% of them ;o)  Strange though, I downloaded Bash 3.2
> and gave it a try and didn't see the problem here..
> 
> Wanna try this small change, to see if it helps? :
> 
> #!/bin/bash
> BR=$(git symbolic-ref HEAD 2>/dev/null) || { echo "$@" ; exit ; }
> BR=${BR#refs/heads/}
> REL=$(git rev-parse --show-prefix)
> REL="${REL%\/}"
> LOC="${PWD%/$REL}"
> echo "[$BR!${LOC/*\/}${REL:+/$REL}]$ "
> 

That one did the job... funny, removing these two // did the job, for
both versions, 
GNU bash, version 3.1.17(1)-release (powerpc-unknown-linux-gnu) and
GNU bash, version 3.2.5(1)-release (x86_64-pc-linux-gnu).

Thx for fixing that script. It really helps me.

Sincerly
Nicolas

```

## Junio C Hamano, 2006-11-19 06:28

Subject: Re: git-PS1 bash prompt setting
Message-ID: <7vhcww7xxd.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vhcww7xxd.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <BAYC1-PASMTP0635A081EAC964E03599B4AEE80@CEZ.ICE>

```
Sean <seanlkml@sympatico.ca> writes:

> On Fri, 17 Nov 2006 09:38:02 +0100
> Nicolas Vilz <niv@iaglans.de> wrote:
>
>> Just a note:
>> 
>> this doesn't work with bash 3.2. I think they altered the way of
>> trimming variables in this version.
>> 
>> on systems with bash 3.2 installed, i get
>> [master!linus-2.6/vm/vm]$ 
>> with the example above.
>> 
>> on systems with bash 3.1, it works properly.
>
> Sorry bout that, I knew it was a bit fragile.  Was rather
> comical reading Junio's recent message about all the things not
> to do if you want portable shell code and noticing my 6 line script
> did 90% of them ;o)

Maybe I should have been more explicit when I said "${paremeter##word}
and friends".  Might not have been obvious, but I only meant the
following four: %, %%, # and ##.

${parameter/pattern/string} and ${parameter//pattern/string} are
not even in POSIX.


```
