#! /bin/bash
DefPager=/local/bin/less
istrue()
{
test 0 -ne "$1"
}
warn()
{
echo "$@" 1>&2
}
if [ "$1" = -h ]; then
echo \
"$0: page a file.
Usage: $0 [pager-option ...] [filename ...]
Files are paged by the program specified in the user's PAGER
environment variable, or by $DefPager if PAGER is not set.
If no filename is given, text to page is read from the standard input.
If filenames are given, they are either paged directly, or unpacked/
uncompressed and then paged. Files are assumed to be in packed, compressed,
or gzipped format if the filename ends in .Z, .z, or .gz respectively.
If a filename that does not end in .Z, .z, or .gz is not found, it is
searched for with one of those extensions attached.
Each group of plain files is paged by a single instance of the pager.
Each packed or compressed file is paged by a separate instance of the
pager.
Initial arguments beginning with + or - are taken to be pager options and
are passed to each instance of the pager.
If a pager option takes a value it should be given with the option as a
single argument (with no space between the option and the value)."
exit 0
fi
while [ $ case "$1" in
-*|+*) Opts="$Opts $1" ; shift;;
*) break;;
esac
done
[ -z "$PAGER" ] && PAGER=$DefPager
[ $
typeset -i filenum=0 badfile=0
for file; do
if [ ! -r "$file" ]; then
case "$file" in
*.[Zz]|*.gz)
for ext in Z z gz; do
if [ -r "$file.$ext" ]; then
file="$file.$ext"
break
fi
done;;
esac
fi
if [ ! -r "$file" ]; then
warn "$file: cannot read."
badfile=1
else
files[filenum]=$file
let filenum+=1
fi
done
if istrue $badfile && [ $filenum -gt 0 ]; then
echo -n "Press return to continue..." 1>&2
read
fi
unset plain
for file in "${files[@]}"; do
case "$file" in
*.[zZ]|*.gz)
set -- Z zcat z pcat gz gzcat
while [ $ case "$file" in
*.$1)
[ ${ unset plain[*]
case "$PAGER" in
*less) Prompt="-P[${file%.$1}\\.$1] (%pb\\%)" ;;
*) unset Prompt ;;
esac
$2 "$file" | $PAGER "$Prompt" $Opts
break
esac
shift 2
done
;;
*) plain[${ esac
done
[ ${