Adding git branch to bash prompt on snow leopard

8

5

I am using this:

$(__git_ps1 '(%s)')

It works however it does not update when I change directories or checkout a new branch. I also have this alias:

alias reload='. ~/.bash_profile'

Sample run:

user@machine:~/dev/rails$cd git_folder/
user@machine:~/dev/rails/git_folder$reload
user@machine:~/dev/rails/git_folder(test)$git checkout master
Switched to branch 'master'
user@machine:~/dev/rails/git_folder(test)$reload
user@machine:~/dev/rails/git_folder(master)$

As you can see it is being set correctly but only if I reload bash_profile. I have wasted way to much time on this. I am using bash on snow leopard. Please help!

Edit: You can see my dotfiles on github and the file setting the PS1 here

crayment

Posted 2010-03-19T08:21:10.517

Reputation: 171

Answers

9

Okay problem solved.

I was doing:

export PS1="$(__git_ps1 '(%s)')"

and I needed to do:

export PS1="\$(__git_ps1 '(%s)')"

You need to escapee the dollar sign otherwise it is just run once and substituted in.

crayment

Posted 2010-03-19T08:21:10.517

Reputation: 171

0

You probably need to use $PROMPT_COMMAND

Paused until further notice.

Posted 2010-03-19T08:21:10.517

Reputation: 86 075

Thanks. I tried playing with PROMPT_COMMAND but not working with my current setup. You can see the file that makes the setting here: http://github.com/crayment/dotfiles/blob/master/bash/config

– crayment – 2010-03-19T11:06:25.393

0

Note that the latest git moves __git_ps1 out of bash_completion so you need to source it separately. See https://superuser.com/a/477749/66255.

studgeek

Posted 2010-03-19T08:21:10.517

Reputation: 1 805