#!/bin/sh

find_pager () {
	if [ -f /usr/bin/less ]; then
		exec /usr/bin/less $@
	else if [ -f /usr/bin/more ]; then
		exec /usr/bin/more $@
		echo "Error: No pager could be found"
		exit 1
	fi
	fi
}

if [ ! -z "$PAGER" ] ; then
	P=$(which $EDITOR 2>/dev/null)
	if [ -L "$P" ]
	then
		P=$(ls -l $P | awk '{ print $NF }')
                if [[ $T = */sensible-pager ]]
                then
                        find_pager $@
                fi
	fi
	if [ -f $PAGER ] ; then
		exec $PAGER $@
	else if [ -f /usr/bin/$PAGER ] ; then
		exec /usr/bin/$PAGER $@
	else if [ ! -z "`which $PAGER 2> /dev/null`" ] ; then
        	exec `which $PAGER` $@
	else
		echo "Error: Could not find the $PAGER editor specified by eviornment variable PAGER"
		exit 1
	fi
	fi
	fi

else
	find_pager $@
fi 
	 
