Skip to content

Instantly share code, notes, and snippets.

@timshadel
Forked from tekkub/.bashrc
Created January 28, 2009 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timshadel/54231 to your computer and use it in GitHub Desktop.
Save timshadel/54231 to your computer and use it in GitHub Desktop.
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\] $ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment