DEV Community

Cover image for Add syntax highlighting to 'cat' in your terminal

Add syntax highlighting to 'cat' in your terminal

Rogier van den Berg
Flutter/Dart, node.js, Typescript and Ruby on Rails dev, ML enthusiast. Avid user of Google Cloud Platform. CTO/Co-founder of Embrosa
・1 min read

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!

Discussion (1)

gradam profile image
Jakub Semik

Thanks for sharing it!
There is also a similar tool called bat