agkozak-zsh-prompt
agkozak-zsh-prompt copied to clipboard
Request: display pipestatus when any exit codes are non-zero
I'm looking for a change like the following (but this doesn't work and I'm not sure why):
- AGKOZAK[PROMPT]+='%(?..%B%F{${AGKOZAK_COLORS_EXIT_STATUS:-red}}(%?%)%f%b )'
+ AGKOZAK[PROMPT]+='${${pipestatus:#0}:+%B%F{${AGKOZAK_COLORS_EXIT_STATUS:-red}\}(${(j:|:)pipestatus})%f%b }'
Here's how something similar looks in p10k:
I don't know if it would be better to implement in a way that can be toggled or not; I would want this always enabled.
I just got back from a trip; I'll try to come up with an answer for you in the next few days.
@AndydeCleyre I just realized that I never got back to you about this! Forgive me.
I think what you're looking for is
AGKOZAK_CUSTOM_PROMPT='${${pipestatus#0}:+%B%F{red\}(${"${pipestatus[*]}"// /|})%f%b } '
In other words, if pipestatus
is a single zero, print nothing; otherwise treat the array pipestatus
as a space-delimited string, replace the spaces with vertical bars, and make the whole thing bold and red.
I like that so much that I think I'll use it in my custom prompt. If I still like it in a few weeks, perhaps I'll make it a standard feature.
I just realized it's not that simple, is it? The prompt prints correctly, but then pipestatus
becomes 0
again and the string disappears.
Let me look into this a bit more deeply.
OK, here's the code you can use until I build this feature into the prompt:
_andy_pipestatus() {
typeset -g ANDY_PIPESTATUS="${(%)${${pipestatus#0}:+%B%F{${AGKOZAK_COLORS_EXIT_STATUS}\}(${"${pipestatus[*]}"// /|})%f%b }}"
}
autoload -Uz add-zsh-hook
add-zsh-hook precmd _andy_pipestatus
and then add to your custom prompt
AGKOZAK_CUSTOM_PROMPT='${ANDY_PIPESTATUS}'
Later I’ll make it so that it changes colors.
Here we go: green when the last result is 0, red otherwise:
_andy_pipestatus() {
typeset -g ANDY_PIPESTATUS="${${pipestatus#0}:+(${"${pipestatus[*]}"// /|})}"
[[ -z $ANDY_PIPESTATUS ]] && return
if [[ $ANDY_PIPESTATUS == *0\) ]]; then
typeset -g ANDY_PIPESTATUS="%F{108}${ANDY_PIPESTATUS}%f "
else
typeset -g ANDY_PIPESTATUS="%B%F{${AGKOZAK_COLORS_EXIT_STATUS}\}${ANDY_PIPESTATUS}%f%b "
fi
}
autoload -Uz add-zsh-hook
add-zsh-hook precmd _andy_pipestatus