# Re: StGit-enabled bash-prompt

3 messages from 2006-10-26 to 2006-10-27. Participants: Ben Clifford, Robin Rosenberg.
Thread: https://gitlist.dev/t/43291

## Robin Rosenberg, 2006-10-26 21:17

Subject: StGit-enabled bash-prompt
Message-ID: <200610262317.30209.robin.rosenberg.lists@dewire.com>
URL: https://gitlist.dev/e/200610262317.30209.robin.rosenberg.lists%40dewire.com

```
Hi,

I added the following snippet to my .bashrc to help me keep track of what 
patch I'm working on.  I got annoyed at typing stg top/stg series all the 
time.

This changes the bash prompt to include the current git branch and the top 
stgit patch to the prompt.

Of course you will read and understand this code. I don't know how good an 
idea it is to use the DEBUG trap this way.

NO WARRANTY (as always)

-- robin

if [ "$PS1" ]; then
    function stgtag
    {
        br=$(stg branch 2>/dev/null)
        top=$(stg top 2>/dev/null)
        if [[ -n "$br$top" ]];then
            echo " [$top@$br] "
        fi
    }
    trap 'PS1="\u@\h$(stgtag)\w]\$ "' DEBUG


```

## Ben Clifford, 2006-10-27 10:01

Subject: Re: StGit-enabled bash-prompt
Message-ID: <Pine.LNX.4.64.0610270957020.9123@dildano.hawaga.org.uk>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0610270957020.9123%40dildano.hawaga.org.uk
In-Reply-To: <200610262317.30209.robin.rosenberg.lists@dewire.com>

```

On Thu, 26 Oct 2006, Robin Rosenberg wrote:

> Of course you will read and understand this code. I don't know how good an 
> idea it is to use the DEBUG trap this way.

I set my prompt without using it, with something approximating this
being defined in my .bash_profile. I think the use of ' instead of " 
causes evaluation of __prompt_githead be delayed until the prompt is 
displayed.


  PS1='$(__prompt_githead) '$PS1

  __prompt_githead() {
  PS_GIT=$(git-symbolic-ref HEAD 2>/dev/null) || exit
  echo -n " $(basename $PS_GIT)" 
  }

-- 

```

## Robin Rosenberg, 2006-10-27 18:54

Subject: Re: StGit-enabled bash-prompt
Message-ID: <200610272054.04948.robin.rosenberg.lists@dewire.com>
URL: https://gitlist.dev/e/200610272054.04948.robin.rosenberg.lists%40dewire.com
In-Reply-To: <Pine.LNX.4.64.0610270957020.9123@dildano.hawaga.org.uk>

```
fredag 27 oktober 2006 12:01 skrev Ben Clifford:
> On Thu, 26 Oct 2006, Robin Rosenberg wrote:
> > Of course you will read and understand this code. I don't know how good
> > an idea it is to use the DEBUG trap this way.
>
> I set my prompt without using it, with something approximating this
> being defined in my .bash_profile. I think the use of ' instead of "
> causes evaluation of __prompt_githead be delayed until the prompt is
> displayed.

Ahh, ofcourse. Thanks.


```
