3 # To use this filter with less, define LESSOPEN:
4 # export LESSOPEN="|/usr/bin/lesspipe.sh %s"
6 # The script should return zero if the output was valid and non-zero
7 # otherwise, so less could detect even a valid empty output
8 # (for example while uncompressing gzipped empty file).
9 # For backward-compatibility, this is not required by default. To turn
10 # this functionality there should be another vertical bar (|) straight
11 # after the first one in the LESSOPEN environment variable:
12 # export LESSOPEN="||/usr/bin/lesspipe.sh %s"
14 #export LESSOPEN="|/Users/Galaxy/git/toGit/etc/lesspipe.sh %s"
16 if [ ! -e "$1" ] ; then
27 # Allow for user defined filters
28 if [ -x ~
/.lessfilter
]; then
36 *.
[1-9n].bz2|
*.
[1-9]x.bz2|
*.man.bz2|
*.
[1-9n].
[gx
]z|
*.
[1-9]x.
[gx
]z|
*.man.
[gx
]z|
*.
[1-9n].lzma|
*.
[1-9]x.lzma|
*.man.lzma
)
38 *.gz
) DECOMPRESSOR
="gzip -dc" ;;
39 *.bz2
) DECOMPRESSOR
="bzip2 -dc" ;;
40 *.xz|
*.lzma
) DECOMPRESSOR
="xz -dc" ;;
42 if [ -n "$DECOMPRESSOR" ] && $DECOMPRESSOR -- "$1" |
file - |
grep -q troff
; then
43 $DECOMPRESSOR -- "$1" |
groff -Tascii -mandoc -
46 *.
[1-9n]|
*.
[1-9]x|
*.man
)
47 if file "$1" |
grep -q troff
; then
51 *.
tar) tar tvvf
"$1" ;;
52 *.tgz|
*.
tar.gz|
*.
tar.
[zZ
]) tar tzvvf
"$1" ;;
53 *.
tar.xz
) tar Jtvvf
"$1" ;;
54 *.xz|
*.lzma
) xz
-dc -- "$1" ;;
55 *.
tar.bz2|
*.tbz2
) bzip2 -dc -- "$1" |
tar tvvf
- ;;
56 *.
[zZ
]|
*.gz
) gzip -dc -- "$1" ;;
57 *.bz2
) bzip2 -dc -- "$1" ;;
58 *.
zip|
*.jar|
*.nbm
) zipinfo
-- "$1" ;;
59 *.rpm
) rpm
-qpivl --changelog -- "$1" ;;
60 *.cpi|
*.
cpio) cpio -itv < "$1" ;;
62 *.gif|
*.jpeg|
*.jpg|
*.pcd|
*.png|
*.tga|
*.tiff|
*.tif
)
63 if [ -x /usr
/bin
/identify
]; then
65 elif [ -x /usr
/bin
/gm
]; then
68 echo "No identify available"
69 echo "Install ImageMagick or GraphicsMagick to browse images"
73 if [ -x /usr
/bin
/file ] && [ -x /usr
/bin
/iconv ] && [ -x /usr
/bin
/cut
]; then
74 case `file -b "$1"` in
75 *UTF-16
*) conv
='UTF-16' ;;
76 *UTF-32
*) conv
='UTF-32' ;;
78 if [ -n "$conv" ]; then
79 env
=`echo $LANG | cut -d. -f2`
80 if [ -n "$env" -a "$conv" != "$env" ]; then
81 iconv -f $conv -t $env "$1"