I have the following in my .bashrc file:
# Git Bash Completion
source "$HOME/.git_completion"
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWSTASHSTATE=1
# Prompt
export PS1="\e[0;35m\u@\h\e[m \e[0;34m\w$(__git_ps1):\e[m\r\n"
This should be displaying the git branch at the end of my prompt… but it’s not. If I manually source my .bash_profile, it works (my .bash_profile loads .bashrc). If I quit terminal and startup again, the git branch disappears :(.
What is causing this, and how to I fix it?
I don’t use git, but I bet the
$(__git_ps1)portion of the prompt is being evaluated when PS1 is first set (and doesn’t return anything). You need to use single quotes, i.e.PS1='\e....\r\n', then the cmd-substitution will be executed each time the prompt is displayed.Double quotes allow env-vars and other shell features beginning with ‘$’ to be expanded. Single-quotes prevent expansions. That is the purpose of having the two types of quoting.
See tldp.org/LDP/abs/html/quoting.html
(I’ve deleted my comments)
I hope this helps.