Currently, this works, if I start bash from a folder already containing a git project.
PS1="${debian_chroot:+($debian_chroot)}\[$BPurple\]\u\[$BGreen\]@\[$BCyan\]\h\[$BGreen\]: \[$BBlue\]\w\[$Yellow\]`__git_ps1`\[$Green\] \$ \[$White\]"
My problem is that, if I cd into a git folder, nothing happens. And then if I start in a git repo, (where (master) does show up, if I cd to anywhere else, the (master) still shows up in my prompt.
So, the PS1 variable isn’t updating. how do I fix that?
Try this:
I simply replaced the double quotes with single quotes, and wrapped the call to
__git_ps1in a command substitution. If that doesn’t work (I haven’t included parameter expansion in my prompt for a while), trywhere the first ‘…’ is everything prior to ‘__git_ps1’, and the second ‘…’ is everything after. Basically, three strings concatenated together, with the first and third in double quotes and the second in single quotes.