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?
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.
Especially if you need something more than "JavaScript, Java, Ruby, Python, Go, and C" - pygments has a list of supported languages a tiny bit longer than that: http://pygments.org/languages/
True, it takes some time to highlight some files - for example 5k loc long Racket files or very long XML/HTML files - but it supports all the languages I use (or used or may use in the future), while this tool supports only one of the languages I use on a daily basis.
I read http://pygments.org/docs/styles and other sites but I didn't find how I can change the default colors. Do I have to edit (clone) pygments or is there a config file?
I do something similar except with "view" aka "vi -R" aka read-only mode.
A couple things I like about "view":
1. No warning screen when using "view file.c" if you or someone else happens to have the same file open for editing.
2. No "unsaved changes" prompt when quitting "view -" (or in other words, no need to force-quit with :q!)
Edit: Also worth noting is that "view file.c" vs "cat file.c |view -" gives vim a better chance of getting the syntax highlighting right since it knows the file extension.
My dad and I wrote virtually this same tool 8 or 10 years ago. The program uses arbitrary regular expressions to match and colorize any file you desire to write a set of rules for. And it ships with some common rules too. This was before pygmentize was very popular (or around at all).
Those who don't google search are doomed to reinvent..
"cat isn't for printing files with line numbers, it isn't for compressing multiple blank lines, it's not for looking at non-printing ASCII characters, it's for concatenating files."
Why not make it just a syntax highlighting filter? Or is the "cat" functionality too trivial to be factored out, and thus it has grown to include other things? I suppose it's a bit of a philosophical question...
Maybe it's like grep. `grep asterisk` is different from `cat asterisk |grep`, in that it knows which file it's in and which line number of that file the match is on.
My synapses, my circumstances and random() sometimes lead me to use any of cat, less, vim, view, grep and probably others that don't come to mind at the moment.
Anything over like 20 lines for me takes a second or so. Then again the machine is like 175 miles away and its a core 2 duo... so I suppose that's reasonable.
A syntax highlighting pager might be more useful to me. cat is a tool that I only use for plumbing, and I rarely want coloring control codes anywhere but stdout.
Some people also say they are glad/happy to code in Notepad.exe
Brains do a lot of things, but there is a limit somewhere or at the very least a trade off of speed. Simple things like syntax highlighting can help you find what you are looking for faster.