Colored man pages not working on gentoo

Could be a number of problems.

Seeing as you're using zsh, try putting this in your ~/.zshrc:

export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;47;34m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'
export LESS=-r

Then open a new terminal window and try running

man ls

if it's not working, run each of the following to find out where the problem is:


Number 1

typeset -p LESS_TERMCAP_md | cat -v

should print

typeset -x LESS_TERMCAP_md="^[[01;31m"

and

typeset -p LESS

should print

typeset -x LESS="-r"

if not, you put the export LESS stuff in the wrong file.


Number 2

echo "${LESS_TERMCAP_md}red${LESS_TERMCAP_me}"

should print

red

in a red color. If it doesn't there is something wrong with your terminal settings. Check your terminal settings (e.g. ~/.Xresources) or try running gnome-terminal or xterm and see if that works.


Number 3

echo -E "a^Ha" | LESS= less -r

(^H must be entered by pressing Ctrl+V then Ctrl+H)

should print

a

in red. If it doesn't, please run these

type less
less --version

and paste the output back in your question.


Number 4

bzcat /usr/share/man/man1/ls.1.bz2 | \
    /bin/sh /usr/bin/nroff -mandoc -Tutf8  | head -n 5 | cat -v

should print

LS(1)                            User Commands                           LS(1)



N^HNA^HAM^HME^HE

(note the ^H like in step number 3)

if it's printing something like:

LS(1)                            User Commands                           LS(1)



^[[1mNAME^[[0m

instead, you will need to find a way to disable "sgr escape sequences". The easiest thing to try is adding export GROFF_NO_SGR=1 to .zshrc, but there are other ways of fixing this.


Number 5

bzcat /usr/share/man/man1/ls.1.bz2 | \
    /bin/sh /usr/bin/nroff -mandoc -Tutf8 | less

should display the ls man page with colors.


man ls

should now be working!


Having read Mikels answer, its very comprehensive, and will hopefully work on all systems, but its probably overkill for myself ( also on a gentoo system. )

So here is a result for people who are very "Do long, didn't read" with all that shenanigans.

The Bare minimum I could do to get Coloured Man pages is as follows:

LESS_TERMCAP_md=$'\E[01;31m' LESS_TERMCAP_me=$'\E[0m' GROFF_NO_SGR=1 man man

This renders text that was previously only in bold, in bold and red. ( The red characterised by the '31' in LESS_TERMCAP_md )

LESS_TERMCAP_se=$'\E[0m' LESS_TERMCAP_so=$'\E[01;32m'

These 2 rules control the formatting of the current line number display, and coerce it to rendering in Green.

LESS_TERMCAP_us=$'\E[04;33m' LESS_TERMCAP_ue=$'\E[0m'

These 2 rules move everything that was previously underlined, to being underlined and yellow. ( 04 is 'underlined', 33 is "yellow" )