首页 > 解决方案 > 在 Zsh 中将 stderr 变为红色的代码错误?

问题描述

我确实有一些代码在 Zsh 中以红色突出显示标准错误;我从https://github.com/fniessen/shell-leuven#stderr-in-red复制了它

然而,发生了一些奇怪的事情:红色有时会被标准输出“破坏”,然后一直持续到屏幕的末尾(见最后一行,其中“已经是最新的”在以红色突出显示的区域之间被挤压):

在此处输入图像描述

(在第一个区块中同样奇怪的事情,在区块的末端有一条虚假的红线。)

如何解决这个问题?代码有问题吗?

PS - 上述输出的示例代码:

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

标签: terminalzshstderrmintty

解决方案


推荐阅读