|
|
7003aa |
#!/bin/sh
|
|
|
7003aa |
#
|
|
|
7003aa |
# To use this filter with less, define LESSOPEN:
|
|
|
7003aa |
# export LESSOPEN="|/usr/bin/lesspipe.sh %s"
|
|
|
7003aa |
#
|
|
|
7003aa |
# The script should return zero if the output was valid and non-zero
|
|
|
7003aa |
# otherwise, so less could detect even a valid empty output
|
|
|
7003aa |
# (for example while uncompressing gzipped empty file).
|
|
|
7003aa |
# For backward-compatibility, this is not required by default. To turn
|
|
|
7003aa |
# this functionality there should be another vertical bar (|) straight
|
|
|
7003aa |
# after the first one in the LESSOPEN environment variable:
|
|
|
7003aa |
# export LESSOPEN="||/usr/bin/lesspipe.sh %s"
|
|
|
7003aa |
|
|
|
7003aa |
if [ ! -e "$1" ] ; then
|
|
|
7003aa |
exit 1
|
|
|
7003aa |
fi
|
|
|
7003aa |
|
|
|
7003aa |
if [ -d "$1" ] ; then
|
|
|
7003aa |
ls -alF -- "$1"
|
|
|
7003aa |
exit $?
|
|
|
7003aa |
fi
|
|
|
7003aa |
|
|
|
7003aa |
exec 2>/dev/null
|
|
|
7003aa |
|
|
|
7003aa |
# Allow for user defined filters
|
|
|
7003aa |
if [ -x ~/.lessfilter ]; then
|
|
|
7003aa |
~/.lessfilter "$1"
|
|
|
7003aa |
if [ $? -eq 0 ]; then
|
|
|
7003aa |
exit 0
|
|
|
7003aa |
fi
|
|
|
7003aa |
fi
|
|
|
7003aa |
|
|
|
7003aa |
manfilter ()
|
|
|
7003aa |
{
|
|
|
7003aa |
if test -x /usr/bin/man ; then
|
|
|
7003aa |
# See rhbz#1241543 for more info. Well, actually we firstly
|
|
|
7003aa |
# used 'man -l', then we switched to groff, and then we again
|
|
|
7003aa |
# switched back to 'man -l'.
|
|
|
7003aa |
/usr/bin/man -P /usr/bin/cat -l "$1"
|
|
|
7003aa |
elif test -x /usr/bin/groff; then
|
|
|
7003aa |
# This is from pre-rhbz#1241543-time.
|
|
|
7003aa |
groff -Tascii -mandoc "$1" | cat -s
|
|
|
7003aa |
else
|
|
|
7003aa |
echo "WARNING:"
|
|
|
7003aa |
echo "WARNING: to better show manual pages, install 'man-db' package"
|
|
|
7003aa |
echo "WARNING:"
|
|
|
7003aa |
cat "$1"
|
|
|
7003aa |
fi
|
|
|
7003aa |
}
|
|
|
7003aa |
|
|
|
7003aa |
export MAN_KEEP_FORMATTING=1
|
|
|
7003aa |
|
|
|
7003aa |
case "$1" in
|
|
|
7003aa |
*.[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)
|
|
|
7003aa |
case "$1" in
|
|
|
7003aa |
*.gz) DECOMPRESSOR="gzip -dc" ;;
|
|
|
7003aa |
*.bz2) DECOMPRESSOR="bzip2 -dc" ;;
|
|
|
7003aa |
*.xz|*.lzma) DECOMPRESSOR="xz -dc" ;;
|
|
|
7003aa |
esac
|
|
|
7003aa |
if [ -n "$DECOMPRESSOR" ] && $DECOMPRESSOR -- "$1" | file - | grep -q troff; then
|
|
|
7003aa |
$DECOMPRESSOR -- "$1" | manfilter -
|
|
|
7003aa |
exit $?
|
|
|
7003aa |
fi ;;&
|
|
|
7003aa |
*.[1-9n]|*.[1-9]x|*.man)
|
|
|
7003aa |
if file "$1" | grep -q troff; then
|
|
|
7003aa |
manfilter "$1"
|
|
|
7003aa |
exit $?
|
|
|
7003aa |
fi ;;&
|
|
|
7003aa |
*.tar) tar tvvf "$1"; exit $? ;;
|
|
|
7003aa |
*.tgz|*.tar.gz|*.tar.[zZ]) tar tzvvf "$1"; exit $? ;;
|
|
|
7003aa |
*.tar.xz) tar Jtvvf "$1"; exit $? ;;
|
|
|
7003aa |
*.xz|*.lzma) xz -dc -- "$1"; exit $? ;;
|
|
|
7003aa |
*.tar.bz2|*.tbz2) bzip2 -dc -- "$1" | tar tvvf -; exit $? ;;
|
|
|
7003aa |
*.[zZ]|*.gz) gzip -dc -- "$1"; exit $? ;;
|
|
|
7003aa |
*.bz2) bzip2 -dc -- "$1"; exit $? ;;
|
|
|
7003aa |
*.zip|*.jar|*.nbm) zipinfo -- "$1"; exit $? ;;
|
|
|
7003aa |
# --nomanifest -> rhbz#1450277
|
|
|
7003aa |
*.rpm) rpm -qpivl --changelog --nomanifest -- "$1"; exit $? ;;
|
|
|
7003aa |
*.cpi|*.cpio) cpio -itv < "$1"; exit $? ;;
|
|
|
7003aa |
*.gpg)
|
|
|
7003aa |
if [ -x /usr/bin/gpg2 ]; then
|
|
|
7003aa |
gpg2 -d "$1"
|
|
|
7003aa |
exit $?
|
|
|
7003aa |
elif [ -x /usr/bin/gpg ]; then
|
|
|
7003aa |
gpg -d "$1"
|
|
|
7003aa |
exit $?
|
|
|
7003aa |
else
|
|
|
7003aa |
echo "No GnuPG available."
|
|
|
7003aa |
echo "Install gnupg2 or gnupg to show encrypted files."
|
|
|
7003aa |
exit 1
|
|
|
7003aa |
fi ;;
|
|
|
7003aa |
*.gif|*.jpeg|*.jpg|*.pcd|*.png|*.tga|*.tiff|*.tif)
|
|
|
7003aa |
if [ -x /usr/bin/identify ]; then
|
|
|
7003aa |
identify "$1"
|
|
|
7003aa |
exit $?
|
|
|
7003aa |
elif [ -x /usr/bin/gm ]; then
|
|
|
7003aa |
gm identify "$1"
|
|
|
7003aa |
exit $?
|
|
|
7003aa |
else
|
|
|
7003aa |
echo "No identify available"
|
|
|
7003aa |
echo "Install ImageMagick or GraphicsMagick to browse images"
|
|
|
7003aa |
exit 1
|
|
|
7003aa |
fi ;;
|
|
|
7003aa |
*)
|
|
|
7003aa |
if [ -x /usr/bin/file ] && [ -x /usr/bin/iconv ] && [ -x /usr/bin/cut ]; then
|
|
|
7003aa |
case `file -b "$1"` in
|
|
|
7003aa |
*UTF-16*) conv='UTF-16' ;;
|
|
|
7003aa |
*UTF-32*) conv='UTF-32' ;;
|
|
|
7003aa |
esac
|
|
|
7003aa |
if [ -n "$conv" ]; then
|
|
|
7003aa |
env=`echo $LANG | cut -d. -f2`
|
|
|
7003aa |
if [ -n "$env" -a "$conv" != "$env" ]; then
|
|
|
7003aa |
iconv -f $conv -t $env "$1"
|
|
|
7003aa |
exit $?
|
|
|
7003aa |
fi
|
|
|
7003aa |
fi
|
|
|
7003aa |
fi
|
|
|
7003aa |
exit 1
|
|
|
7003aa |
esac
|