My History of Shell Prompts
posted on 2014-12-08 by Spencer Bravo
As odd as it might seem, until recently I was using the basic, out of the box, shell prompt. The code for this, in my bashrc, was just the basic:
PS1='\u@\h \w \$'
If you don't know what PS1 or bash is then this is probably the setup you have. This produces a shell prompt such as: spencer@plutonium ~/dotfiles $
This prompt works just fine. But its so boring! I kept this setup for probably the first 6 months I started using linux. But then I wanted to start to spice things up with my shell prompt. So I downloaded Ed's colors.sh file from his dotfiles. To utilize this all you have to do is include it in your bashrc(see my dotfiles for an example). I went through his colors and decided to make my prompt purple. So all I had to do was change my prompt to this: PS1='${Purple}\u@\h \w \$'
I kept this setup for about a month but then thought "why do I bother keeping my hostname? It just takes up space." So I changed it to PS1='${Purple}\u: \w \$'
I kept this configuration for quite some time but then I saw something cool that Ed did. He created a small script that checks to see if the command was succesful or not and if it was succesful it would place a green smiley, but if it wasn't it would give back a red frown. You can find that script: here. Then I just changed my PS1 to: PS1='${Purple}\u: \w [$(checkium_color)\]$(checkium_random_face) \$'
At this point I had a prompt like this(note:colors not included): spencer: ~/dotfiles :) $
I kept this configuration for probably about two months but then noticed that I had an issue. Some directories were very long and took up a lot of space so my prompt looked something like this: spencer: ~/Dropbox/codeshrub/posts/code :) $
This took up way too much space so I changed the w in my PS1 to W to only show the latest directory: PS1='${Purple}\u: \W [$(checkium_color)\]$(checkium_random_face) \$'
So now that long directory is just spencer: code :) $
Much easier to read, takes up less space, and it's not likely I'll forget my earlier directory path. I made one last change to my prompt. I removed the external script to check for a succesful command and place a smiley face and to replace it, I added this to my bash profile: cmd_check() {
if [[ $? = 0 ]]; then
echo " ${Green}✓";
else
echo " ${Red}❌";
fi;
And also changed my PS1 to: PS1='${BIGreen}\u: ${IWhite}\W $(cmd_check) \$${Color_Off} '
This changes my colors, removes the smileys and adds the x and check, and also makes sure colors are off at the end of the prompt. This is my final product(on the actual one there are the pretty colors :) ):
spencer: ~ ✓ $
I hope you enjoyed this post and I hope it helps you on your PS1 endevors.
posted in bash