2007-06-04 10:53:13 +00:00
|
|
|
#!/bin/sh
|
2007-02-07 12:55:35 +00:00
|
|
|
#
|
|
|
|
# To use this filter with less, define LESSOPEN:
|
|
|
|
# export LESSOPEN="|/usr/bin/lesspipe.sh %s"
|
2010-12-21 17:37:35 +00:00
|
|
|
#
|
2011-02-09 15:59:28 +00:00
|
|
|
# The script should return zero if the output was valid and non-zero
|
|
|
|
# otherwise, so less could detect even a valid empty output
|
|
|
|
# (for example while uncompressing gzipped empty file).
|
|
|
|
# For backward-compatibility, this is not required by default. To turn
|
|
|
|
# this functionality there should be another vertical bar (|) straight
|
|
|
|
# after the first one in the LESSOPEN environment variable:
|
|
|
|
# export LESSOPEN="||/usr/bin/lesspipe.sh %s"
|
2007-02-07 12:55:35 +00:00
|
|
|
|
|
|
|
lesspipe() {
|
|
|
|
case "$1" in
|
2010-04-12 08:16:36 +00:00
|
|
|
*.[1-9n]|*.man|*.[1-9n].bz2|*.man.bz2|*.[1-9].gz|*.[1-9]x.gz|*.man.gz|*.[1-9].xz|*.[1-9]x.xz|*.man.xz)
|
2007-02-07 12:55:35 +00:00
|
|
|
case "$1" in
|
2010-12-21 17:37:35 +00:00
|
|
|
*.gz) DECOMPRESSOR="gzip -dc" ;;
|
|
|
|
*.bz2) DECOMPRESSOR="bzip2 -dc" ;;
|
2007-02-07 12:55:35 +00:00
|
|
|
esac
|
2011-01-03 09:13:36 +00:00
|
|
|
if [ ! -z "$DECOMPRESSOR" ] ; then
|
2010-12-21 17:37:35 +00:00
|
|
|
if $DECOMPRESSOR -- "$1" | file - | grep -q troff; then
|
|
|
|
if echo "$1" | grep -q ^/; then #absolute path
|
|
|
|
man -- "$1" | cat -s
|
|
|
|
else
|
|
|
|
man -- "./$1" | cat -s
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
$DECOMPRESSOR -- "$1"
|
|
|
|
fi
|
2007-02-07 12:55:35 +00:00
|
|
|
else
|
2010-12-21 17:37:35 +00:00
|
|
|
exit 1
|
2007-02-07 12:55:35 +00:00
|
|
|
fi ;;
|
|
|
|
*.tar) tar tvvf "$1" ;;
|
|
|
|
*.tgz|*.tar.gz|*.tar.[zZ]) tar tzvvf "$1" ;;
|
2010-04-12 08:16:36 +00:00
|
|
|
*.tar.xz) tar Jtvvf "$1" ;;
|
|
|
|
*.xz) xz -dc -- "$1" ;;
|
2007-02-07 12:55:35 +00:00
|
|
|
*.tar.bz2|*.tbz2) bzip2 -dc -- "$1" | tar tvvf - ;;
|
|
|
|
*.[zZ]|*.gz) gzip -dc -- "$1" ;;
|
|
|
|
*.bz2) bzip2 -dc -- "$1" ;;
|
2009-03-17 07:44:54 +00:00
|
|
|
*.lzma) lzma -c -d -- "$1" ;;
|
2009-12-14 09:05:26 +00:00
|
|
|
*.zip|*.jar|*.nbm) zipinfo -- "$1" ;;
|
2007-02-07 12:55:35 +00:00
|
|
|
*.rpm) rpm -qpivl --changelog -- "$1" ;;
|
|
|
|
*.cpi|*.cpio) cpio -itv < "$1" ;;
|
|
|
|
*.gif|*.jpeg|*.jpg|*.pcd|*.png|*.tga|*.tiff|*.tif)
|
2010-12-21 17:37:35 +00:00
|
|
|
if [ -x /usr/bin/identify ]; then
|
|
|
|
identify "$1"
|
|
|
|
elif [ -x /usr/bin/gm ]; then
|
|
|
|
gm identify "$1"
|
|
|
|
else
|
|
|
|
echo "No identify available"
|
|
|
|
echo "Install ImageMagick or GraphicsMagick to browse images"
|
|
|
|
fi ;;
|
2007-02-07 12:55:35 +00:00
|
|
|
*)
|
2010-12-21 17:37:35 +00:00
|
|
|
exit 1
|
2007-02-07 12:55:35 +00:00
|
|
|
esac
|
2010-12-21 17:37:35 +00:00
|
|
|
exit $?
|
2007-02-07 12:55:35 +00:00
|
|
|
}
|
|
|
|
|
2010-12-21 17:37:35 +00:00
|
|
|
if [ ! -e "$1" ] ; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2007-02-07 12:55:35 +00:00
|
|
|
if [ -d "$1" ] ; then
|
|
|
|
/bin/ls -alF -- "$1"
|
2010-12-21 17:37:35 +00:00
|
|
|
exit $?
|
2007-02-07 12:55:35 +00:00
|
|
|
else
|
|
|
|
lesspipe "$1" 2> /dev/null
|
|
|
|
fi
|