Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: display pipestatus when any exit codes are non-zero #34

Open
AndydeCleyre opened this issue Jun 3, 2021 · 5 comments
Open
Assignees

Comments

@AndydeCleyre
Copy link
Contributor

AndydeCleyre commented Jun 3, 2021

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:

image

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.

@agkozak agkozak self-assigned this Jun 9, 2021
@agkozak
Copy link
Owner

agkozak commented Jun 12, 2021

I just got back from a trip; I'll try to come up with an answer for you in the next few days.

@agkozak
Copy link
Owner

agkozak commented Oct 17, 2021

@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.

@agkozak agkozak closed this as completed Oct 17, 2021
@agkozak agkozak reopened this Oct 17, 2021
@agkozak
Copy link
Owner

agkozak commented Oct 17, 2021

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.

@agkozak
Copy link
Owner

agkozak commented Oct 17, 2021

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.

@agkozak agkozak closed this as completed Oct 17, 2021
@agkozak agkozak reopened this Oct 17, 2021
@agkozak
Copy link
Owner

agkozak commented Oct 18, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants