Dre*_*kes 10 git watch-command
运行时git status -sb我看到:

我想要watch(来自 procps-ng 3.3.3)一个存储库。该--color选项应该保留颜色。
有趣的是,它适用于ls:
$ watch --color "ls --color"
Run Code Online (Sandbox Code Playgroud)
显示:

但是对于git颜色消失:
$ watch --color "git status -sb"
Run Code Online (Sandbox Code Playgroud)

那么,为什么watch显示ls来自git输出而不是来自输出的颜色?
git 使用配置值来确定是否显示彩色输出。
例如:
git config --global color.ui auto
Run Code Online (Sandbox Code Playgroud)
这会将颜色设置设置为auto全局。在auto模式下,正如 Oli 建议的那样,git 将在发送颜色代码之前确定它是否是真正的终端。
您可以将此全局值强制为always,但更好的主意可能是将其应用于特定命令:
git -c color.status=always status -sb
Run Code Online (Sandbox Code Playgroud)
把它们放在一起:
watch --color git -c color.status=always status -sb
Run Code Online (Sandbox Code Playgroud)
以下陈述是正确的:
watch在新的 shell 中运行命令,sh..bashrc别名ls为ls --color=auto使颜色。sh不继承或使用bash别名。所以当watch运行时ls,它不要求颜色,它只是运行普通的旧版本。您可以规避这一点,但正如 aditya 指出的那样,您还需要启用颜色watch才能正确处理它们。
一个工作示例ls是:
watch --color -- ls --color=always
Run Code Online (Sandbox Code Playgroud)
如果你不通过--color观看,你会看到一堆丑陋的内嵌颜色代码。
ls --color被解释为ls --color=always。
ls --color=auto 不会在手表中打印颜色。这表明它是从终端本身推断颜色支持。
有关原因的更多信息,我们可以测试 watch shell 是否认为它是一个真正的终端:
$ bash -c '[[ -t 1 ]] && echo "real terminal"'
real terminal
$ watch -- "bash -c '[[ -t 1 ]] && echo "real terminal"'"
# ... nothing.
Run Code Online (Sandbox Code Playgroud)
我怀疑某些应用程序正在查看(或类似)以判断它们是否应该打开颜色。
| 归档时间: |
|
| 查看次数: |
4031 次 |
| 最近记录: |