Words To Start A Paragraph For An Essay Top Mba Essay Editor Service Us Romeo And Juliet Newspaper Essay Cause And Effect Essay Topics For High School Students

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


cd ~/


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

mate  ./.bash_profile

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.


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


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


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


source ~/.bash_profile


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

Leave a comment

Your email address will not be published. Required fields are marked *