Creating a Bash command prompt with a red $ after failure of previous command

后端 未结 3 601
情书的邮戳
情书的邮戳 2021-01-13 06:03

I\'m new to Bash programming, and I\'m working on creating a custom Bash command prompt. My goal is to create a prompt which only shows the login name and h

3条回答
  •  心在旅途
    2021-01-13 06:29

    I got it to work:

    PROMPT_COMMAND='if [ $? = 0 ]; then PS1="\[\e[32;1m\]\u@\[\e[0m\e[30;47m\]\H\[\e[0m\]:\[\e[34;1m\]\w\[\e[0m\]$ "; else PS1="\[\e[31;1m\]\u@\[\e[0m\e[31;47m\]\H\[\e[0m\]:\[\e[31;1m\]\w\[\e[0m\]$ "; fi'
    

    enter image description here

    Standing on the sholders of @jtbandes. @jtbandes is the original author of the idea.

提交回复
热议问题