[ACCEPTED]-How to make Less indicate location in percentage-less-unix
A less manual version of knitatoms' answer
combined with 16 Alex Marteilli's answer
works quite well: pass the
+Gg option to
less via 15 its pager option.
For example, try
man -P 'less -s -M +Gg' man
This can 14 be effected permanently by putting
export MANPAGER='less -s -M +Gg'
in one 13 of your shell configuration files (above 12 syntax is for Bash and
ZSH). Now, for example,
man man displays 11 the percentage as you
You should 10 not put the
+Gg in the
LESS variable! For example,
export LESS='-M +Gg'
will 9 cause problems when reading very large files. For 8 example,
yes | LESS='-M +Gg' less
does not work very well ...
As other 7 answers have explained, the problem is that 6
less can't say
what percent into the file you 5 are until it knows how long the file
is, and 4 it doesn't read to the end of the file by 3 default when reading
from a pipe.
From the 2
OPTIONS section of
+ 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 means "return to 1 the beginning of file".
-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.
More generally, the
LESS environment variable 30 may contain options equivalent to command 29 line flags you could explicitly pass when 28 running
less -- here, the
-m option that tells 27 it to prompt more richly (including the 26 percentage, as you asked). You could pass 25 also more than one option within that single 24 environment variable by ending each with 23 a
$. For much more info, see less's manpage.
Edit: it is of 22 course possible (depending on how you're 21 using less, e.g. if you're piping to it 20 rather than calling it on a file) that less 19 doesn't know the total size it will be displaying, in 18 which case of course it can't show the % -- in 17 that case it will prompt with what little 16 info it does have, e.g., how much text has 15 it shown so far. For example,
man does use 14
less that way, by piping.
So, if your specific 13 need is to see the % in
man (rather than when 12 calling
less directly on a file) you need to 11 use an "alternate pager" (environment 10 variable
MANPAGER or switch
-P on the
man command line) which 9 is a simple script that saves
man's output 8 to a temp file and then uses
less on the latter. (That 7 may lose man's own "colorization" unless 6 you play yet further and deeper tricks, etc, etc 5 -- similarly you might use the "preformat 4 pages" option of
man and uncompress such 3 a preformatted page to a tempfile on which 2 to run
less, etc, but this is starting to become 1 a somewhat complex "simple script";-).
To add to Alex Martelli' answer:
Note that 7 you can also pass any command line parameter 6 to less at runtime, by just typing it (including 5 the -), followed by enter key. So you can 4 just type
into a running less to toggle 3 the long prompt.
This is especially useful 2 for options that need to be changed at runtime, e.g. -S 1 (line folding on/off).
On Linux I just go to the end of the man 8 page with Shift+G then return to the beginning 7 with g. (Or you can return to your previous 6 position with '').
Less then has enough information 5 to display the percentage of how far through 4 the file you are. (You might need to type 3
-M to get the long prompt.)
It's a bit of a 2 hack but only two key presses. Not sure 1 if this works on OS/X.
With a live
less runtime I used
-MEnter" at 4 the
: prompt with less running.
With really 3 large buffers I also had to go to the end 2 to "discover" their size. End and 1 back Home.
Note: I would have posted as a comment to @sleske's answer, but last I recall, comments don't support
I have this in my environment. It'll print 2
<filename> - Lines X-Y of Z at the bottom, or at least as much of that 1 information as it has.
export LESS='-P?f%f - .?ltLine?lbs. %lt?lb-%lb.?L of %L.:?pt%pt\%:?btByte %bt:-...'
More Related questions