11

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: http://forums.gentoo.org/viewtopic-t-819833-start-0.html.

1

3 Answers 3

26

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!

21
  • 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
    Commented Jan 25, 2011 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
    Commented Jan 25, 2011 at 5:13
  • And change zcat /usr/share/man/man1/ls.1.gz to bzcat /usr/share/man/man1/ls1.bs2.
    – Mikel
    Commented Jan 25, 2011 at 5:26
  • 1
    I tried the new options and all of them work except the last one, it prints the man pages with no colours.
    – Vicfred
    Commented Jan 25, 2011 at 5:49
  • 8
    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
    Commented Jan 25, 2011 at 6:37
4

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

1

People searching for solutions to this in 2023 might be affected by a change in the groff package introduced in version 1.23.0.

Putting export MANROFFOPT=-c in my .zshrc fixed it for me.

(or alternatively GROFF_NO_SGR=1)

Background:

https://bbs.archlinux.org/viewtopic.php?id=287185

https://github.com/jedsoft/most/issues/18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .