解决方案
knitatoms' answer 的较少手动版本
结合Alex Marteilli's answer
效果很好:通过其寻呼机选项将+Gg 选项传递给less。
例如,试试
man -P 'less -s -M +Gg' man
这可以通过放置永久生效
export MANPAGER='less -s -M +Gg'
在您的一个 shell 配置文件中(以上语法适用于 Bash 和
ZSH)。现在,例如,man man 显示百分比为您
想要!
警告
您应该不将+Gg 放入LESS 变量中!例如,
在做
export LESS='-M +Gg'
在读取非常大的文件时会导致问题。例如,
yes | LESS='-M +Gg' less
效果不太好……
说明
正如其他答案所解释的,问题是less 不能说
你在文件中的百分比是多少,直到它知道文件多长时间
是,而且读取时默认不读到文件末尾
来自管道。
来自man less 的OPTIONS 部分:
+ If a command line option begins with +, the remainder of that
option is taken to be an initial command to less. For exam‐
ple, +G tells less to start at the end of the file rather than
the beginning, and +/xyz tells it to start at the first occur‐
rence of "xyz" in the file. As a special case, +<number> acts
like +<number>g; that is, it starts the display at the speci‐
fied line number (however, see the caveat under the "g" com‐
mand above). If the option starts with ++, the initial com‐
mand applies to every file being viewed, not just the first
one. The + command described previously may also be used to
set (or change) an initial command for every file.
g 表示“返回文件开头”。
来自man man:
-P pager, --pager=pager
Specify which output pager to use. By default, man uses pager
-s. This option overrides the $MANPAGER environment variable,
which in turn overrides the $PAGER environment variable. It
is not used in conjunction with -f or -k.
The value may be a simple command name or a command with argu‐
ments, and may use shell quoting (backslashes, single quotes,
or double quotes). It may not use pipes to connect multiple
commands; if you need that, use a wrapper script, which may
take the file to display either as an argument or on standard
input.