Cat with syntax highlighting

After I recently found out that a newer version of nano than the one that ships by default with OS X can be upgraded to a version that supports syntax highlighting, I started to be annoyed by the fact that cat didn't supported syntax highlighting.

So I did some research, turns out that with a little bit of effort and a small workaround, we can bring it to cat as well.

Note: I only tested this on OS X, but in theory this should work on Linux as well I suppose.

So basically you need to have python installed on your system (but it is by default on OS X, don't worry) and install 1 plugin. Then we create an alias for cat that's pointing to the python command and that'd be it.

If you installed Python with homebrew, run this command (if using the one that ships with your system, install with sudo)

easy_install Pygments

And now we just need to make an alias for it (change the filename to whatever you use for aliases ~/.aliases, ~/.bashrc, ~/.zshrc,..)

echo "\n# Cat with syntax highlighting\nalias cat='pygmentize -g'" >> ~/.aliases


This is the default cat command:


And this is the new one with the python alias:


Some other examples with some javascript & a shell script:



Cheers 🍻