如何减少以百分比表示位置 [英] How to make Less indicate location in percentage
问题描述
我现在的目标是在运行时也显示百分比符号,例如命令
I now aim to show the percentage sign also when you run, for example, the command
man emacs
如果运行它,您将得到例如字节3300".
If you run it, you get 'byte 3300' for instance.
Alex的答案建议对我来说,我们需要通过以下方式制作单独的shell函数:
Alex's answer suggests me that we need to make a separate shell function by
man "$1"| col -b > /tmp/manual
less /tmp/manual
其中$ 1表示第一个参数.
where $1 refers to the first parameter.
新问题出在线程. 感谢Yuliy的关键动作!
推荐答案
解决方案
knitatoms答案的手动版本较少
结合 Alex Marteilli的答案
效果很好:将+Gg
选项通过其分页器选项传递给less
.
Solution
A less manual version of knitatoms' answer
combined with Alex Marteilli's answer
works quite well: pass the +Gg
option to less
via its pager option.
例如,尝试
man -P 'less -s -M +Gg' man
这可以通过永久放置来实现
This can be effected permanently by putting
export MANPAGER='less -s -M +Gg'
在您的一个shell配置文件中(以上语法适用于Bash和
ZSH).现在,例如,man man
将百分比显示为
想要!
in one of your shell configuration files (above syntax is for Bash and
ZSH). Now, for example, man man
displays the percentage as you
wanted!
您不应不将+Gg
放入LESS
变量中!例如,
做
You should not put the +Gg
in the LESS
variable! For example,
doing
export LESS='-M +Gg'
在读取非常大的文件时会引起问题.例如,
will cause problems when reading very large files. For example,
yes | LESS='-M +Gg' less
效果不是很好...
正如其他答案所解释的那样,问题是less
不能说
您知道文件占多大的百分比,直到知道文件有多长时间
是,并且在读取时默认情况下不会读取到文件末尾
从管道.
As other answers have explained, the problem is that less
can't say
what percent into the file you are until it knows how long the file
is, and it doesn't read to the end of the file by default when reading
from a pipe.
来自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
的意思是返回文件的开头".
The g
means "return to the beginning of file".
来自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.
这篇关于如何减少以百分比表示位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!