DEV Community

Cover image for Add syntax highlighting to 'cat' in your terminal
Rogier van den Berg
Rogier van den Berg

Posted on

Add syntax highlighting to 'cat' in your terminal

I use my terminal everyday, and frequently I am way faster with it then navigating around with my mouse in Finder.

Within your terminal the cat command is very useful to quickly peek inside a file, but when you're looking at source code, this is a bit difficult to read. I just thought "Wouldn't there be syntax highlighting for my terminal?". As it turns out, there is. 🎉

How to set it up

  • With Brew, install Pygments: brew install pygments
  • Next, add the following to your .zshrc/.bashrc file: alias cat="pygmentize -g"
  • Open a new terminal window, or source your .zshrc file: source ~/.zshrc

Now, when you e.g. run cat Dockerfile on a Dockerfile, things look very neat!

Top comments (1)

Collapse
 
gradam profile image
Jakub Semik

Thanks for sharing it!
There is also a similar tool called bat
github.com/sharkdp/bat