Blame SOURCES/lesspipe.sh

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