0

I do have some code to highlight stderr in red, in Zsh; I've copied it from https://github.com/fniessen/shell-leuven#stderr-in-red

However, there are strange things happening: the red is sometimes "broken" by stdout, and then continues up to the end of the screen (see last line, where "Already up to date" is squashed between regions highlighted in red):

enter image description here

(Same strange thing in the first block, where there is a spurious red line at the end of the block.)

How to solve this? Is there something wrong in the code?

PS - Example code for the above output:

BLU=$(tput bold)$(tput setaf 4)
reset=$(tput sgr0)

find . -maxdepth 5 -name ".git" -type d | rev | cut -c 6- | rev | sed "s#^\./##" |
    while IFS=$'\n' read -r repo; do
        printf '%s\n' "Current repository: ${BLU}$repo${reset}"
        git -C "$repo" remote update --prune
        git -C "$repo" merge --ff-only "@{u}"
        echo
    done
Maciej Łoziński
  • 812
  • 1
  • 10
  • 16
user3341592
  • 1,419
  • 1
  • 17
  • 36
  • 1
    You have no control over how standard error and standard output are interleaved by the terminal, and the terminal doesn't know or care which stream the ANSI escape sequences instructing it to change colors came from. – chepner Feb 14 '20 at 15:26
  • I can follow "your" logic but, then, how is "Already up to date" in white? I guess there is not "white escape sequence" sent before outputting stdout? – user3341592 Feb 14 '20 at 17:33
  • Pipe the output to `hexdump` or write to a file (taking care that you configure Git to output color even if it isn't writing to a terminal) to see just what escape sequences *are* being generated. – chepner Feb 14 '20 at 17:46
  • @chepner, if I pipe the output to `hexdump`, then the stderr is not directed to it, right? Same with a file, except if I do `2>&1`, but then nothing would be sent to stderr anymore. So, how can I do? – user3341592 Feb 17 '20 at 14:23
  • `... 2>&1 | hexdump` will send both streams to `hexdump`. It won't necessarily be interleaved line-by-line, but you should be able to pick out the escape sequences being written to each stream by context. – chepner Feb 17 '20 at 15:02

0 Answers0