Friday, December 07, 2012

Color & Git Branch in your BASH Prompt

This one will be easy.  Place this into your .bash_profile:



This defines a function called "parse_git_branch", which reads the symbolic reference for the HEAD pointer (sending errors to /dev/null) and assigning the value to the "ref" variable.  Then, it echos the value of the variable, but filters out "refs/heads/" from the answer (See example 10.10 here at tldp.org)

After setting the value for some colors, it sets the first level prompt to print the current working directory in green and the git branch in yellow.

Voila

No comments:

Post a Comment