

Ccat – syntax highlighting cat - jingweno
https://github.com/jingweno/ccat

======
mavidser
There's also the "python-pygments" package which provides awesome syntax
highlighting. You can alias it to ccat too:

    
    
        alias ccat='pygmentize -g'

~~~
a3n
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.

~~~
gh02t
You can use vimpager instead of less to get highlighting if you want.

~~~
a3n
I usta do that, but there were occasional quirks. But then, I have occasional
quirks and I'm still allowed out of the house.

------
shurcooL
This is pretty cool, and nice demo gif. Thanks for making it!

Honestly, the biggest advantage for me over all other proposed alternatives is
that it's a pure Go binary, so I can just do this:

    
    
        go get -u github.com/jingweno/ccat
    

On any of my machines. One predictable command will fetch the source, all
dependencies and build it without any configuration.

I use Go as my primary development language, so I'm more likely to have it
installed than any other tools that are not go-gettable.

------
alfiedotwtf
Not to diminish OP's project, but I pipe most things to vim to get all my
standard highlighting goodness:

    
    
        cat file_name | vi -

~~~
oops
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.

------
tanderson92
alias ccat='supercat'
([http://supercat.nosredna.net/](http://supercat.nosredna.net/))

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..

~~~
hurin
> Those who don't google search are doomed to reinvent..

Not to be critical - but you are also forcing people to reinvent by having a
custom-rule parser, rather than wrapping an existing lexer library.

------
albinoloverats
I've been using source-highlight[1] to achieve the same result.

[edit]: alias ccat="source-highlight --out-format=esc --style-
file=/usr/share/source-highlight/esc.style --failsafe -i "

I'll have to see how this compares.

[1]: [http://www.gnu.org/software/src-
highlite/](http://www.gnu.org/software/src-highlite/)

------
codychan
Why not use `less` instead of `cat`? Besides it is very easy to use
`pygmentize` and `source-highlight` to get syntax highlighting result.

------
userbinator
Seeing as it also reads multiple files and/or standard input, I am reminded of
this:

[http://harmful.cat-v.org/cat-v/](http://harmful.cat-v.org/cat-v/)

"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...

~~~
smorrow
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.

------
DblPlusUngood
Another solution for machines with vim installed:

    
    
      vim -u /usr/share/vim/vim73/macros/less.vim <file>
    

less.vim makes vim behave like less with syntax highlighting.

~~~
MikeTLive
only two days back i added this alias:

alias vless=/usr/share/vim/vim73/macros/less.sh

after finding it on a search for a colorized pager

------
tomweingarten
I'd just hoped someone would make this last week! Only I was hoping it would
be named catfancier:

[https://twitter.com/tomweingarten/status/592751132788838401](https://twitter.com/tomweingarten/status/592751132788838401)

------
AdmiralAsshat
Do people cat sourcecode to read it? For anything larger than a five line
shell script, I'd assume one would open it in vim or emacs.

~~~
a3n
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.

------
prakashk
I use the highlight package[1] that comes with Debian/Ubuntu. With that:

    
    
        highlight -O ansi file.ext | less -R
        highlight -O xterm256 file.ext | less -R
    

highlight can also convert the input to other formats: HTML, XHTML, RTF,
LaTeX, TeX, BBCode or SVG.

An alternative to `less -R` is the `most` pager [2].

[1]
[https://packages.debian.org/jessie/highlight](https://packages.debian.org/jessie/highlight)
[2]
[https://packages.debian.org/jessie/most](https://packages.debian.org/jessie/most)

------
beberlei
This is unfortunate, there is already a "ccat" command short for "ccrypt cat"
installable through "ccrypt" on debian based systems.

------
ryanartecona
Huge missed opportunity to name this thing `scat`, and claim the poop emoji as
a logo.

------
kiddico
I've always used vimcat. It's pretty damn slow, but I don't mind.

~~~
tekromancr
Same here! I never had issues with it being slow, however. Maybe I just
haven't tried to vimcat a file that was large enough to matter.

~~~
kiddico
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.

------
kerny
I'm using vimcat for this. Available as part of vimpager
[https://github.com/rkitover/vimpager](https://github.com/rkitover/vimpager)

------
kmfrk
Big fan of hicat myself:
[https://github.com/rstacruz/hicat](https://github.com/rstacruz/hicat).

------
pankajdoharey
What i usually have done for years is this :

sudo apt-get install python-pygments; alias ccat='pygmentize'

then :

ccat program.js

ccat loader.rb #etc...

------
xupybd
Been using this for a while
[http://www.vim.org/scripts/script.php?script_id=4325](http://www.vim.org/scripts/script.php?script_id=4325)

------
boomlinde
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.

------
amelius
I'm so glad my brain does the syntax highlighting for me.

~~~
chrisan
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.

