[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#8111: less package doesn't include LESSOPEN support (was Re: Warning!! PAGER=zless)



'Craig Sanders wrote:'
>
>Package: less
>Version: 321-2
>
>1.  set the environment variable LESSOPEN in your ~/.bashrc or in
>    /etc/profile (modify as required if you use csh or zsh or something
>    else).
>
>        export LESSOPEN="|lesspipe.sh  %s"
>
>
>2.  create a shell script called lesspipe.sh in /usr/local/bin.
>
>        #!/bin/sh
>
>        case "$1" in
>            *.tar) tar tvf $1  2>/dev/null ;;
>            *.tar.Z) tar tvfz $1  2>/dev/null ;;
>            *.tar.gz) tar tvfz $1  2>/dev/null ;;
>            *.Z) zcat $1  2>/dev/null ;;
>            *.gz) zcat  -c $1  2>/dev/null ;;
>            *.deb) dpkg -I $1 ; dpkg -c $1  2>/dev/null ;;
>        esac
>
>this can be extended to cover many more file types. 
>
>Note that the order of the case statements is important...e.g. if you
>don't have 'tar' before 'gz' then the gz line will "catch" .tar.gz files
>and you wont get a listing.

I'm not sure about this design.  There could exist gzip files that
don't have .gz endings and so on.  I think a better approach is to use
file(1) (and gzip?) to do this.  And I sometimes like to pipe .gz files
into less.  Another bug in your script is that it doesn't support
uncompressing multiple files and saving marks in each of them and
hoping back and forth easily.  Maybe someone can merge your approach
with mine :) Maybe the less maintainer is getting into trouble
accepting the job of adding this enhancement.  Might I suggest putting
some examples in /usr/doc/less?

BTW, you don't need the | in your ENV variables.

$ grep LESS ~/.bash_profile
export LESSCLOSE="lessclose.sh %s %s" LESSOPEN="lessopen.sh %s"
$ cat `which lessopen.sh`
#!/bin/sh -eC

# 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
$ cat `which lessclose.sh`
#!/bin/sh

rm $2


-- 
Christopher J. Fearnley          |  Linux/Internet Consulting
cjf@netaxs.com, cjf@onit.net     |  Design Science Revolutionary
http://www.netaxs.com/~cjf       |  Explorer in Universe
ftp://ftp.netaxs.com/people/cjf  |  "Dare to be Naive" -- Bucky Fuller


Reply to: