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
Some may notice I used Arch colors :) :
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?
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.
Pingback: Color man pages : Linux T&T
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.
Jeremy, most do use Xterm. If it is not working on your terminal, it be best to provide more Details.
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?
Same here Jeremy. Not sure of the problem yet myself….
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?
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.
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
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
Very nice tip, thanks! Works really good : )
Pingback: code(alpha) » Colored Man Pages
Pingback: S03E20 – The Midnight Flyer – MP3 LOW | Ubuntu Podcast from the UK LoCo team
Pingback: S03E20 – The Midnight Flyer – MP3 HIGH | Ubuntu Podcast from the UK LoCo team
Pingback: S03E20 – The Midnight Flyer – OGG HIGH | Ubuntu Podcast from the UK LoCo team
Pingback: S03E20 – The Midnight Flyer | Ubuntu Podcast from the UK LoCo team
Pingback: S03E20 – The Midnight Flyer – OGG LOW | Ubuntu Podcast from the UK LoCo team
Pingback: What viewer to use for viewing man pages with syntax highlighting?
Pingback: Different color prompts for different machines when using terminal/ssh? - Question Lounge
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
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
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/
another blogger I respect, with same thought stream: http://www.cyberciti.biz/faq/linux-unix-colored-man-pages-with-less-command/
Pingback: colour man pages - jonathans blog
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`.