Unix – Syntax highlighting/colorizing cat

color-schemesyntax highlightingunix

Is there a method to colorize the output of cat, the way grep does.

For grep, in most consoles it displays a colored output highlighting the searched keywords. Otherwise, you can force it by calling grep --color
Is there a generic way to color the output of any program according to your personal choice.

From what I understand, the program itself is not responsible for the colors. It is the shell.

I am using the default shell in FreeBSD 5.2.1 which looks like it has never seen colors since epoch.

Best Answer

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'
Related Topic