I want my prompt to display the current git-branch when inside of a repo directory. e.g.,

[desktop repo(master)]$

In my terminal I can type:

cat <<EOF >> ~/.bash_profile
PS1='\[\e[0;32m\][\h \W\[\e[m\]$(__git_ps1 "(%s)")\[\e[0;32m\]]\$ \[\e[m\]'

But the resultant appended text in .bash_profile is:

PS1='\[\e[0;32m\][\h \W\[\e[m\]\[\e[0;32m\]]$ \[\e[m\]'

the __git_ps1 method is not present in the result. If I manually edit the .bash_profile with vim then source ~./bash_profile, the PS1 statement contains the __git_ps1 method and it works fine.

This cat statement is part of a larger 'bootstrapping' script, but I've trimmed out all the irrelevant stuff. I have successfully implemented this on Ubuntu. I am trying to get it running on a CentOS VM.



Try cat << "EOF", this prevents expansion of the dollar function and the quotes.

  • yep. that was it. huzzah! – nograde May 23 '14 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.