31 Comments

Customize man page colors with ‘less’ definitions

Man pages by default use less for displaying. I’ve used vim before to for colored text in man pages but something got bjorked in an update. To have color with man pages termcap will need to be invoked. Thanks to nico for the tip.

All that needs to be done is to export bold and underline values of termcap. Adding the values to the ~/.bashrc will make sure that they are always used:

# Less Colors for Man Pages
export LESS_TERMCAP_mb=$'\E[01;31m'       # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m'  # begin bold
export LESS_TERMCAP_me=$'\E[0m'           # end mode
export LESS_TERMCAP_se=$'\E[0m'           # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;246m'    # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m'           # end underline
export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline

And source the ~/.bashrc to have it work:

source ~/.bashrc

Notice I used Arch and Gentoo colors, my two favorite distros :) :

About these ads

About Gen2ly

<3's linux

31 comments on “Customize man page colors with ‘less’ definitions

  1. What I’d be inerested even more is syntax highlighting in ‘less’ …is that possible or should I just use ‘vim’ as my viewer as well?

  2. Unsure. But termcap is limited and i dont’ think it has the ability to ‘recognize strings’ only predefined variables (like man-pages got). You can look at ‘man termcap’ to what it can do. A wrapper script possibly could be put around it but i think that would be alot, alot of work.

  3. [...] Less Colors For Man Pages « Helpful Linux Tidbits [...]

  4. Do you use xterm? Something must be interfering with mine in my environment as it is not trivial to get it working on my host.

  5. Jeremy, most do use Xterm. If it is not working on your terminal, it be best to provide more Details.

  6. Ahh, this is quite concerning and probably the source of the issue:

    %% env|grep LESS_TERMCAP
    LESS_TERMCAP_mb=
    LESS_TERMCAP_md=
    LESS_TERMCAP_me=
    LESS_TERMCAP_ue=
    LESS_TERMCAP_us=
    LESS_TERMCAP_so=
    LESS_TERMCAP_se=

    any ideas?

  7. Same here Jeremy. Not sure of the problem yet myself….

  8. Hmm, this is a bit out there but I notice most people use \e to begin escape sequences before entering terminal colors. Possible try this?

  9. Those variables only *appear* to be emtpy, because they are entirely made of unprintable escape sequences.

    Try: env | grep LESS_TERMCAP | cat

    You still won’t see the codes, but you see the effect on the next line that’s printed out.

  10. Nice tip, works fine for me.
    I am interested in the colors though, cause i am on Arch :)
    Do you happen to have a corresponding (read: equally nice) color theme for your xterm and maybe vim ?

    Thanks

  11. That’s a bit in deliberation. I using yakuake, and using a theme based on Konsole, Oxygen theme:

    http://kde-look.org/content/show.php/Oxygen+Konsole+Color+Scheme?content=86353

    The values I’m using:

    color0 181C20 color1 A44245 color2 00BF00 color3 BBAD5B color4 2B76C7 color5 8B56A3 color6 5BCEE4 color7 D4D7D0 color8 A44245 color9 A44245 color10 37A42B color11 C4C29B color12 2B76C7 color13 8B56A3 color14 71AAB3 color15 EAEAEA

    As for vim there’s alot to choose but I like how the Oxygen scheme looks in it. For more basic tones you might want to look at brian’s Gentooish vim scheme though:

    http://briancarper.net/page/vim

  12. Very nice tip, thanks! Works really good : )

  13. [...] this link to Linuxtidbits' post about "Less Colors For Manpages" and you'll know how to make it [...]

  14. [...] we have your feedback including a tidbit from Martin van de [...]

  15. [...] we have your feedback including a tidbit from Martin van de [...]

  16. [...] we have your feedback including a tidbit from Martin van de [...]

  17. [...] we have your feedback including a tidbit from Martijn van de [...]

  18. [...] we have your feedback including a tidbit from Martijn van de [...]

  19. [...] You might find this link interesting, though there may be one or more other ways to do it too. http://linuxtidbits.wordpress.com/20…for-man-pages/ [...]

  20. for mac os x this is what i had to use, as it appears a less advanced ansi color interpretation:

    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 standout-mode
    export LESS_TERMCAP_so=$’\E[01;44m’ # begin standout-mode – info
    export LESS_TERMCAP_ue=$’\E[0m’ # end underline
    export LESS_TERMCAP_us=$’\E[32m’ # begin underline

  21. I see a few issues with this approach. If you login to your account from different terminals, the same escape sequences will be sent in all cases. There’s no way to personalize this for different terminals. (Also, it uses an undocumented feature of less, which may change or disappear. These LESS_TERMCAP_xxx environment variables were intended to make it easy to cause escape sequences to become visible, to aid in debugging.)

    I think a better approach is to personalize your termcap/terminfo database. On a Fedora systems, for example, I can do

    echo ‘xterm-mycolors, bold=\E[38;5;246m, sgr0=\E[0m, use=xterm,’ >myterm.ti

    tic myterm.ti

    export TERM=xterm-mycolors

    This not only achieves the same thing in less without using undocumented features, it makes bold text be the desired color in all programs that use termcap/terminfo.

    –Mark

  22. There is no need to use most, it can also be done with most :-)

    http://spsneo.com/blog/2008/07/21/colourful-man-pages-in-ubuntu/

  23. Someone necessarily assist to make seriously
    posts I might state. That is the very first time I frequented your web page and so
    far? I amazed with the analysis you made to create this actual post
    amazing. Fantastic task!

  24. It’s awesome to visit this web page and reading the views of all mates about this piece of writing, while I am also eager of getting experience.

  25. Hello, yeah this article is genuinely good and I have learned lot of
    things from it about blogging. thanks.

  26. This includes emotional abuse, physical abuse as well as sexual abuse.
    John’s Wort which helps to provide anxiety relief and controls and lessens panic attack occurrence. The sudden onset of this symptom can certainly lead a person to feel as if they are suffering a heart attack.

  27. Power stations would have to be built every 2 miles along the
    power lines. Luckily, several pioneers have worked hard and collaborated on Tesla’s work over the years.
    The mans name is Marin Soljacic, a professor at MIT
    and founder of one of the leading companies in our electronic future, Witricity.

  28. To see the normally-invisible escape sequences in the LESS_TERMCAP_* variables, try `cat -v`:

    $ env | grep ^LESS_TERMCAP | cat -v
    LESS_TERMCAP_mb=^[[01;31m
    LESS_TERMCAP_md=^[[01;38;5;208m
    LESS_TERMCAP_me=^[[0m

    You can also use less itself, as long as its ‘raw control chars’ mode is disabled, i.e. `env | grep ^LESS_TERMCAP | less -+r`.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 52 other followers

%d bloggers like this: