Since bzless calls less for the actual paging, its help screen is the
same as that of less. So it should provide the same features. But since
this time less is called always with a standard input, it behaves
slightly differrently:
E.g., it cannot print the current filename, the '=' command doesn't work.
I think less should be used here with the LESSOPEN variable. (The same
is true for zless/zmore.)
I use the following version:
#!/bin/sh
# Bzmore wrapped for bzip2,
# adapted from zmore by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
PATH="/usr/bin:$PATH"; export PATH
export LESSOPEN="|bzip2 -cdfq %s"
prog=`echo $0 | sed 's|.*/||'`
if test "`echo -n a`" = "-n a"; then
# looks like a SysV system:
n1=''; n2='\c'
else
n1='-n'; n2=''
fi
oldtty=`stty -g 2>/dev/null`
if stty -cbreak 2>/dev/null; then
cb='cbreak'; ncb='-cbreak'
else
# 'stty min 1' resets eof to ^a on both SunOS and SysV!
cb='min 1 -icanon'; ncb='icanon eof ^d'
fi
if test $? -eq 0 -a -n "$oldtty"; then
trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15
else
trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15
fi
if test $# = 0; then
if test -t 0; then
echo usage: $prog files...
else
case "$prog" in
*less) less ;;
*) bzip2 -cdfq | more ;;
esac
fi
else
FIRST=1
for FILE
do
if test $FIRST -eq 0; then
echo $n1 "--More--(Next file: $FILE)$n2"
stty $cb -echo 2>/dev/null
ANS=`dd bs=1 count=1 2>/dev/null`
stty $ncb echo 2>/dev/null
echo " "
if test "$ANS" = 'e' -o "$ANS" = 'q'; then
exit
fi
fi
if test "$ANS" != 's'; then
echo "------> $FILE <------"
case "$prog" in
*less) less "$FILE" ;;
*) bzip2 -cdfq "$FILE" | more ;;
esac
fi
if test -t; then
FIRST=0
fi
done
fi
antos@MAST.queensu.ca writes:
8< snip >8
Your script can be summarized into this (simplier) script:
#!/bin/sh
PATH="/usr/bin:$PATH"; export PATH
LESSOPEN="|bzip2 -cdfq %s"; export LESSOPEN
exec less "$@"
The problem is that the user might already have LESSOPEN defined. I do
not think using LESSOPEN is a good idea because it will interfere with
the user's LESSOPEN, which might do other things than uncompressing
the file.
Why don't you use this in the first place:
#!/bin/sh
case "$1" in
*.Z|*.gz) exec gzip -cdf "$1" ;;
*.bz2) exec bzip2 -cdf "$1" ;;
*) exec cat "$1" ;;
esac
and not use zless/bzless at all?
Phil.
Yes, I just wanted to keep the generality of the original script. I see. This is a problem. But this idea is in less' man page. Perhaps LESSOPEN could be used at least when it was empty/unset ? Another problem with these scripts is that LESSOPEN is not effective when viewing standard input. Do you mean instead of cat, and then piping it into 'less' ? Because my problem is just that I would like to use 'less' and its features like '=' '(to print the filename), which does not work if 'less' displays the stdin instead of file(s). So it was quite disappointing when bzless did not behave as its (actually less') help documentation. Andras
We've been using zless for years which overrides LESSOPEN, so what's wrong with doing the identical thing in bzless? If you haven't personally overridden LESSOPEN yourself, then it makes sense to use bzless. If it makes sense to use bzless, then why would you care if bzless overrides LESSOPEN? FWIW, on my own systems, I just copied zless, changed "gzip" to "bzip2" and was happy. It works. Less behaves like less always behaves. Supply multiple files on the commandline, and you can view them all with ":n" and ":p" which you can't do with the normal bzless.
version 124098 1.0.5-3 thanks $ less +/a /etc/motd #works fine $ zless +/a /etc/motd #works fine $ bzless +/a /etc/motd ------> +/a <------ bzip2: Can't open input file +/a: No such file or directory.