Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: less modifications (was "Re: odd output of "ls --color FILES | less")
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: less modifications (was "Re: odd output of "ls --color FILES | less")



Hello Ken. Yes there was someone asking for a percentage indicator in the "less" prompt and that was me. Thank you oh so very much for your useful contribution, you set me in the right path with your indications and that was exactly what I needed to get what I wanted!! Your indications were amazingly accurate in every way: I don't care about tcsh because I'm a bash lover!

On Friday, December 27, 2002, at 03:24 AM, Ken Engel wrote:

Hi,
Did someone ask for the percent indicator when using less with man pages?
I spent over an hour getting this just right!

I don't know exactly how this would be in (t)csh; quotes are funny animals. But here's
how it will look in bash. Put this in .bashrc:

export LESS=--prompt="%f (%pb\%)"
export PAGER=less

Then the indicator at the bottom will look like this:

/path/to/somewhere/filename (25%)

I did this but afterward I enhanced it a bit:

LESS=--prompt="%f (%pb\%, %lmth line, %L lines)$"
export LESS
PAGER="less -wis"
export PAGER

So now the "less" prompt looks like:

/tmp/man.016488 (24%, 14th line, 90 lines)

I'm going to try to modify man's output to make it print the name of the manual page, instead of the uninformative "man.016488". I guess that has to be done with the "man" command because "less" is just reading from a file which was output by "man"; "less" has no way of knowing who wrote that file. Instead if I get "man" to output to /tmp/rm if I ask for "man rm" then "less" would print "/tpm/rm (<percentage>%, <current-line>th line, <total-lines> lines)" in its prompt. That would be way better! Do any of you listers have any clue or suggestion as how to make this happen? Should I tamper with the "man" command or with any other to get the right file name in /tmp when I ask for a man page?


Now, how to make this work for man pages. Unfortunately, it requires creating a
temp file. This is because man pipes its output to your $PAGER, so less has no way
of knowing the percentage beforehand. I'd be interested if someone has a solution
to that.

It works for man pages, as I just demonstrated in the output of my "less" prompt. The modifications we made make "less" print the current percentage of the file being read, the current line number and the total lines in the file. And this works for man pages because all the "man" command does is write a file, which has been previously formatted through the troff format, to /tmp. So "less" is indeed reading from a file, just as if you issue "less <some-file>; the pipe doesn't go directly to less. Example:

<formating command> /usr/share/man/man1/sh.1 > /tmp/man.xyz | $PAGER /tmp/man.xyz

That said, here's one way to do it; write a script:

#!/bin/bash
# Collect arguments and options
args="$@"
# Assume the last argument is the man page you're looking for and store it.
# (In other words, something like 'man_script ls mv rm' will only work as 'man rm'.)
currman=${args##* }
# Use cat to create a plain text version of the man page.
/usr/bin/man -P cat $@ > /tmp/less.$$
unset LESS
less --prompt="\ %%$currman\ (%pb\\%)" /tmp/less.$$
rm -f /tmp/less.$$
# End man_script


I called it simply 'm'. So, 'm rm' and the indicator will show

rm (27%)

I will give this one a try!


And a Happy New Year to you all!
Ken


And a happy new year to you too! Sincerely,...


Juan.


PS: Do you think you could look into getting man to write to a file of the appropriate name when asked for a specific man page? Thanks, bye!
_______________________________________________
darwinos-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwinos-users
Do not post admin requests to the list. They will be ignored.
References: 
 >Re: odd output of "ls --color FILES | less" (From: Ken Engel <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.