Showing git branch in shell prompt? Showing git branch in shell prompt? bash bash

Showing git branch in shell prompt?


Simpler solution: quote the GIT_STATUS so it doesn't get evaluated on bash startup, but instead gets evaluated when bash is displaying the prompt:

COLOR1='\[\e[1;32m\]'COLOR2='\[\e[1;1m\]'COLOR3='\[\e[m\]'GIT_STATUS='$(__git_ps1 " %s")'PROMPT_CHAR='\$'PS1="${COLOR1}\u@\h${COLOR3} \w${COLOR2}${GIT_STATUS} ${COLOR2}${PROMPT_CHAR}"

Also note that exporting PS1 is not a good idea.


You want PS1 to be updated to contain the current branch every time the prompt is displayed, that is, before you type the next command. Ask bash to do this by setting PS1 again in the precmd function. bash runs this function before showing you the prompt:

precmd() {    PS1=...}