summaryrefslogtreecommitdiffstats
path: root/usr.bin/man/man.sh
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2011-06-03 14:34:38 +0000
committerru <ru@FreeBSD.org>2011-06-03 14:34:38 +0000
commitac14eff506609aa01adf3b7519861b7f6eb43c06 (patch)
tree4108d557e1262b98ba251da1b502b7dc79403dfc /usr.bin/man/man.sh
parente43f9045296b6f5823d53836a7a651d2e678c070 (diff)
downloadFreeBSD-src-ac14eff506609aa01adf3b7519861b7f6eb43c06.zip
FreeBSD-src-ac14eff506609aa01adf3b7519861b7f6eb43c06.tar.gz
When MANCOLOR environment variable is set, enable ANSI color escapes
in grotty(1). This makes it possible to view colorized manpages in color. When MANPAGER environment variable is set, use it instead of PAGER. Why another environment variable, one might ask? With color output enabled, both a terminal and a pager should support the ANSI color escapes. On a supporting terminal, less(1) with option -R would be such a pager, while "more -s" (the current default pager for man(1)) will show garbage. It means a different default pager is needed when color output is enabled, but many people have PAGER set customary, and it's unlikely to support ANSI color escapes, so introducing yet another variable (MANPAGER) seemed like a good option to me: - if MANPAGER is set, use that unconditionally; - if you disable color support (it is by default), and don't set MANPAGER, you get an old behavior: -P pager, $PAGER, "more -s", in that order; - if you enable color support (by setting MANCOLOR), and don't set MANPAGER, we ignore PAGER which is unlikely to support ANSI color escapes, and you get: -P pager, "less -Rs", in that order; - you might have good reasons for different man(1) and general purpose pagers; - later versions of GNU man(1) support MANPAGER.
Diffstat (limited to 'usr.bin/man/man.sh')
-rwxr-xr-xusr.bin/man/man.sh32
1 files changed, 22 insertions, 10 deletions
diff --git a/usr.bin/man/man.sh b/usr.bin/man/man.sh
index 11a9206..98749a6 100755
--- a/usr.bin/man/man.sh
+++ b/usr.bin/man/man.sh
@@ -294,10 +294,10 @@ man_display_page() {
ret=0
else
if [ $debug -gt 0 ]; then
- decho "Command: $cattool $catpage | $PAGER"
+ decho "Command: $cattool $catpage | $MANPAGER"
ret=0
else
- eval "$cattool $catpage | $PAGER"
+ eval "$cattool $catpage | $MANPAGER"
ret=$?
fi
fi
@@ -356,6 +356,10 @@ man_display_page() {
;;
esac
+ if [ -z "$MANCOLOR" ]; then
+ NROFF="$NROFF -P-c"
+ fi
+
if [ -n "${use_width}" ]; then
NROFF="$NROFF -rLL=${use_width}n -rLT=${use_width}n"
fi
@@ -382,7 +386,7 @@ man_display_page() {
if [ -n "$tflag" ]; then
pipeline="$pipeline | $TROFF"
else
- pipeline="$pipeline | $NROFF | $PAGER"
+ pipeline="$pipeline | $NROFF | $MANPAGER"
fi
if [ $debug -gt 0 ]; then
@@ -484,7 +488,7 @@ man_parse_args() {
while getopts 'M:P:S:adfhkm:op:tw' cmd_arg; do
case "${cmd_arg}" in
M) MANPATH=$OPTARG ;;
- P) PAGER=$OPTARG ;;
+ P) MANPAGER=$OPTARG ;;
S) MANSECT=$OPTARG ;;
a) aflag=aflag ;;
d) debug=$(( $debug + 1 )) ;;
@@ -808,7 +812,7 @@ search_whatis() {
bad=${bad#\\n}
if [ -n "$good" ]; then
- echo -e "$good" | $PAGER
+ echo -e "$good" | $MANPAGER
fi
if [ -n "$bad" ]; then
@@ -832,13 +836,21 @@ setup_cattool() {
}
# Usage: setup_pager
-# Correctly sets $PAGER
+# Correctly sets $MANPAGER
setup_pager() {
# Setup pager.
- if [ -z "$PAGER" ]; then
- PAGER="more -s"
+ if [ -z "$MANPAGER" ]; then
+ if [ -n "$MANCOLOR" ]; then
+ MANPAGER="less -sR"
+ else
+ if [ -n "$PAGER" ]; then
+ MANPAGER="$PAGER"
+ else
+ MANPAGER="more -s"
+ fi
+ fi
fi
- decho "Using pager: $PAGER"
+ decho "Using pager: $MANPAGER"
}
# Usage: trim string
@@ -921,7 +933,7 @@ do_whatis() {
# User's PATH setting decides on the groff-suite to pick up.
EQN=eqn
-NROFF='groff -S -P-ch -Wall -mtty-char -man'
+NROFF='groff -S -P-h -Wall -mtty-char -man'
PIC=pic
REFER=refer
TBL=tbl
OpenPOWER on IntegriCloud