Useful and Fun Bash Prompt Tweaking

A friend of mine gave me the following code, which he pulled off of http://serverfault.com. The site’s still in beta, and I don’t have an account there so I can’t actually get the full source URL, but here’s the code:
RESET="\[\017\]"
NORMAL="\[\033[0m\]"
RED="\[\033[31;1m\]"
YELLOW="\[\033[33;1m\]"
WHITE="\[\033[37;1m\]"
SMILEY="${WHITE}:)${NORMAL}"
ANGRY="${RED}:(${NORMAL}"
SELECT="if [ \$? = 0 ]; then echo \"${SMILEY}\"; else echo \"${ANGRY}\"; fi"

PS1="${RESET}[\u@\h]: \w \`${SELECT}\` ${YELLOW}${NORMAL}\$ "

What does this do? Why, it makes your bash prompt display a smiley face, depending on the output of the previous command! Just append this to your .bashrc file, and you’ll get handy, emotional output every time you issue a command.
Here’s a sample of the output:
[peter@standard]: ~ :) $ mkdir tmp
[peter@standard]: ~ :) $
cd tmp
[peter@standard]: ~/tmp :) $
touch test1.txt test2.txt
[peter@standard]: ~/tmp :) $
echo "hi" > test2.txt
[peter@standard]: ~/tmp :) $
diff test1.txt test2.txt
0a1
> hi
[peter@standard]: ~/tmp :( $
cat test1.txt > test2.txt
[peter@standard]: ~/tmp :) $
diff test1.txt test2.txt
[peter@standard]: ~/tmp :) $

Leave a Reply