Customize zsh's prompt when displaying previous command exit code

点点圈 提交于 2019-12-02 20:08:58

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 %~ %(?..[%?] )%# '

Alternatively, you can:

setopt PRINT_EXIT_VALUE

to always print a newline showing previous return value.

I don't prefer this for ordinary use, but it is often good for debugging shell scripts.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!