gpt4 book ai didi

less-unix - 如何让 Less 以百分比表示位置

转载 作者:行者123 更新时间:2023-12-03 15:06:19 24 4
gpt4 key购买 nike

我现在的目标是在您运行时也显示百分号,例如,命令

man emacs

例如,如果你运行它,你会得到'byte 3300'。

Alex's answer建议我我们需要通过
man "$1"| col -b > /tmp/manual
less /tmp/manual

其中 $1 指的是第一个参数。

新问题在 thread .感谢 Yuliy 的关键举措!

最佳答案

解决方案

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显示百分比
通缉!

警告

你不应该把 +GgLESS多变的!例如,
正在做
export LESS='-M +Gg'

读取非常大的文件时会导致问题。例如,
yes | LESS='-M +Gg' less

不能很好地工作......

解释

正如其他答案所解释的那样,问题在于 less不能说
你在文件中的百分比是多少,直到它知道文件多长时间
是,而且读取时默认不读到文件末尾
从管道。

来自 OPTIONS man less的部分:
+      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.

关于less-unix - 如何让 Less 以百分比表示位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1049350/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com