Pigmentize and Ubuntu terminal
Quick post about how to configure pygmentize to be usable in the default Ubuntu terminal. Writing this up because I wanted to post a screenshot of some code on Twitter.
Pygmentize is a command-line syntax highlighter that comes with Pygments. The default style only works well on a light background. When you use it in the default Ubuntu terminal the result is difficult to read and ugly. Normally I don’t change a lot of defaults on my system. But this is clearly unusable and needs be fixed. This is what it looks like with the default settings.
There is not enough contrast which makes it difficult to read. We need a style that works well on a dark background. Luckily Pygments ships with a couple of dark styles such as monokai, rrt, fruity, vim and native. After trying them out I decided on fruity, which looks like this.
Let’s also add some linenumbers and make it easier to call from the command line. Add the following to your ~/.bashrc
file.
function ccat() {
pygmentize -O style=fruity $1 | cat -n
}
Now you can use the ccat
command and the result will look like this.