Scriptim/bash-prompt-generator

Conditional color based on last exit code

jxu opened this issue · 1 comments

jxu commented

Something interesting my friend told me about is having the prompt symbol colored based on whether or not the last command succeeded, i.e. the value of $?:

image

Is conditional coloring or symbols too much complexity?

That is not a built-in feature of the Bash prompt as far as I know. So you'd have to write a custom function (e.g., in your .bashrc or inline) that outputs the colored prompt symbol. Then you can use the Command element in the prompt generator and configure it to call the function.

For instance, you could use the following command:

if [[ "$?" == "0" ]]; then echo -e "\e[32m✓\e[0m"; else echo -e "\e[31m✘\e[0m"; fi