【问题标题】:Word wrap when using git grep使用 git grep 时自动换行
【发布时间】:2011-12-12 18:23:59
【问题描述】:

我正在尝试从终端运行 git grep(使用 Titanium)。结果不会包裹并在窗口处被切断,因此我无法阅读任何内容。我尝试弄乱配置,但什么也得不到。如何使这些 grep 结果换行?

【问题讨论】:

标签: linux git terminal


【解决方案1】:

使用像 less 这样的寻呼机,git grep 已经能够将选项传递给所述寻呼机:

-e

下一个参数是模式。
此选项必须用于以 - 开头的模式,并且应该在将用户输入传递给 grep 的脚本中使用。

从 git 2.0.1(2014 年 6 月 25 日)开始,它也适用于不区分大小写的 git grep

Johannes Schindelin (dscho) 看到commit f7febbe

git grep -O -i:如果寻呼机是'less',则传递'-I'选项

<command>恰好是魔串“less”时,今天

git grep -O<command> -e<pattern>

有助于将 +/&lt;pattern&gt; 传递给 less,因此您可以使用 nshift+n 击键浏览文件中的结果。

唉,这对于不区分大小写的匹配来说是不正确的,

git grep -i -O<command> -e<pattern>

对于这种情况,我们应该将--IGNORE-CASE 传递给“less”,以便 nshift+n 可以在结果之间移动忽略模式中的大小写。

原始补丁来自 msysgit 并使用“-i”,但这并不是因为缺乏对“-I”的支持,而是它只是忽略了即使模式包含大写字母它也应该工作。

【讨论】:

    【解决方案2】:

    您是否在您的.gitconfig 中设置了core.pager?如果您使用的是less,则可以通过按键盘上的右箭头键来查看多余的字符。

    编辑:即使我取消设置core.pagergit grep 似乎默认调用less -S

    编辑 2: 哎呀,正如 Keith Thompson 指出的那样,less 默认情况下会换行。从手册页:

       -S or --chop-long-lines
              Causes lines longer than the screen width to be  chopped  rather
              than  folded.  That is, the portion of a long line that does not
              fit in the screen width is not shown.  The default  is  to  fold
              long lines; that is, display the remainder on the next line.
    

    【讨论】:

    • less 中,-S 在换行和截断之间切换。
    • 啊,你说得对。我使用-S,所以我认为这种行为是默认的。我已将此添加到我的答案中。
    • 如果你真的想修改行为,正确的方法是设置LESS环境变量。如果未设置,Git 默认为FRSXF 使其在小于屏幕时自动退出,X 使其正常工作(避免弄乱回滚),R 使其显示颜色。所以你可能想使用LESS=FRX 来避免弄乱其他任何东西。
    【解决方案3】:

    尝试通过cat 管道输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多