Use Bat to Print a File with Syntax Highlighting in the terminal

Ian Jones
InstructorIan Jones

Share this video with your friends

Send Tweet
Published 2 years ago
Updated 2 years ago

bat is a cat replacement that adds syntax highlighting to file previews.

You can install bat with brew install bat

Next, you simply call bat to print out the contents.

Instructor: [0:00] I'm going to cat.zshrc. As you can see, it prints the file in plain text with no highlighting. To get highlighting on a file in your terminal, you need to install bat. You can install it on Mac with brew install bat. I already have it installed so I'm not going to run the command.

[0:27] Now, instead of cat, I can run bat.zshrc. We will get this nice file view with line numbers and highlights. If I ls-a, you can see that I have this prettier.yml file. If I bat prettier.yml, you can see that syntax highlighting works on more than just SH files.