title: Bash prompt with the last exit code
body: <p>I've been trying to customize my Bash prompt so that it will look like</p>
  <pre><code>[feralin@localhost ~]$ _
  </code></pre>
  <p>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:</p>
  <pre><code>\e[1;33m[$(if [[ $? == 0  ]]; then echo &quot;\e[0;31m&quot;; else echo &quot;\e[0;32m&quot;; fi)\u\e[m@\e[1;34m\h \e[0;35m\W\e[1;33m]$ \e[m
  </code></pre>
  <p>However, from my observations, the <code>$(if ...; fi)</code> seems to be evaluated once, when the <code>.bashrc</code> is run, and the result is substituted forever after. This makes the name always green, even if the last exit code is nonzero (as in, <code>echo $?</code>). Is this what is happening? Or is it simply something else wrong with my prompt? Long question short, <strong>how do I get my prompt to use the last exit code?</strong></p>