Syntax highlighting/colorizing cat
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'
And if you want line numbers:
alias ccat='pygmentize -g -O style=colorful,linenos=1'
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-pygmentssudo pip install pygmentssudo easy_install Pygments #for Mac user
and for highlight
package which is easily available on all distributions
sudo apt install highlightsudo 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:
and this is highlight
:
From late April 2018 onwards:
Bat - A cat(1) clone with syntax highlighting and Git integration.
The project is a cat clone with support for colors and customizations written in Rust. It offers not only syntax highlighting with multiple themes, but also Git integration. As described in the documentation:
bat tries to achieve the following goals:
- Provide beautiful, advanced syntax highlighting
- Integrate with Git to show file modifications
- Be a drop-in replacement for (POSIX) cat
- Offer a user-friendly command-line interface
It is, needless to say, much faster than pygmentize and does not choke when confronted with large files.
Source code and binary releases + installation instructions can be found in the Github repository, as well as a comparison to alternative programs.