Friday fun: bat is cat with syntax highlighting
I type cat at a terminal at least fifty times a day. It took me three years to realise there was something better.
# what I used to type
cat package.json
# what I type now
bat package.json
Same two words. But bat gives you syntax highlighting, line numbers, a git gutter, and automatic paging for long files. You get all of it without changing your workflow or adding a new command to remember.
What bat does differently
cat prints file contents to stdout with no formatting. That’s fine until you’re scanning a JSON file with 200 lines of nested objects and your eyes start crossing.
bat is a drop-in replacement that adds:
- syntax highlighting for 200+ languages and formats
- line numbers in the left gutter
- a git modification marker (shows which lines changed)
- automatic paging with less when the output is longer than your terminal
- theme support (Solarized, Dracula, Monokai, you name it)
bat --style=plain response.json
Pass --style=plain when you need to pipe the output. bat detects when stdout is not a TTY and acts like cat automatically, so scripts that use cat keep working.
Why this matters for API work
At Deepgram I spent a lot of my day looking at JSON responses from the STT API. A raw transcript looks like a blob of text. With bat I could see the structure at a glance, spot the line with the confidence score, and jump straight to it using the line numbers.
{
"results": {
"channels": [
{
"alternatives": [
{
"transcript": "hello world",
"confidence": 0.98
}
]
}
]
}
}
With cat, that all looks the same. With bat, the keys render in one colour, the strings in another, and the numbers stand out. Your brain processes the shape before you read a single word.
How to try it
# macOS
brew install bat
# Linux (most distros)
apt install bat # or your package manager equivalent
# Windows (scoop)
scoop install bat
Set an alias if you want to keep the cat muscle memory while using bat:
alias cat=bat
One line in your .zshrc or .bashrc and you’re done.
FAQ
What happens when bat is used in a script that expects cat?
bat detects non-TTY output and disables all formatting. A script that pipes cat into grep or jq works the same with bat. No surprises.
Does bat slow down for large files?
bat pages output through less automatically, so large files start rendering immediately and you scroll through them. cat dumps everything at once, which can slow your terminal down for multi-megabyte files.
Can I change the colour theme?
Yes. Run bat --list-themes to see available options, then set export BAT_THEME=Dracula in your shell config. There are dozens of themes matching common editor colour schemes.