Subject: Bug#3952: Less annoyances

From: Chris Fearnley <[email-masked]>
Date: Sun, 11 Aug 1996 22:01:51 -0400 (EDT)

'Christoph Lameter wrote:'
>
>A wish because of the heavy usage of gzipped files under debian:
>
>- Add functionality for less to automatically recognize a gzipped file
>and view it correctly without having to resort to zless.

I have code for that (or you can use most):

First set some environment variables in .bash_profile or /etc/profile:
export LESSCLOSE="lessclose.sh %s %s" LESSOPEN="lessopen.sh %s"

Then somewhere in $PATH put lessclose.sh and lessopen.sh:
$ cat /usr/local/bin/lessclose.sh 
#!/bin/sh

rm $2
$ cat /usr/local/bin/lessopen.sh 
#!/bin/sh

# When the environment variable LESSOPEN is set to refer to this file
# (e.g., LESSOPEN="lessopen.sh %s"), one can do several interesting
# things with pipes (see less(1) for details).  Namely,
# 1. view any gzipped or compressed file(s) anywhere in the filesystem with
#    the simple command "less filename(s)".  And you can use less' multiple
#    file searching and bookmark facilities on the gzipped files!
# 2. view a list of compressed and uncompressed files from the same
#    command prompt (using all of less' multiple file features).
# 3. "zcat file.gz | less" still works.
 
if [ $1 != "-" ]; then  # $1 = "-" when we are reading standard input
   gzip -t $1 &> /dev/null
   if [ $? -eq 0 ]; then # Is it compressed?
      zcat $1 > /tmp/$$.`basename $1`  # Use basename for files in
      echo /tmp/$$.`basename $1`       #   other directories
   fi
fi
exit 0

-- 
Christopher J. Fearnley            |    Linux/Internet Consulting
[email-masked], [email-masked]       |    UNIX SIG Leader at PACS
http://www.netaxs.com/~cjf         |    (Philadelphia Area Computer Society)
ftp://ftp.netaxs.com/people/cjf    |    Design Science Revolutionary
"Dare to be Naive" -- Bucky Fuller |    Explorer in Universe