Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a problem using these methods to get colors in my man pages in gentoo. I've asked already in the gentoo forums but it still doesn't work, and the comments in a bug report (Bug 184604) don't work either. Can someone help me to get colours in my man pages?

EDIT: Yes, I'm using less as pager and urxvt-unicode as terminal emulator

EDIT2:

I already asked in the gentoo forums but it didn't help, this is the link I couln't post before (because of my reputation) http://forums.gentoo.org/viewtopic-t-819833-start-0.html.

share|improve this question
    
you are using less as your pager right? –  xenoterracide Jan 18 '11 at 10:54
    
What terminal emulator are you using, and what does echo $TERM display? –  Gilles Jan 18 '11 at 21:54

2 Answers 2

up vote 12 down vote accepted

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!

share|improve this answer
    
I'm using zsh, I couln't post this before because I was a new user forums.gentoo.org/viewtopic-t-819833-start-0.html also typeset -p LESS printed this: "typeset: no such variable: LESS" and about the number 5, there's no ls.1.gz but there's ls.1.bz2 but it prints this "gzip: /usr/share/man/man1/ls.1.bz2: not in gzip format" the rest of the options work well but I still don't have coloured man pages. –  Vicfred Jan 25 '11 at 5:08
    
typeset -p LESS not working is your problem. But seeing as you are using zsh, you should put export LESS=-r in your ~/.zshrc, not in ~/.bashrc. Please do that then try these steps again. –  Mikel Jan 25 '11 at 5:13
    
And change zcat /usr/share/man/man1/ls.1.gz to bzcat /usr/share/man/man1/ls1.bs2. –  Mikel Jan 25 '11 at 5:26
    
I have updated the instructions based on the information you just provided. –  Mikel Jan 25 '11 at 5:34
3  
export GROFF_NO_SGR=1 worked, thank you, could you point me to some references on this? you were the only one who actually gave a different answer. –  Vicfred Jan 25 '11 at 6:37

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" )

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.