A little Saturday morning tweaking.
Based on this post at railstips.org, I decided to adjust my Bash prompt by appending the following to my ~/.bashrc file:
#...
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "("${ref#refs/heads/}")"
}
BLACK="\[\033[0;30m\]"
BLUE="\[\033[0;34m\]"
VIOLET="\[\033[1;35m\]"
CYAN="\[\033[0;36m\]"
PS1="\n[$CYAN\u@\h:$BLUE\w$VIOLET \$(parse_git_branch)$BLACK]\n\$ "
The prompt will now show the name of the branch I am working in when the current directory is part of a Git repository. The original code used yellow, red, and green to highlight parts of the prompt. That messed with my mind when I ran RSpec and saw yellow and red when I was expecting all green. Rather than get used to it, I changed the colors. I also added some newlines to perhaps keep the command line neater when deep in a directory tree.
[Update 2010-07-23]
After running with the above settings for a while I decided I don’t care for the colors in the prompt. Don’t need the square brackets either. I do like seeing the current git branch. That simplifies things a bit.
#...
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "("${ref#refs/heads/}")"
}
PS1="\n\u@\h:\w \$(parse_git_branch)\n\$ "
[Update 2010-09-25]
Okay, maybe a little color…
#...
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "("${ref#refs/heads/}")"
}
VIOLET="\[\033[1;35m\]"
NO_COLOR="\[\033[0;0m\]"
PS1="\n$VIOLET\u@\h:\w \$(parse_git_branch)$NO_COLOR\n\$ "
See. I told you it was "tweaking."

