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
|
|
|
|
2011-02-15 11:02:37 +00:00
|
|
|
if [ ! -e "$1" ] ; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d "$1" ] ; then
|
|
|
|
ls -alF -- "$1"
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
exec 2>/dev/null
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
*.[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)
|
|
|
|
case "$1" in
|
|
|
|
*.gz) DECOMPRESSOR="gzip -dc" ;;
|
|
|
|
*.bz2) DECOMPRESSOR="bzip2 -dc" ;;
|
|
|
|
*.xz|*.lzma) DECOMPRESSOR="xz -dc" ;;
|
2007-02-07 12:55:35 +00:00
|
|
|
esac
|
2011-02-14 21:20:13 +00:00
|
|
|
if [ -n "$DECOMPRESSOR" ] && $DECOMPRESSOR -- "$1" | file - | grep -q troff; then
|
2011-11-22 16:52:58 +00:00
|
|
|
$DECOMPRESSOR -- "$1" | groff -Tascii -mandoc -
|
2011-02-14 21:20:13 +00:00
|
|
|
exit $?
|
|
|
|
fi ;;&
|
2011-02-15 11:02:37 +00:00
|
|
|
*.[1-9n]|*.[1-9]x|*.man)
|
2011-02-14 21:20:13 +00:00
|
|
|
if file "$1" | grep -q troff; then
|
|
|
|
man -l "$1" | cat -s
|
|
|
|
exit $?
|
|
|
|
fi ;;&
|
2011-02-15 11:02:37 +00:00
|
|
|
*.tar) tar tvvf "$1" ;;
|
|
|
|
*.tgz|*.tar.gz|*.tar.[zZ]) tar tzvvf "$1" ;;
|
|
|
|
*.tar.xz) tar Jtvvf "$1" ;;
|
|
|
|
*.xz|*.lzma) xz -dc -- "$1" ;;
|
|
|
|
*.tar.bz2|*.tbz2) bzip2 -dc -- "$1" | tar tvvf - ;;
|
|
|
|
*.[zZ]|*.gz) gzip -dc -- "$1" ;;
|
|
|
|
*.bz2) bzip2 -dc -- "$1" ;;
|
|
|
|
*.zip|*.jar|*.nbm) zipinfo -- "$1" ;;
|
|
|
|
*.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"
|
2011-02-14 16:01:44 +00:00
|
|
|
exit 1
|
2010-12-21 17:37:35 +00:00
|
|
|
fi ;;
|
2011-02-15 11:02:37 +00:00
|
|
|
*)
|
2011-11-22 17:17:36 +00:00
|
|
|
if [ -x /usr/bin/file ] && [ -x /usr/bin/iconv ] && [ -x /usr/bin/cut ]; then
|
2011-04-13 14:00:15 +00:00
|
|
|
case `file -b "$1"` in
|
2011-02-14 16:01:44 +00:00
|
|
|
*UTF-16*) conv='UTF-16' ;;
|
|
|
|
*UTF-32*) conv='UTF-32' ;;
|
|
|
|
esac
|
2011-11-22 17:17:36 +00:00
|
|
|
if [ -n "$conv" ]; then
|
|
|
|
env=`echo $LANG | cut -d. -f2`
|
|
|
|
if [ -n "$env" -a "$conv" != "$env" ]; then
|
|
|
|
iconv -f $conv -t $env "$1"
|
|
|
|
exit $?
|
|
|
|
fi
|
2011-02-14 16:01:44 +00:00
|
|
|
fi
|
|
|
|
fi
|
2010-12-21 17:37:35 +00:00
|
|
|
exit 1
|
2011-02-15 11:02:37 +00:00
|
|
|
esac
|
|
|
|
exit $?
|
2010-12-21 17:37:35 +00:00
|
|
|
|