So I've been asked a couple of times for this post and I keep not getting around to it so thought I would take some time and get this out. My bash prompt is very informative, long, and functional and that is they way I like it. One prompt actually results in 2 lines in my terminal being used. This is my current Bash Prompt in terminal:
- First thing to notice is my command prompt is actually on the second line, below all the information. This is by design.
- The first part of the prompt in the typical username and computer name. Nothing special. A lot of people remove this but I keep it. When all the voices in my head start shouting at each other I can always look at my command prompt and remember who I am.
- Next is my location on the computer. Again, a lot of people will just have this piece represent only the current folder but I like to see the entire path. Main reason is I might have several Project folders on my system and this helps me to see which Project folder I am in.
- Then comes this little piece of magic that I love, my Git Branch. This section only displays when I am in a directory structure related to a Git checkout and shows me which branch of that git checkout I am working on. This section, depending on your system, may require different set ups. Since I am on my OSX system what I am using is
git-completion.bash
(orgit-prompt.sh
). One of the better post on how to install this correctly can be found on a StackOverFlow.com thread. Keep in mind, if I am not on a Git branch none of this section displays, not even the []- which makes it is very clean. - Finally I like to add a time stamp to the end of my prompt. This allows me to return to a console and figure out when I last ran something from that window. It's very helpful. The time doesn't stay current, meaning it won't continue to keep time, it will only show you the time when that prompt was created and that is it.
The prompt does include the different colors for the different sections if your system supports it and most Unix type console do support it. Here is the magic that makes this happen.
There are a couple of ways to play around with this, tweak it until you find what you like, without impacting your system permanently until you want to. At the command prompt simply copy and past the entire line including the word "export", you should be able to see the new prompt immediately. Once you've tweaked it to exactly what you want you can add it to either you .profile
or .bash_profile
files however you can remove the word export when you do that and just start the line at PS1
If you would like a version without the Git Branch indicator this version should work for you
Here is a link to some other helpful and fun Bash Prompts
Enjoy and Happy Bash'ing
Update: My buddy @johncongdon on twitter pointed out by adding export GIT_PS1_SHOWDIRTYSTATE=1
to your .profile
or .bash_profile
then you will also get the status of the Git branch.