modified: spffq.py
[GalaxyCodeBases.git] / etc / lesspipe.sh
blobbb5fcc209c15a670bcb182b466216a3844820bc1
1 #!/bin/sh
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
17 exit 1
20 if [ -d "$1" ] ; then
21 ls -alF -- "$1"
22 exit $?
25 exec 2>/dev/null
27 # Allow for user defined filters
28 if [ -x ~/.lessfilter ]; then
29 ~/.lessfilter "$1"
30 if [ $? -eq 0 ]; then
31 exit 0
35 case "$1" in
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)
37 case "$1" in
38 *.gz) DECOMPRESSOR="gzip -dc" ;;
39 *.bz2) DECOMPRESSOR="bzip2 -dc" ;;
40 *.xz|*.lzma) DECOMPRESSOR="xz -dc" ;;
41 esac
42 if [ -n "$DECOMPRESSOR" ] && $DECOMPRESSOR -- "$1" | file - | grep -q troff; then
43 $DECOMPRESSOR -- "$1" | groff -Tascii -mandoc -
44 exit $?
45 fi ;;
46 *.[1-9n]|*.[1-9]x|*.man)
47 if file "$1" | grep -q troff; then
48 man -l "$1" | cat -s
49 exit $?
50 fi ;;
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" ;;
61 *.gpg) gpg -d "$1" ;;
62 *.gif|*.jpeg|*.jpg|*.pcd|*.png|*.tga|*.tiff|*.tif)
63 if [ -x /usr/bin/identify ]; then
64 identify "$1"
65 elif [ -x /usr/bin/gm ]; then
66 gm identify "$1"
67 else
68 echo "No identify available"
69 echo "Install ImageMagick or GraphicsMagick to browse images"
70 exit 1
71 fi ;;
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' ;;
77 esac
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"
82 exit $?
86 exit 1
87 esac
88 exit $?