Battles With Boredom

May 13, 2009

Useful and Fun Bash Prompt Tweaking

Filed under: Politics,Techspeak — Peter Nikolaidis @ 4:31 pm

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 :) $

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress

© 2012-2014 Peter C. Nikolaidis All Rights Reserved -- Copyright notice by Blog Copyright