Customize zsh's prompt when displaying previous command exit code

前端 未结 2 1555
梦谈多话
梦谈多话 2021-02-02 06:59

Zsh includes the ability to display the return code/exit code of the previous command in the prompt by using the %? escape sequence.

However I would like to

2条回答
  •  既然无缘
    2021-02-02 07:49

    Add this in the position in PS1 where you want the exit code to appear:

    %(?..[%?] )
    

    It's a conditional expression. The part between the two dots (nothing in this case) is output if the expression before the first dot is true. The part after the second dot is output if it's false.

    For example:

    PS1='%n%m %~ %(?..[%?] )%# '
    

提交回复
热议问题