git bash 如何增加less的屏幕宽度?

In git bash how to increase less's screen width?

我正在 git bash 2.32 Windows 10.

在 git bash 更新到 2.32 后,我看到用于显示日志的命令有奇怪的行为:

git -c core.pager='less -S -F' log --all --decorate --oneline --graph

如您所见,我尝试使用“a dog”命令,less pager 配置为在 EOF 时退出并剪切长度超过当前屏幕宽度的行。 但在我更新到 2.32 后,输出似乎在 80 个符号后被截断,这通常比实际屏幕宽度小得多(如下图所示)。

我正在尝试了解如何增加该限制,以便 less 截断比 160 个符号长的行,或者截断不适合当前屏幕的行。

注意:我将宽度更改为 160,现在 echo $COLUMNS returns 160,但这一点帮助也没有。

注意:我还为当前会话启用了 checkwinsize 选项。也没有运气。

这是一个相对较新的 Git-for-Windows 错误,已找到 here in the archives for the Git mailing list. There is a lot of further discussion in this GitHub issue 的讨论和补丁。该错误将在 Git-for-Windows.

的下一次更新中修复

与此同时,考虑 this workaround from KalleOlaviNiemitalo:

git config --global core.pager "env -u COLUMNS less"

问题“Duplicated lines when moving in pager #3235”将在 Git 2.33(2021 年第 3 季度)中修复。
您今天可以使用 Git for Windows snapshots.

对其进行测试

(见顶部的重复行)

根本原因:当我们无法弄清楚终端有多宽时,我们自己使用80的回退值(这是不可避免的),但是当我们运行 寻呼机,我们在 COLUMNS 中导出它,这会强制寻呼机使用硬编码值,即使寻呼机完全有能力自行计算。

当我们退回到硬编码默认值供自己使用时,停止导出 COLUMNS

参见 commit 9b6e2c8 (21 Jun 2021) by Johannes Schindelin (dscho)
(由 Junio C Hamano -- gitster -- in commit 32d6280 合并,2021 年 7 月 8 日)

pager: avoid setting COLUMNS when we're guessing its value

Co-authored-by: Junio C Hamano
Signed-off-by: Johannes Schindelin

We query TIOCGWINSZ in Git to determine the correct value for COLUMNS, and then set that environment variable.

If TIOCGWINSZ is not available, we fall back to the hard-coded value 80 and still set the environment variable.

On Windows this is a problem.
The reason is that Git for Windows uses a version of less that relies on the MSYS2 runtime to interact with the pseudo terminal (typically inside a MinTTY window, which is also aware of the MSYS2 runtime).

Both MinTTY and less.exe interact with that pseudo terminal via ioctl() calls (which the MSYS2 runtime emulates even if there is no such thing on Windows).

Since https://github.com/gwsw/less/commit/bb0ee4e76c2, less prefers the COLUMNS variable over asking ncurses itself.

But git.exe itself is not aware of the MSYS2 runtime, or for that matter of that pseudo terminal, and has no way to call ioctl() or TIOCGWINSZ.

Therefore, git.exe will fall back to hard-coding 80 columns, no matter what the actual terminal size is.

But less.exe is totally able to interact with the MSYS2 runtime and would not actually require Git's help (which actually makes things worse here).
So let's not override COLUMNS on Windows.

Let's just not set COLUMNS unless we managed to query the actual value from the terminal.

This fixes git-for-windows/git issue 3235