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.

When I look at a man page in my 'console' (not an xterm) I see some coloration, but I don't get this in my xterm's (e.g. konsole) is there any way I can enable this? hopefully a fairly simple solution?

share|improve this question

3 Answers 3

up vote 37 down vote accepted

You need to use the termcap(5) feature. The man page on some Unices says this tool is obsolete and to use terminfo, but it's still available on others, and terminfo is more complicated. Most importantly, less uses termcap.

I do the following so that less and man (which uses less) will have color:

$ cat ~/.LESS_TERMCAP 
export LESS_TERMCAP_mb=$(tput bold; tput setaf 2) # green
export LESS_TERMCAP_md=$(tput bold; tput setaf 6) # cyan
export LESS_TERMCAP_me=$(tput sgr0)
export LESS_TERMCAP_so=$(tput bold; tput setaf 3; tput setab 4) # yellow on blue
export LESS_TERMCAP_se=$(tput rmso; tput sgr0)
export LESS_TERMCAP_us=$(tput smul; tput bold; tput setaf 7) # white
export LESS_TERMCAP_ue=$(tput rmul; tput sgr0)
export LESS_TERMCAP_mr=$(tput rev)
export LESS_TERMCAP_mh=$(tput dim)
export LESS_TERMCAP_ZN=$(tput ssubm)
export LESS_TERMCAP_ZV=$(tput rsubm)
export LESS_TERMCAP_ZO=$(tput ssupm)
export LESS_TERMCAP_ZW=$(tput rsupm)

And then in my ~/.bashrc, I do this:

    # Get color support for 'less'
    export LESS="--RAW-CONTROL-CHARS"

    # Use colors for less, man, etc.
    [[ -f ~/.LESS_TERMCAP ]] && . ~/.LESS_TERMCAP

NOTE: See Documentation on LESS_TERMCAP_* variables? for how this works.

The final result

    ss of man page

share|improve this answer
    
Kudos to @Dennis Williamson for the answer. See superuser.com/questions/146182/… –  Stefan Lasiewski Aug 10 '10 at 21:17
5  
I believe the reason this works the way it does, is because 'console' translates 'underline' into colour, where-as X11 stuff supports underlines. You can test this theory by typing echo -e "\e[04mhello world\e[0m" in both the console and your X11 terminal and seeing the difference. So this above hack abuses termcap to lie to LESS about what codes it needs to emit for bold/underline and forces it to produce colour escape codes instead. –  Kent Fredric Feb 15 '11 at 12:03
2  
Indeed, the translation of underline into blue has historic reasons, going back to the text modes of the original PC graphics adapters MDA and CGA (actually the CGA text modes are still available to date). Those graphics adapters stored two bytes per character: One holding the ASCII code, one holding the attributes. The MDA interpreted the attribute byte as combinations of underline, bright, blinking and inverse, while the CGA interpreted that byte as foreground and background colour. And it happened that the MDA attribute for underline equalled the CGA attribute for blue on black. –  celtschk May 8 at 18:39

You can solve this issue by using a different pager, for example most. man will actually use the program specified in the PAGER environment variable. From the man(1) man page:

MANPAGER, PAGER

If $MANPAGER or $PAGER is set ($MANPAGER is used in preference), its value is used as the name of the program used to display the manual page. By default, pager -s is used.

The value may be a simple command name or a command with arguments, and may use shell quoting (backslashes, single quotes, or double quotes).

It may not use pipes to connect multiple commands; if you need that, use a wrapper script, which may take the file to display either as an argument or on standard input.

If most is installed on your system, try this, before launching man:

export PAGER=most
share|improve this answer
1  
most should be installed, for this to work. –  enzotib Sep 14 '11 at 7:41

I think this might be helpful.

excerpt

$ mkdir ~/.terminfo/ && cd ~/.terminfo

Now get the terminfo description:

$ wget http://nion.modprobe.de/mostlike.txt

Now compile it using tic (the terminfo entry-description compiler)

$ tic mostlike.txt
(you may want to delete the mostlike.txt file after compiling)

And then just define an alias in the rc file of your favorite shell.

$ alias man="TERMINFO=~/.terminfo/ LESS=C TERM=mostlike PAGER=less man"

If you want to modify the terminfo file, use infocmp mostlike to get the content of it later.

share|improve this answer
9  
It helps if you summarize the source here, so people can see what it says without having to click through (and in case the site ever goes down) –  Michael Mrozek Aug 10 '10 at 20:57
2  
Please provide answers, not just links to answers. It's very good to provide links which support your answer, however. Imagine I was Googling for this question--- a good answer at StackExchange will quickly find it's way to the first page of results. –  Stefan Lasiewski Aug 10 '10 at 21:27
    
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. –  manatwork Nov 7 '13 at 14:21

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.