10
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?

exebook
  • 32,014
  • 33
  • 141
  • 226

1 Answers1

18

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`)$ '
Ry-
  • 218,210
  • 55
  • 464
  • 476