PS1="\\w (`git branch | grep '^*' | cut -b 3-100`)$ "
I set my PS1 as above, but it will not update the branch name in the prompt after I change the branch with git checkout
, or change the repository with the cd
. How to fix this?
The backtick-quoted bit is evaluated when PS1
is set (once), not when the prompt is displayed. Use single quotes to save the expansion for the latter event:
PS1='\w (`git branch | grep "^*" | cut -b 3-100`)$ '