How to get syntax highlighting for cat using pygments

Some people like to quickly have a look at short source files using cat at the terminal. It would be nice to have syntax highlighting for such a use. Though cat does not support syntax highlighting, it is easy to get a similar experience using Pygments, a syntax highlighter written in Python.

First, install Pygments using pip:

$ sudo pip install Pygments

This installs a pygmentize program, whose -g can be used to request it to guess the type of input file and apply the appropriate syntax highlighting:

$ pygmentize -g foobar.cpp

If you use this regularly, create an alias for it with a name that is easy to remember like ccat.

Tried with: Pygments 1.6, Python 2.7.3 and Ubuntu 12.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.