4 ms·
Brilliant! 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,
by a3n 12y ago
Brilliant!
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.
- rraval 12y agoJust 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.
- gh02t 12y agoYou can use vimpager instead of less to get highlighting if you want.
- a3n 12y agoI usta do that, but there were occasional quirks. But then, I have occasional quirks and I'm still allowed out of the house.
- Splognosticus 12y agoYou might also want to take a look at less's input preprocessor, which could be used to automatically colorize source.
- woof 12y agoInstall src-hilite and use LESSOPEN: LESS=' -R ' LESSOPEN='| /usr/local/bin/src-hilite-lesspipe.sh %s'