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
Jozef Mlich db9a82f
	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"
Jozef Mlich db9a82f
	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
de1ff32
# Allow for user defined filters
de1ff32
if [ -x ~/.lessfilter ]; then
de1ff32
	~/.lessfilter "$1"
de1ff32
	if [ $? -eq 0 ]; then
Jozef Mlich db9a82f
		exit 0
de1ff32
	fi
de1ff32
fi
de1ff32
6dde17a
manfilter ()
6dde17a
{
6dde17a
	if test -x /usr/bin/man ; then
6dde17a
		# See rhbz#1241543 for more info.  Well, actually we firstly
6dde17a
		# used 'man -l', then we switched to groff, and then we again
6dde17a
		# switched back to 'man -l'.
6dde17a
		/usr/bin/man -P /usr/bin/cat -l "$1"
6dde17a
	elif test -x /usr/bin/groff; then
6dde17a
		# This is from pre-rhbz#1241543-time.
6dde17a
		groff -Tascii -mandoc "$1" | cat -s
6dde17a
	else
6dde17a
		echo "WARNING:"
6dde17a
		echo "WARNING: to better show manual pages, install 'man-db' package"
6dde17a
		echo "WARNING:"
6dde17a
		cat "$1"
6dde17a
	fi
6dde17a
}
6dde17a
Viktor Jancik 09eadae
export MAN_KEEP_FORMATTING=1
Viktor Jancik 09eadae
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
6dde17a
		$DECOMPRESSOR -- "$1" | manfilter -
Jozef Mlich db9a82f
		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
6dde17a
		manfilter "$1"
Jozef Mlich db9a82f
		exit $?
Vojtech Vitek (V-Teq) fc10441
	fi ;;&
Jozef Mlich db9a82f
*.tar) tar tvvf "$1"; exit $? ;;
Jozef Mlich db9a82f
*.tgz|*.tar.gz|*.tar.[zZ]) tar tzvvf "$1"; exit $? ;;
Jozef Mlich db9a82f
*.tar.xz) tar Jtvvf "$1"; exit $? ;;
Jozef Mlich db9a82f
*.xz|*.lzma) xz -dc -- "$1"; exit $? ;;
Jozef Mlich db9a82f
*.tar.bz2|*.tbz2) bzip2 -dc -- "$1" | tar tvvf -; exit $? ;;
Jozef Mlich db9a82f
*.[zZ]|*.gz) gzip -dc -- "$1"; exit $? ;;
Jozef Mlich db9a82f
*.bz2) bzip2 -dc -- "$1"; exit $? ;;
Jozef Mlich db9a82f
*.zip|*.jar|*.nbm) zipinfo -- "$1"; exit $? ;;
Jozef Mlich db9a82f
*.rpm) rpm -qpivl --changelog -- "$1"; exit $? ;;
Jozef Mlich db9a82f
*.cpi|*.cpio) cpio -itv < "$1"; exit $? ;;
Jozef Mlich db9a82f
*.gpg) gpg -d "$1"; exit $? ;;
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"
Jozef Mlich db9a82f
		exit $?
Vojtech Vitek (V-Teq) 164583b
	elif [ -x /usr/bin/gm ]; then
Vojtech Vitek (V-Teq) 164583b
		gm identify "$1"
Jozef Mlich db9a82f
		exit $?
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"
Jozef Mlich db9a82f
		exit 1
Vojtech Vitek (V-Teq) 164583b
	fi ;;
Vojtech Vitek (V-Teq) f9e095f
*)
Vojtech Vitek (V-Teq) 0758dba
	if [ -x /usr/bin/file ] && [ -x /usr/bin/iconv ] && [ -x /usr/bin/cut ]; then
Vojtech Vitek (V-Teq) a01bfbd
		case `file -b "$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) 0758dba
		if [ -n "$conv" ]; then
Vojtech Vitek (V-Teq) 0758dba
			env=`echo $LANG | cut -d. -f2`
Vojtech Vitek (V-Teq) 0758dba
			if [ -n "$env" -a "$conv" != "$env" ]; then
Vojtech Vitek (V-Teq) 0758dba
				iconv -f $conv -t $env "$1"
Jozef Mlich db9a82f
				exit $?
Vojtech Vitek (V-Teq) 0758dba
			fi
Vojtech Vitek (V-Teq) a65fb06
		fi
Vojtech Vitek (V-Teq) a65fb06
	fi
Jozef Mlich db9a82f
	exit 1
Vojtech Vitek (V-Teq) f9e095f
esac