DEV Community

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

Posted on

3 2

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

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs