Scriptim/bash-prompt-generator

Change prompt color based on previous command status

behnamgolds opened this issue · 1 comments

Hey , I was wondering if you could add this feature, where if the previous command failed , the prompt color turn into red and otherwise change to green or maybe change emojis instead (with options to select the colors/emojis) ?

something like this maybe :

PS1="\ \$(if [[ \$? -gt 0 ]]; then printf \"\\[\\033[01;31m\\]\xF0\x9F\x98\xA7\"; else printf \"\\[\\033[01;32m\\]\xF0\x9F\x98\x83\"; fi)\ \[\033[01;30m\]\u\ \[\033[01;33m\]@\ \[\033[01;36m\]\h \ \[\033[01;33m\]\w \ \[\033[01;35m\]\\$ \ \[\033[00m\]\ "

Screenshot_2024-05-02_09-59-50

Hey, Bash has no built-in feature for that but it can be realized using a custom command. See #27 for details.