Bash Prompt with Last Exit Code

后端 未结 7 1751
余生分开走
余生分开走 2020-11-30 22:12

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

7条回答
  •  不知归路
    2020-11-30 22:45

    Improved @demure

    I think this is important because there is not always exit status is 0 or 1.

    if [ $EXIT != 0 ]; then
        PS1+="${Red}${EXIT}:\u${RCol}"      # Add red if exit code != 0
    else
        PS1+="${Gre}${EXIT}:\u${RCol}"      # Also displays exit status
    fi
    

提交回复
热议问题