← All posts

CLI

bat: A cat Clone With Syntax Highlighting and Git Signs

bat is a cat clone with syntax highlighting, line numbers, and git change markers - a nicer way to read files.

B CLI

cat is fine for dumping a file, but the moment you're reading code in the terminal you want more: colors, line numbers, a sense of what changed. bat is a drop-in-ish replacement that adds exactly that. It syntax-highlights hundreds of languages, shows line numbers, marks git additions and modifications in the gutter, and pipes through a pager automatically for long files - while still behaving like cat when you pipe it into something else.

Reading Code, Not Just Printing It

The difference shows the first time you open a file you're trying to understand:

# Pretty-print a file with highlighting and git signs bat src/main.rs # Show a specific line range bat --line-range 40:80 config.yaml # Use it as a colorizing pager for other tools rg --json TODO | bat

Smart When Piped

bat detects whether it's talking to a terminal or a pipe: interactive gets the full decorated view, piped output stays plain so it composes cleanly. You can even wire it in as the pager for other tools to get highlighted output everywhere.

Rough Edges and Limitations

  • It's not exactly cat. Scripts depending on byte-for-byte cat behavior should call cat; bat's extras are for humans.
  • Themes need a glance. The default is good, but matching your terminal's colors may take a config tweak.
  • One more binary. A tiny thing to install on every new machine you set up.

It's a small quality-of-life upgrade that you feel every single time you read a file in the terminal.

Internal link suggestion: link "colorizing pager" to the ripgrep or delta post to build out a highlighted-output toolchain.