This is definitely a quality-of-life thing that you only notice when it’s gone. I typically use it as a function, but since it’s the shell, there’s ten thousand ways to do it. Here’s (my) fish shell version for copy-paste:
function man -d "Pretty manpages"
LESS_TERMCAP_mb=(printf "\e[1;31m") \
LESS_TERMCAP_md=(printf "\e[1;31m") \
LESS_TERMCAP_me=(printf "\e[0m") \
LESS_TERMCAP_se=(printf "\e[0m") \
LESS_TERMCAP_so=(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=(printf "\e[0m") \
LESS_TERMCAP_us=(printf "\e[1;32m") \
That’s nice. Going to use that for sure.
FYI fish has a set_color builtin that might make that a bit more readable.
If you use Neovim, you can use the builtin man page plugin.
For example: https://i.imgur.com/eLNmYkh.png
Checkout https://github.com/neovim/neovim/blob/611351677dba450fc1a312061572c44c7e3d6482/runtime/doc/filetype.txt#L509 for docs and how to use it as the default man pager.
This is a fantastic tip. Thanks for sharing.
If you like adding colors to commands that lack it, I’ve found the Generic Colouriser really helpful, and very easy to use. E.g., here’s adding colors to Fossil with it.
I ran into exactly the same bug when I tried to move the not-so-nice environment variables out of my profile and into the lesskey file. Ultimately I never got around to finding out why it wouldn’t work - but together with someone else, came up with a small C wrapper around less(1) which lets the user set colours in a more sane manner.
With this, you only have to do:
See here for a more detailed description along with the source code.
This is great, I like that it avoids polluting the shell environment.
The issue should be fixed in the most recent less version (released just 10 days ago) but most systems won’t have this up-to-date version so there is still a need for a solution like yours to set the variables elsewhere.
If you’re on macOS and already have Dash.app installed, check out open dash://manpages:$1 (e.g. open dash://manpages:ls).
And if you want a nice-ish PDF:
man -t ls | open -fa Preview
I put together a script for that. It’s a little overengineered to catch missing dependencies, but it’s kinda nice because it puts the PDF output in $TMPDIR as a cache for subsequent retrievals of the same manpage.
setting PAGER=most does this automatically too.
I use vim as my PAGER in order to get a consistent highlighting and colour scheme.
Easiest way to do this is via https://github.com/rkitover/vimpager - but you can also use the “less.sh” wrapper that’s included with vim.
(Path will obviously vary based on your OS, etc.)
On MacOS, “brew install vimpager” will be quickest.