# current HEAD in bash prompt

2 messages from 2005-11-17 to 2005-11-18. Participants: Ben Clifford, Alex Riesen.
Thread: https://gitlist.dev/t/2585

## Ben Clifford, 2005-11-17 08:39

Subject: current HEAD in bash prompt
Message-ID: <9C44605A-4F0F-42FA-A8ED-A4F7EFA24C32@hawaga.org.uk>
URL: https://gitlist.dev/e/9C44605A-4F0F-42FA-A8ED-A4F7EFA24C32%40hawaga.org.uk

```
After getting a bit confused when having too many branches, and for  
people who don't mind extra forks and like too much info in their  
prompt, I've recently started using this:

export PS1='!\! [\j] \u@\h:\w$(output-git-head-or-blank)\$ '

where output-git-head-or-blank is:

#!/bin/bash

PS_GIT=$(git-symbolic-ref HEAD 2>/dev/null) && echo "[$(basename  
$PS_GIT)]" && exit

# else output nothing


When in a non-git directory, you get a non-git prompt (of course,  
modify this to whatever you want)

!502 [0] benc@piva:~$

and when in a git directory you get (a truncated form of) whatever  
today's head points at:


!502 [0] benc@piva:~$ cd src/globe
!503 [0] benc@piva:~/src/globe[master]$


-- 
Ben • ベン • Бэн • 벤 • 班明
http://www.hawaga.org.uk/ben/
My email is high latency but best way to contact me. Alternatively,  
SMS number(s) at above URL.

```

## Alex Riesen, 2005-11-18 14:57

Subject: Re: current HEAD in bash prompt
Message-ID: <81b0412b0511180657h6c5a66f8y4a41f3fa20a8b238@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0511180657h6c5a66f8y4a41f3fa20a8b238%40mail.gmail.com
In-Reply-To: <9C44605A-4F0F-42FA-A8ED-A4F7EFA24C32@hawaga.org.uk>

```
On 11/17/05, Ben Clifford <benc@hawaga.org.uk> wrote:
> After getting a bit confused when having too many branches, and for
> people who don't mind extra forks and like too much info in their
> prompt, I've recently started using this:
>
> export PS1='!\! [\j] \u@\h:\w$(output-git-head-or-blank)\$ '
>

I did almost the same, but in .c (attached).

```
