via Bedazzle Your Bash Prompt with Git Info // RailsTips by John Nunemaker.
I came across the above rails tip by John Nunemaker today. It shows how you can show which git branch you’re on while in your bash terminal.
The code he provided didn’t exactly work for me (I’m on OSX) so I ended up changing things a little bit:
function parse_git_branch {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
GREEN="\[33[0;32m\]"
YELLOW="\[33[0;33m\]"
WHITE="\[33[0;0m\]"
PS1="$GREEN\$(date +%H:%M) \w$YELLOW \$(parse_git_branch)$WHITE\$ "This produces a bash that looks like the screenshot below. As you’ve probably guessed, jetpack is the git repo/directory and authorization is the branch I’m currently on.


{ 6 comments… read them below or add one }
Hmm that’s interesting. I wonder why that is. When I put in what you have, the colors don’t work for me but with the original code, it works. In anycase, glad you got it working.
Will others pls comment on which of the two (if any) works for you? Also add your OSX version. I am on Leopard.
The colors aren't working for me. I had to do this to make it work:
GREEN=”[ 33[0;32m]“
YELLOW=”[ 33[0;33m]“
WHITE=”[ 33[0;0m]“
Hmm that’s interesting. I wonder why that is. When I put in what you have, the colors don’t work for me but with the original code, it works. In anycase, glad you got it working.
Will others pls comment on which of the two (if any) works for you? Also add your OSX version. I am on Leopard.
Here's an alternative one:
http://pastie.org/485245
Which outputs:
http://www.grabup.com/uploads/06fbca0fb8cbb751c...
(the asterisk shows if the branch has un-commited changes)
both codes are wrong. linux
Lucho – I say it works on OSX, not linux so that might be the difference. If you do figure out what works on linux, I’d be happy to add that to the post.