Blame SOURCES/lesspipe.sh

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