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:
A few things to note about my prompt:
- I use a dark background on my terminal window, so my colors are set accordingly.
- My prompt primarily consists of my username, machine name, and current working directory.
- I use a little divider (regardless of terminal width) to separate those details from my current Git branch.
- My Git branch is color coded depending on if its dirty or not. (Green is fine, red is modified)
- 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.
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.