Right now, I use most
as my pager. While it has helpful syntax highlighting for man
pages, it lacks colored syntax highlighting for anything else (I'm specifically looking for diff/C++).
Meanwhile, pygments
is a wonderful program. I can easily make colorized output with it:
# ./pygmentize -f console256 ${file}
hg diff | ./pygmentize -f console256 -l diff
Now, I would like to be able to page the output, so I just use:
# ./pygmentize -f console256 ${file} | most
hg diff | ./pygmentize -f console256 -l diff | most
At this point, most dumps all the colorizing control characters to my screen like so:
^[[38;5;28;01mclass^[[39;00m ^[[38;5;21;01mheap_allocator^[[39;00m
{
^[[38;5;28;01mpublic^[[39;00m^[[38;5;241m:^[[39m
This is, of course, unreadable. I looked though the man
page for most
, but I couldn't find any "Hey, show those control characters as colors instead of printing them" options. less
has the same garbage behavior as most
, but more
shows the colors perfectly fine, with the obvious limitations of being more
.
Is there a pager that supports syntax highlighting or some crazy combination of parameters and programs I can string together to make this work? Ultimately, I would like to get diffs and logs from Mercurial to be highlighted, so maybe there is a shortcut in there...
Might I suggest vimpager
?
First off, recent vim
distributions (I believe 6.0 and above) come with a pager-esque-mode script. It's quite simple and functional, and operates similarly to less
. Try: vim '+help less' +only
.
Even better, however, Rafael Kitover has written a much more robust and powerful script called vimpager
. It's available on GitHub (or vimscripts). If you are on OS X and using Homebrew, it's as easy as brew install vimpager
.
At that point, you can simply set $PAGER=vimpager
, or even alias less=vimpager
. It works excellently.
less -R
shows ANSI color sequences as-is (instead of expanding to caret notation). That'll make syntax highlighting work!
You can also create an environment variable LESS=-R
to make this the default behavior. Similarly for other options; see man less
.
You might try using jed. Yes, it's a text editor, not a pager, but it's quite lightweight and the default install contains excellent colorschemes for a wide variety of file types and languages.
Look for bat: A cat(1) clone with wings.
bat
supports syntax highlighting for a large number of programming and markup languages.
It is not a pager, but it automatically redirects output to less
if needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With