Blame SOURCES/lesspipe.sh

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