Just a quick tip, you would want to use `less -R` (upper case R) instead. `less -r` allows all raw characters which makes it difficult for less to maintain screen appearance. From the man page:
-R or --RAW-CONTROL-CHARS
Like -r, but only ANSI "color" escape sequences are output in "raw"
form. Unlike -r, the screen appearance is maintained correctly in most
cases.
Re:Ccat – syntax highlighting cat
by Splognosticus on Wednesday May 06, 2015 @12:22PM
(#9499782)
You might also want to take a look at less's input preprocessor, which could be used to automatically colorize source.
Install src-hilite and use LESSOPEN:
LESS=' -R '
LESSOPEN='| /usr/local/bin/src-hilite-lesspipe.sh %s'
You can use vimpager instead of less to get highlighting if you want.
While I was reading the ccat page I was wishing it was a colorized less, rather than a colorized cat.
Then I thought to read the man page for less, because sometimes what you want is already there. And it does handle color, but only if they're escaped colors. Oh well.
Then I saw your comment, tried pygmentize on a python script, and there's some nice colored code, that scrolled off the terminal.
Then I piped that into less, just to be grumpy. Yep, it's all white ... but wait, what are all those escape characters?
...
pygmentize -g myScript.py |less -r
The colors! The colors! And in less, no less.