A few more minor tweaks.
[pkgusr] / usr / bin / lesspipe.sh
1 #!/bin/sh
2 #
3 # Copyright 1997, 1998, 1999, 2000  Patrick Volkerding, Moorhead, MN, USA
4 # Copyright 2001, 2002  Slackware Linux, Inc, Concord, CA, USA
5 # Copyright 2006, 2009  Patrick Volkerding, Sebeka, MN, USA
6 # All rights reserved.
7 #
8 # Redistribution and use of this script, with or without modification, is
9 # permitted provided that the following conditions are met:
10 #
11 # 1. Redistributions of this script must retain the above copyright
12 #    notice, this list of conditions and the following disclaimer.
13 #
14 #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 #  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
17 #  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 #  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 #  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 #  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 #  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 #  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 #
25
26 # This is a preprocessor for 'less'.  It is used when this environment
27 # variable is set:   LESSOPEN="|lesspipe.sh %s"
28
29 lesspipe() {
30   case "$1" in
31   *.tar) tar tvvf "$1" 2>/dev/null ;;
32   *.tgz | *.tar.gz | *.tar.Z | *.tar.z | *.tar.bz2 | *.tbz ) tar tvvf "$1" 2>/dev/null ;;
33   *.tlz | *.tar.lzma ) lzma -dc "$1" 2> /dev/null | tar tvvf - 2> /dev/null ;;
34   *.txz | *.tar.xz ) xz -dc "$1" 2> /dev/null | tar tvvf - 2> /dev/null ;;
35   *.zip) unzip -l "$1" 2>/dev/null ;;
36   *.rpm) rpm -qpvl "$1" 2>/dev/null ;;
37   *.rar) # check if rar is installed first
38     if which rar 1> /dev/null ; then
39       `which rar` t "$1" 
40     fi ;;
41   *.1|*.2|*.3|*.4|*.5|*.6|*.7|*.8|*.9|*.n|*.man) # *roff src?
42     if file -L "$1" | grep roff 1> /dev/null ; then
43       nroff -S -mandoc "$1"
44     fi ;;
45   *.1.gz|*.2.gz|*.3.gz|*.4.gz|*.5.gz|*.6.gz|*.7.gz|*.8.gz|*.9.gz|*.n.gz|*.man.gz) # compressed *roff src?
46     if gzip -dc "$1" | file - | grep roff 1> /dev/null ; then
47       gzip -dc "$1" | nroff -S -mandoc -
48     else gzip -dc "$1"  2>/dev/null
49     fi ;;
50   *.1.bz2|*.2.bz2|*.3.bz2|*.4.bz2|*.5.bz2|*.6.bz2|*.7.bz2|*.8.bz2|*.9.bz2|*.n.bz2|*.man.bz2) # compressed *roff src?
51     if bzip2 -dc "$1" | file - | grep roff 1> /dev/null ; then
52       bzip2 -dc "$1" | nroff -S -mandoc -
53     fi ;;
54   *.gz) gzip -dc "$1"  2>/dev/null ;;
55   *.bz2) bzip2 -dc "$1" 2>/dev/null ;;
56   *.lzma) lzma -dc "$1" 2>/dev/null ;;
57   *.xz) xz -dc "$1" 2>/dev/null ;;
58   *) if [ "$(file -li $1|awk -F= '{print $2;}')" = "binary" ]; then
59          # It is a binary, lets use strings
60          strings "$1"
61      fi ;;
62   esac
63 }
64
65 lesspipe "$1"