Roland's homepage

My random knot in the Web

Use pygmentize as a colorized cat

The less command uses a programmable filter with which you can colorize its output. In this article an alias to do the same for cat is shown.

To colorize files, I use pygmentize, which is part of the pygments Python package. At the time of writing, I’m using pygments version 2.9.0.

This is the alias.

alias catp 'pygmentize -O style=solarized-dark \!*'

Let’s break it down.

The name of the alias is catp, short for cat-pygmentized.

By default, pygmentize sends output to standard output, so it acts like cat. It uses the filename to guess which lexer to use.

My terminals use the solarized-dark theme, so use the same style for pygmentize.

The !* is a history substitution, where ! indicates the last event, and * all the parameters.

For comments, please send me an e-mail.

Related articles

←  Merging local git repositories Using sed  →