使用 git grep 时自动换行

发布于 2024-12-11 12:20:34 字数 103 浏览 0 评论 0原文

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

I am trying to run git grep from terminal (using Titanium). The results do not wrap and get cut off at the window so I cannot read anything. I tried messing around with config but could not get anything. How can I make these grep results wrap?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

讽刺将军 2024-12-18 12:20:34

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

编辑:即使当我取消设置core.pager时,git grep似乎默认会调用less -S

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

 -S 或 --chop-long-lines
          导致比屏幕宽度长的线条被截断
          比折叠。也就是说,长线中不存在的部分
          不显示适合屏幕宽度。默认是折叠
          排长队;也就是说,将余数显示在下一行。

Have you set core.pager in your .gitconfig? If you are using less, you can see the extra characters by pressing the right arrow key on the keyboard.

Edit: Even when I unset core.pager, git grep seems to invoke less -S by default.

Edit 2: Whoops, as Keith Thompson pointed out less does wrap lines by default. From the man page:

   -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.
自找没趣 2024-12-18 12:20:34

尝试通过 cat 管道输出。

Try piping the output through cat.

放血 2024-12-18 12:20:34

有了像 less 这样的分页器, git grep 已经能够将选项传递给所述寻呼机:

-e

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

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

请参阅 提交 f7febbe 来自 约翰内斯·辛德林 (dscho)

git grep -O -i:如果寻呼机为“less”,则传递“-I”选项

恰好是魔术字符串“less”时,今天

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

有助于将 +/ 传递给 less,以便您可以使用 nshift+ 浏览文件中的结果n 次按键。

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

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

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

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

With a pager like less, git grep was already able to pass options to said pager:

-e

The next parameter is the pattern.
This option has to be used for patterns starting with - and should be used in scripts passing user input to grep.

Starting git 2.0.1 (June 25th, 2014), that also also work with case insensitive git grep.

See commit f7febbe from Johannes Schindelin (dscho):

git grep -O -i: if the pager is 'less', pass the '-I' option

When <command> happens to be the magic string "less", today

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

helpfully passes +/<pattern> to less so you can navigate through the results within a file using the n and shift+n keystrokes.

Alas, that doesn't do the right thing for a case-insensitive match,
i.e.

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

For that case we should pass --IGNORE-CASE to "less" so that n and shift+n can move between results ignoring case in the pattern.

The original patch came from msysgit and used "-i", but that was not due to lack of support for "-I" but it merely overlooked that it ought to work even when the pattern contains capital letters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文