Super awesome custom command prompt os x and git branches

If you want to customize your command prompt in terminal on OS X it’s super easy. A couple of things that I want to know at all times is where in the directory structure am I and also if I am working with in a project that is under git version control I want to know what branch I am working in. 

A lot of that is easy to find out by either issuing an “$ ls” command or “$ git branch”, but I would rather save my self the key strokes and see where I am at in the command prompt. 

Open terminal and navigate to your home directory. If you are just opening terminal then it should open in your home directory but just to make sure you can type

[code]

cd ~/

[/code]

After you are in your home directory you need to open your bash_profile witch is a hidden file on your system. If you do not have a .bash_profile you need to create one. I have textmate installed and usually open mine by typing

[code]
mate  ./.bash_profile
[/code] 

Once you open your .bash_profile you need the following lines in the file. I would suggest you put them below everything else if you already have statements in your file.

[code]

function parse_git_branch {
 ref=$( git branch 2> /dev/null | sed -e ’/^[^*]/d’ -e ’s/* (.*)/(1)/’) || return
 echo ${ref#refs/heads/}
}

RED=“[33[0;31m]”
YELLOW=“[33[0;33m]”
GREEN=“[33[0;32m]”

export PS1=“[ W ]$YELLOW$(parse_git_branch)$GREEN$ ”

[/code]

After you save and close the file go back to your terminal window and type the following

[code]

source ~/.bash_profile

[/code]

If all goes well you should have a better looking command prompt.