How can you customize your terminal bash prompt with smiley faces?
I'm trying to figure out how I can customize my terminal's bash prompt to use smiley faces. What I want (as seen in the example blow) is for the cwd to be separated from the prompt by a \n and show a green smiley face if the command succeeded, and a red sad face if it failed.
Any ideas?
This was inspired by a Peepcode screencast.
Solution 1:
After spending about a half hour playing around with andhrimnir's code and doing further research, I finally got what I wanted.
PS1="\w \`if [ \$? = 0 ]; then echo -e '\[\e[01;32m\]\n\xE2\x98\xBA'; else echo -e '\[\e[01;31m\]\n\xE2\x98\xB9'; fi\` \[\e[01;34m\]\[\e[00m\]"
You can find a list of emoticons here and then convert them to the 3-digit byte code you see after the newline character.
To get the cwd
, all I had to do was use \w
. You could also show the current user by doing \u@\w
, which would output something like joshsmith@~
.
Solution 2:
It appears that the smiley face shown above is unicode character 0x263a
. So you'll need a unicode-capable terminal (Not sure if terminal.app supports this, I imagine it does though).
Here's sample code that prints a green smiley face for return codes of 0 and red frown faces otherwise.
PS1="\[\e[01;32m\]\u@\h \[\e[01;34m\]\W \`if [ \$? = 0 ]; then echo -e '\[\e[01;32m\]:)'; else echo -e '\[\e[01;31m\]:('; fi\` \[\e[01;34m\]$\[\e[00m\]"
Credit goes to Fingel on the Arch forums (he posted it here).