My custom Bash shell prompt

I spent quite a bit of time, in my opinion, perfecting my Bash shell prompt.  To be fair, its always evolving.  However, I just recently got it to a point that I’m really happy with.  The one thing that’s been the most frustrating is that I literally know NOTHING about shell scripting in Bash or anything even remotely close.  So I really just fumble my way through it and do a LOT of trial and error until things just sort of work.  Here’s an example of what my prompt looks like:

Screen Shot 2013-11-13 at 9.11.32 PM

A few things to note about my prompt:

  1. I use a dark background on my terminal window, so my colors are set accordingly.
  2. My prompt primarily consists of my username, machine name, and current working directory.
  3. I use a little divider (regardless of terminal width) to separate those details from my current Git branch.
  4. My Git branch is color coded depending on if its dirty or not. (Green is fine, red is modified)
  5. My actual prompt cursor is on the 2nd line.

The actual .bash_profile file I setup can be found in a handy repo I created specifically to house files for my development machine.  This way if I ever get a new machine or need to have it wiped and start from scratch, most of my custom configuration files and settings can be found in one place.

Download my .bash_profile file.
Note: that repo also has my Sublime preferences backed up!

A few other things about my .bash_profile:

  • I have a bunch of convenience aliases (most may not be of any use to you)
  • I do have some shortcuts for Git in there, which are nice.
  • There’s a neat “sls” alias (super list?) that outputs a color coded dir listing
  • The code to actually build the prompt is REAL hacky – but it works!
  • Note: sourcing git-prompt.sh at the top is necessary so that you can use __git_ps1 further down to actually output the branch details to the prompt.

Enjoy!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s