I've been trying to let my prompt (PS1) show what git branch I'm in, and if that branch is dirty or not (i.e. coloured in red or green). Have been able to do this using a ruby function that is read by PS1, but this is very slow because the ruby interpreter has to be run every time my terminal wants to show a prompt.
A screenshot of what I want (and achieved using the ruby version) is at http://twitpic.com/1gubtf
. The accompanying code is at http://github.com/jandot/git-prompt
I've been trying to recode this into bash, but can't get it to work.
Here's my non-working code:
* .bash_profile contains:
source ./git-ps.sh 2>/dev/null
export PS1="[\w \$(parse_git_branch)]> "
* git-ps.sh is:
CURRENT_BRANCH=`git branch 2>/dev/null | grep '*' | head -n1`
if [ $CURRENT_BRANCH != "" ] ; then
if [[ "$STATUS_LINES" =~ "# Changed but not updated" ]] ; then
elif [[ "$STATUS_LINES" =~ "# Changes to be committed" ]] ; then
elif [[ "$STATUS_LINES" =~ "# Untracked files" ]] ; then
Using this code, my prompt looks like this:
Clearly there is an issue with escaping the colour codes somewhere, but I haven't been able to find what it is...
Any help would be greatly appreciated.