Monday 3 June 2013

less colors for man pages

I have been using Tera Term for quite long time, but whenever I open the man pages it displays the text in some weird yellow color. To get rid of this yellow color I have started my search and end up in two methods for displaying colored man pages. One is using less, more preferred one because it provides the powerful feature of less command and the other is using most.

1. Using less

Less is used as the default command for viewing man pages.

Add the following to the BASH configuration file ~/.bashrc or /etc/bashrc

# Less Colors for Man Pages

export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\E[01;31m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # end mode
export LESS_TERMCAP_se=$'\E[0m' # end stand-out mode
export LESS_TERMCAP_so=$'\E[01;44;33m' # begin stand-out mode
export LESS_TERMCAP_ue=$'\E[0m' # end underline
export LESS_TERMCAP_us=$'\E[01;32m' # begin underline

You can customize the colors too, see ANSI escape code for reference.

Log out and log back in or source the /etc/bashrc have it work

# source /etc/bashrc

2. Change to vim editor to open man pages

If you use bash, just add the following script in your ~/.bashrc or /etc/bashrc

export PAGER="/bin/sh -c \"unset PAGER;col -b -x | vim -R -c 'set ft=man nomod nolist' -c 'map q :q<CR>' -c 'map <SPACE> <C-D>' -c 'map b <C-U>' -c 'nmap K :Man <C-R>=expand(\\\"<cword>\\\")<CR><CR>' -\""

3. Using most

most provides almost same functions as as less and more, but most is not powerful as less and configuring most to use colors is simper than using less.

RPMForge repo has to be  configured, if we want to use yum. You can download the source tarball from the website http://www.jedsoft.org/most/ or you can download the rpm from http://pkgs.repoforge.org/most/

Open the file /etc/man.config and replace 'PAGER  /usr/bin/less -is' with 'PAGER  /usr/bin/most -s'

Verify this by typing man <some command>

Note: Thanks Nico for this tip.

No comments:

Post a Comment