Syntax highlighting/colorizing cat

Options:

pygmentize is good. I have an alias:

alias c='pygmentize -g'

but highlight is another widely available alternative is

alias cats='highlight -O ansi --force'

Installation:

You may have to install pygments using one of these:

sudo apt install python-pygments
sudo pip install pygments
sudo easy_install Pygments #for Mac user

and for highlight package which is easily available on all distributions

sudo apt install highlight
sudo yum install highlight
  • Bitbucket repo: https://bitbucket.org/birkenfeld/pygments-main
  • GitHub mirror: https://github.com/sglyon/pygments

In Action:

I'm attaching shots for both down below for a good comparison in highlightings

Here is pygmentize in action: Pygmentize highlighting on python file

and this is highlight: Highlight highlighting on python file


I'd recommend pygmentize from the python package python-pygments. You may want to define the following handy alias (unless you use ccat from the ccrypt package).

alias ccat='pygmentize -g'

Syntax highlighted cat output using pygmentize

And if you want line numbers:

alias ccat='pygmentize -g -O style=colorful,linenos=1'