I want to include the return status in my prompt. (Easy add '$? '
, right?)
However, I only want the status returned (and trailing space) if non-zero.
Example:
sd ~ $ false
1 sd ~ $ true
sd ~ $
bashprompt
I want to include the return status in my prompt. (Easy add '$? '
, right?)
However, I only want the status returned (and trailing space) if non-zero.
Example:
sd ~ $ false
1 sd ~ $ true
sd ~ $
Best Answer
Make sure that the
promptvars
option is on (it is by default). Then put whatever code you like inPROMPT_COMMAND
to define a variable containing exactly what you want in the prompt.In zsh you could use its conditional construct in
PS1
(bash has no equivalent).