Terminal hotness

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:…


This content originally appeared on @mdo and was authored by Mark Otto

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:

New Terminal prompt

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 \e[m ends it.
  • 0:35 is the color we’re setting for the ⌘ character. All declared colors take on the format of X:Ym (yes, the m is required).
  • \w is a variable for outputting the current path. Other available variables include \h for hostname and \u for username.
  • 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!


This content originally appeared on @mdo and was authored by Mark Otto


Print Share Comment Cite Upload Translate Updates
APA

Mark Otto | Sciencx (2012-10-18T00:00:00+00:00) Terminal hotness. Retrieved from https://www.scien.cx/2012/10/18/terminal-hotness/

MLA
" » Terminal hotness." Mark Otto | Sciencx - Thursday October 18, 2012, https://www.scien.cx/2012/10/18/terminal-hotness/
HARVARD
Mark Otto | Sciencx Thursday October 18, 2012 » Terminal hotness., viewed ,<https://www.scien.cx/2012/10/18/terminal-hotness/>
VANCOUVER
Mark Otto | Sciencx - » Terminal hotness. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2012/10/18/terminal-hotness/
CHICAGO
" » Terminal hotness." Mark Otto | Sciencx - Accessed . https://www.scien.cx/2012/10/18/terminal-hotness/
IEEE
" » Terminal hotness." Mark Otto | Sciencx [Online]. Available: https://www.scien.cx/2012/10/18/terminal-hotness/. [Accessed: ]
rf:citation
» Terminal hotness | Mark Otto | Sciencx | https://www.scien.cx/2012/10/18/terminal-hotness/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.