Bash Prompt with Last Exit Code
So, I've been trying to customize by bash prompt so that it will look like [feralin@localhost ~]$ _ with colors. I managed to get constant colors (the same colors every time I see the prompt) but I want the username ('feralin') to appear red, instead of green, if the last command had a nonzero exit status. I came up with: \e[1;33m[$(if [[ $? == 0 ]]; then echo "\e[0;31m"; else echo "\e[0;32m"; fi)\u\e[m@\e[1;34m\h \e[0;35m\W\e[1;33m]$ \e[m However, from my observations, the $(if ...; fi) seems to be evaluated once, when the .bashrc is run, and the result is substituted forever after. This