From: jim@jagubox.gsfc.nasa.gov (Jim Jagielski)
Subject: Re: ksh man and PAGER ?
Reply-To: jim@jagubox.gsfc.nasa.gov (Jim Jagielski)
Organization: NASA/Goddard Space Flight Center
Distribution: na
Date: Fri, 31 Jul 1992 13:23:00 GMT

weinhous@RadOnc.Duke.EDU (Marty Weinhous (guest)) writes:

>I recently (1) switched to ksh and (2) installed "less" (v 170) from
>jagubox (thanks Jim).

>Now I would like "man" to use "less" rather than "more". I tried setting
>PAGER to /usr/local/bin/less, but got scrambled man pages (lots of
>escape characters rather than bolds, etc.). Attempts to fix this by
>setting TERM to vt100 caused a chane in appearance, but not a fix.

>Would someone please tell me how to use "less" as the default pager
>for "man"? As always, thanks in advance.

>- Marty

Here's the complete source for the hacked /usr/bin/man:

--------->8 cut here--------------
#!/bin/sh
:
: man
:
#	@(#)Copyright Apple Computer 1987	Version 1.7 of man.sh on 91/12/16 20:04:46 (ATT 1.1)
#	Catable manual entries printer
#

BASE=/usr

sec=\?
dir=
col=
cmd=
entries=
TTERM=
mypager=

if [ "$PAGER" = "" ]
then
	mypager="/usr/local/bin/less -s -M -e"
else
	# pages such as pg need to have ul handle underlining
	mypager="ul | $PAGER"
fi

if [ ! -t 1 ] ; then	# If stdout is not a tty skip the pager
	mypager=cat
fi

#  parse options

for i in $*
do case $i in

	[1-8])	sec=$i ;;
	-c)	col=col ;;
	-d)	dir=. ;;
	-w)	cmd=w ;;
	-T*)	TERM="`echo $i | sed 's/-T//'`" ;;
	-12)	TTERM=-12 ;;
	*)	entries="$entries $i" ;;
   esac
done


#  now find the named entries

# Only need to truncate to 14 chars for System V file system.
# / is now a Berkeley file system, so we only truncate when we
# are not can't find the requested file.

for i in $entries; do

    if [ "$dir" = "." ]; then
	if [ ! -r "$i" ]; then
	    ti=`expr $i : '^\(..............\).*' '|' $i`
	    if [ ! -r "$ti" ]; then
		echo $0: $i not found >&2
		exit 1
	    else
		all="$all $ti"
	    fi
	else 
	    all="$all $i"
	fi

    else
	cd $BASE/catman
	fil="`find */man$sec/$i.* -print 2>/dev/null`"
	if [ -n "$fil" ]; then
	    all="$all $fil"
	else
	    fil="`find */man$sec/$i -print 2>/dev/null`"
	    if [ -n "$fil" ]; then
		all="$all $fil"
	    else
		ti=`expr $i : '^\(..............\).*' '|' $i`
		fil="`find */man$sec/$ti -print 2>/dev/null`"
		if [ -n "$fil" ]; then
		    all="$all $fil"
		else
		    echo $0: $i not found >&2
		    exit 1
		fi
	    fi
	fi
    fi
done


# fix up the terminal type option (make sure to use col, etc.)

case "$TERM$TTERM" in

	300|300s|450|37|300-12|300s-12|450-12| \
		4000a|4000A|382|1620|1620-12)	post="greek -T$TERM$TTERM" ;;
	hp|2621|2645|2640)	col=col; post="greek -T$TERM$TTERM" ;;
	4014|tek)	post="greek -T$TERM$TTERM" ;;
	X97)		col=col; post=xerox ;;
	*)		col=col; post=cat ;;
esac

if [ "$col" != "" ]
   then post="$col | $post"
fi


# now print the pages
# First export TERM, which you need to do if you use -T
export TERM

if [ "$cmd" = "w" ]

   then	echo $all
	exit 0

   else	for i in $all

	do case $i in

		*.z)	eval "pcat $i | $post | $mypager" ;;
		*.Z)	eval "zcat $i | $post | $mypager" ;;
		*)	eval "cat $i | $post | $mypager" ;;

	   esac
	done

fi
--------->8 cut here--------------
-- 
==============================================================================
#include <std/disclaimer.h>

                Jim Jagielski                  NASA/GSFC, Code 734.4
          jim@jagubox.gsfc.nasa.gov             Greenbelt, MD 20771

           "The great scallop... this tatty, scrofulous old rapist,
               is second in depravity only to the common clam."
Newsgroups: comp.unix.aux