timshadel
1/28/2009 - 10:40 PM

Bold your current git branch on the command line (tested on Mac OS X)

Bold your current git branch on the command line (tested on Mac OS X)

TERM=xterm-color
# \[     starts a sequence of non-printable chars
# \]     ends that sequence
# \e[1m  turns text that follows Bold
# \e[m   turns text that follows Normal
#
# \[\e[1m\]  tells the shell not to count the non-printable bold command in it's wrapping calculations
# \[\e[m\]  tells the shell not to count the non-printable normal command in it's wrapping calculations
#
# Unlike HTML <b></b> elements; this is more like <b>...<normal>  It's important that the shell counts
# the characters between <b> and <normal> as printable in its line wrap calculations.
 
parse_git_branch() {
git symbolic-ref HEAD 2> /dev/null | cut -d/ -f3- | sed -e 's/\(.*\)/ (\1)/'
}
PS1="\h:\W\[\e[1m\]\$(parse_git_branch)\[\e[m\] $ "