| 1 |
From the man page: |
| 2 |
You may define an "input preprocessor" for less. Before |
| 3 |
less opens a file, it first gives your input preprocessor |
| 4 |
a chance to modify the way the contents of the file are |
| 5 |
displayed. |
| 6 |
|
| 7 |
What this means is that less(1) can automatically open up tar files, |
| 8 |
uncompress gzipped files, and even display something reasonable for |
| 9 |
graphics files. |
| 10 |
|
| 11 |
You just need to put the following in your |
| 12 |
.zlogin/.login/.bash_profile/whatever: |
| 13 |
|
| 14 |
eval $(lesspipe) |
| 15 |
or |
| 16 |
eval $(lessfile) |
| 17 |
|
| 18 |
lesspipe will toss the contents/info on stdout and less will read them |
| 19 |
as they come across. This means that you don't have to wait for the |
| 20 |
decoding to finish before less shows you the file. This also means that |
| 21 |
you'll get a 'byte N' instead of an N% as your file position. You can |
| 22 |
seek to the end and back to get the N% but that means you have to wait |
| 23 |
for the pipe to finish. |
| 24 |
|
| 25 |
lessfile will toss the contents/info on a file which less will then |
| 26 |
read. After you're done, lessfile will then delete the file. This |
| 27 |
means that the process has to finish before you see it, but you get nice |
| 28 |
percentages (N%) up front. |
| 29 |
|
| 30 |
If you have some additional tests for binary files that I don't handle, go |
| 31 |
ahead and send them to me. Note that I will never integrate commands |
| 32 |
for text files. If you want to add man-ifying or html-izing commands to |
| 33 |
your copy of lesspipe, go ahead, they just won't be integrated in the |
| 34 |
main distribution. |
| 35 |
|
| 36 |
Here are two additional tests that you might like to use but aren't in |
| 37 |
the lesspipe script due to speed or principle of least surprise. |
| 38 |
|
| 39 |
# Decode directories: |
| 40 |
if [ -d "$1" ]; then |
| 41 |
echo "$1:"; ls -l $1 |
| 42 |
else |
| 43 |
|
| 44 |
# view strings inside of an executable |
| 45 |
if [ -x "$1" ]; then |
| 46 |
type=$(file "$1") |
| 47 |
case "$type" in |
| 48 |
*executable* ) |
| 49 |
echo -e "$type\n" |
| 50 |
strings "$1" |
| 51 |
;; |
| 52 |
esac |
| 53 |
fi |
| 54 |
|
| 55 |
These two entries courtesy of Adrian Bridgett <[email protected]>. |
| 56 |
Please send in your entries as well. |
| 57 |
|
| 58 |
If you have any questions, send me e-mail at <[email protected]>. |
| 59 |
Mentioning less in the subject line will help. |