Last Updated: February 25, 2016
·
1.924K
· victorbrca

Command prompt with color exit smiley face

Here's a neat little trick that you can use to display a color exit code smiley face on your shell prompt.

When the previous code exits with a 0, a green smiley face is displayed; if it exits with anything other than 0, then a red sad face is displayed.

victor@Desktop:~ :) $ cd /tmp
victor@Desktop:/tmp :) $ ls 123
ls: cannot access 123: No such file or directory
victor@Desktop:~ :(

Simply change the 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` $ '