|
Ivana Varekova |
f358912 |
#!/bin/sh
|
|
Ivana Varekova |
18956e2 |
#
|
|
Ivana Varekova |
18956e2 |
# To use this filter with less, define LESSOPEN:
|
|
Ivana Varekova |
18956e2 |
# export LESSOPEN="|/usr/bin/lesspipe.sh %s"
|
|
Vojtech Vitek (V-Teq) |
164583b |
#
|
|
Vojtech Vitek (V-Teq) |
27567f0 |
# The script should return zero if the output was valid and non-zero
|
|
Vojtech Vitek (V-Teq) |
27567f0 |
# otherwise, so less could detect even a valid empty output
|
|
Vojtech Vitek (V-Teq) |
27567f0 |
# (for example while uncompressing gzipped empty file).
|
|
Vojtech Vitek (V-Teq) |
27567f0 |
# For backward-compatibility, this is not required by default. To turn
|
|
Vojtech Vitek (V-Teq) |
27567f0 |
# this functionality there should be another vertical bar (|) straight
|
|
Vojtech Vitek (V-Teq) |
27567f0 |
# after the first one in the LESSOPEN environment variable:
|
|
Vojtech Vitek (V-Teq) |
27567f0 |
# export LESSOPEN="||/usr/bin/lesspipe.sh %s"
|
|
Ivana Varekova |
18956e2 |
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
if [ ! -e "$1" ] ; then
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
exit 1
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
fi
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
if [ -d "$1" ] ; then
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
ls -alF -- "$1"
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
exit $?
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
fi
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
exec 2>/dev/null
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
case "$1" in
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.[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)
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
case "$1" in
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.gz) DECOMPRESSOR="gzip -dc" ;;
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.bz2) DECOMPRESSOR="bzip2 -dc" ;;
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.xz|*.lzma) DECOMPRESSOR="xz -dc" ;;
|
|
Ivana Varekova |
18956e2 |
esac
|
|
Vojtech Vitek (V-Teq) |
fc10441 |
if [ -n "$DECOMPRESSOR" ] && $DECOMPRESSOR -- "$1" | file - | grep -q troff; then
|
|
Vojtech Vitek (V-Teq) |
fc10441 |
$DECOMPRESSOR -- "$1" | man -l - | cat -s
|
|
Vojtech Vitek (V-Teq) |
fc10441 |
exit $?
|
|
Vojtech Vitek (V-Teq) |
fc10441 |
fi ;;&
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.[1-9n]|*.[1-9]x|*.man)
|
|
Vojtech Vitek (V-Teq) |
fc10441 |
if file "$1" | grep -q troff; then
|
|
Vojtech Vitek (V-Teq) |
fc10441 |
man -l "$1" | cat -s
|
|
Vojtech Vitek (V-Teq) |
fc10441 |
exit $?
|
|
Vojtech Vitek (V-Teq) |
fc10441 |
fi ;;&
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.tar) tar tvvf "$1" ;;
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.tgz|*.tar.gz|*.tar.[zZ]) tar tzvvf "$1" ;;
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.tar.xz) tar Jtvvf "$1" ;;
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.xz|*.lzma) xz -dc -- "$1" ;;
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.tar.bz2|*.tbz2) bzip2 -dc -- "$1" | tar tvvf - ;;
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.[zZ]|*.gz) gzip -dc -- "$1" ;;
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.bz2) bzip2 -dc -- "$1" ;;
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.zip|*.jar|*.nbm) zipinfo -- "$1" ;;
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.rpm) rpm -qpivl --changelog -- "$1" ;;
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.cpi|*.cpio) cpio -itv < "$1" ;;
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*.gif|*.jpeg|*.jpg|*.pcd|*.png|*.tga|*.tiff|*.tif)
|
|
Vojtech Vitek (V-Teq) |
164583b |
if [ -x /usr/bin/identify ]; then
|
|
Vojtech Vitek (V-Teq) |
164583b |
identify "$1"
|
|
Vojtech Vitek (V-Teq) |
164583b |
elif [ -x /usr/bin/gm ]; then
|
|
Vojtech Vitek (V-Teq) |
164583b |
gm identify "$1"
|
|
Vojtech Vitek (V-Teq) |
164583b |
else
|
|
Vojtech Vitek (V-Teq) |
164583b |
echo "No identify available"
|
|
Vojtech Vitek (V-Teq) |
164583b |
echo "Install ImageMagick or GraphicsMagick to browse images"
|
|
Vojtech Vitek (V-Teq) |
a65fb06 |
exit 1
|
|
Vojtech Vitek (V-Teq) |
164583b |
fi ;;
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
*)
|
|
Vojtech Vitek (V-Teq) |
a65fb06 |
if [ -x /usr/bin/file -a -x /usr/bin/iconv -a -x /usr/bin/cut ]; then
|
|
Vojtech Vitek (V-Teq) |
a65fb06 |
case `file "$1"` in
|
|
Vojtech Vitek (V-Teq) |
a65fb06 |
*UTF-16*) conv='UTF-16' ;;
|
|
Vojtech Vitek (V-Teq) |
a65fb06 |
*UTF-32*) conv='UTF-32' ;;
|
|
Vojtech Vitek (V-Teq) |
a65fb06 |
esac
|
|
Vojtech Vitek (V-Teq) |
a65fb06 |
env=`echo $LANG | cut -d. -f2`
|
|
Vojtech Vitek (V-Teq) |
a65fb06 |
if [ -n "$conv" -a -n "$env" -a "$conv" != "$env" ]; then
|
|
Vojtech Vitek (V-Teq) |
a65fb06 |
iconv -f $conv -t $env "$1"
|
|
Vojtech Vitek (V-Teq) |
a65fb06 |
exit $?
|
|
Vojtech Vitek (V-Teq) |
a65fb06 |
fi
|
|
Vojtech Vitek (V-Teq) |
a65fb06 |
fi
|
|
Vojtech Vitek (V-Teq) |
164583b |
exit 1
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
esac
|
|
Vojtech Vitek (V-Teq) |
f9e095f |
exit $?
|
|
Vojtech Vitek (V-Teq) |
164583b |
|