Blog is moving

My blog is moving to http://victormendonca.com/blog/. If you are looking for a specific or older post you are in the right place Otherwise check out my new page for more up to date content.

Wednesday, November 21, 2012

Command prompt exit face (color smiley face)

Here's a neat little hack that you can use to display a color exit code smiley face on your shell prompt (also refer to "Playing with terminal colors on your script" for more info on color and shell).

Here's what the end result looks like:
victor@Desktop:~ :) $ cd /tmp
victor@Desktop:/tmp 
:) $ ls 123
ls: cannot access 123: No such file or directory

victor@Desktop:~ :(

To achieve that, simply change your PS1 variable in your profile or you shell rc file to the code below:
PS1='\u@\h:\w `if [ $? = 0 ]; then echo \[\e[32m\]:\)\[\e[37m\]; else echo \[\e[31m\]:\(\[\e[37m\]; fi` $ '

No comments: