2

System: OS X 10.9.x (Mavericks)

Goal: To be able to change the color scheme used for manpages depending on whether the displayed page is in the default system location (/usr/share/man/…) or the location where package-manager installed manpages live (/usr/local/share/man/…).

I have only a vague awareness of the rendering process of manpages. I know that man hands off a page to some sort of preprocessor (troff?) and some stuff happens before the page is displayed in less. But that’s about it. :/

Zearin
  • 1,474
  • 2
  • 17
  • 36
  • I don't know the reason why you want to change the color scheme but I read man pages on OS X only this way: `function pman { man -t "$1" | open -f -a Preview; }` This opens a PDF version in preview with `pman rsync`. Hope this may help. – 2called-chaos Mar 26 '14 at 14:59

1 Answers1

0

As per the following question on Unix StackExchange, the color scheme for man pages is based on the environment variables settings passed to the pager.

For less these are the less termcap variables which are described in the following question on Unix StackExchange

A simple solution to your problem a shellscript that looks something like

#!/bin/bash
mancommand=`man -d $1 2>&1 | tail -1`
parts=( $mancommand );
path=${parts[8]};
if [[ $path == */usr/share/man/* ]]

then
       # One colour scheme
       LESS_TERMCAP_mb=$'\E[01;31m' \
       LESS_TERMCAP_md=$'\E[01;38;5;74m' \
       LESS_TERMCAP_me=$'\E[0m' \
       LESS_TERMCAP_se=$'\E[0m' \
       LESS_TERMCAP_so=$'\E[38;5;246m' \
       LESS_TERMCAP_ue=$'\E[0m' \
       LESS_TERMCAP_us=$'\E[04;38;5;146m' eval $mancommand
else
        # Second colour scheme
        LESS_TERMCAP_mb=$(tput bold; tput setaf 2) \
        LESS_TERMCAP_md=$(tput bold; tput setaf 6) \
        LESS_TERMCAP_me=$(tput sgr0) \
        LESS_TERMCAP_so=$(tput bold; tput setaf 3; tput setab 4) \
        LESS_TERMCAP_se=$(tput rmso; tput sgr0) \
        LESS_TERMCAP_us=$(tput smul; tput bold; tput setaf 7) \
        LESS_TERMCAP_ue=$(tput rmul; tput sgr0) \
        LESS_TERMCAP_mr=$(tput rev) \
        LESS_TERMCAP_mh=$(tput dim) \
        LESS_TERMCAP_ZN=$(tput ssubm) \
        LESS_TERMCAP_ZV=$(tput rsubm) \
        LESS_TERMCAP_ZO=$(tput ssupm) \
        LESS_TERMCAP_ZW=$(tput rsupm) eval $mancommand
fi
Community
  • 1
  • 1
Appleman1234
  • 15,946
  • 45
  • 67