Terminal hotness18 Oct 2012
The default Terminal prompt is kind of bad—it tells me very little and doesn't look super fly. After a bit of research, I learned how to customize colors, characters, variables, and show my git branch name.
Here's what the default Terminal looks like:
ComputerName:~/Directory/Path username $
Plain, and some what informative, but I don’t care about most of this. I know who I am and what computer I’m using, so that can go away. I also don’t need a $ to identify new lines. What I do need is some flavor, the path, and some git info. So I cooked up my own prompt to give me just that. Now, it looks like this:
To use this yourself, open
~/.bash_profile in your favorite editor, and add the following snippet:
export PS1='\e[0:35m⌘\e[m \e[0:36m\w/\e[m \e[0:33m`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`\e[m'
Save your changes and restart Terminal. Voilà. Breaking it down some, here's what's going on in this snippet, as outlined by this Geek Stuff article:
\e[starts a new color, while
0:35is the color we're setting for the ⌘ character. All declared colors take on the format of
X:Ym(yes, the m is required).
\wis a variable for outputting the current path. Other available variables include
\hfor hostname and
- Lastly, we grep throught the list of branches and output that.
Honestly, I don't know much about the last part, but it's a small script I picked up on with a big of Googling and has worked without a hitch so far.
Anywho, that's it. You can easily swap out the ⌘ special character and change the colors to make it your own. Enjoy!