I want to display a green smile face if the previous exit code is 0 and red smile face if not successful.
Basically I want to do this prompt but with other stuff included.
PS1='\u@\h:\w `if [ $? = 0 ]; then echo \[\e[32m\]:\)\[\e[37m\]; else echo \[\e[31m\]:\(\[\e[37m\]; fi` $ '
I want to abstract the condition logic to a function but when I try to combine these two the escape characters show instead of the colors.
smiley()
{
if [ $? == 0 ]; then
echo ':)'
else
echo ':('
fi
}
RED="\033[1;5;91m"
GREEN="\033[1;5;92m"
NONE="\033[m"
NORMAL="\[\033[0m\]"
YELLOW="\[\033[1;4;93m\]"
MAGENTA="\[\033[35m\]"
WHITE="\[\033[1;37m\]"
BLINK="\[\033[5m\]"
#INVERT="\[\e[7m\]"
#OFF="\[\033[m\]"
PS1="${YELLOW}\u${MAGENTA}@${YELLOW}\h${NORMAL}:${WHITE}\w $(smiley)\n"
I even tried one line but it didn't work either.
PS1='\[\033[1;4;93m\]\u\[\033[35m\]@\[\033[1;4;93m\]\h\[\033[0m\]\[\033[1;37m\] \W if [ $? = 0 ]; then echo \[\e[32m\]:\)\[\e[37m\]; else echo \[\e[31m\]:\(\[\ e[37m\]; fi\n'
If there any way to do this without PROMPT_COMMAND?