【问题标题】:How to preserve the color of input when piping to grep?管道传输到 grep 时如何保留输入的颜色?
【发布时间】:2023-01-11 23:55:52
【问题描述】:

当管道传输到grep时,我想保留任意命令的颜色(在我的例子中,可能与问题相关,git diff),这样grep就不会应用它自己的任何额外颜色并保留原版的。

例如,假设 git diff 的输出包含

-    hello world
+    goodbye world

这会将 - 线染成红色,将 + 线染成绿色。我希望 git diff | grep world 的结果保持红色和绿色。

【问题讨论】:

    标签: git terminal colors grep pipe


    【解决方案1】:

    尝试

    git diff --color=always | grep --color=never world
    

    git help diff

    【讨论】:

      猜你喜欢
      • 2019-01-24
      • 2011-01-20
      • 2017-01-07
      • 1970-01-01
      • 2023-03-15
      • 2021-04-05
      • 2012-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多