Skip to content

bat

A cat clone that highlights syntax, shows Git modifications in the gutter, and pages automatically.

Homebrew formula Direct download

What it does

bat prints files with syntax highlighting for a few hundred languages, line numbers, a header, and +/~/- markers in the gutter for Git-tracked changes. Output longer than a screen goes through a pager; piped output is plain, so bat file | grep x still behaves.

bat hugo.yaml
bat -r 40:80 Makefile      # line range
bat --diff                  # only changed lines

Wiring it in

export MANPAGER="sh -c 'sed -e s/.\\[[0-9]*m//g | bat -p -l man'"
alias cat='bat --paging=never'

bat --list-themes shows the themes; --theme or BAT_THEME selects one.

Alternative to

AlternativeTypeTrade-off
catBuilt inThe right tool when the output is being piped
less -RBuilt inPaging with colour, no syntax highlighting
pygmentize—Highlighting via Python, slower, more languages
deltaOpen sourceThe same author’s sibling idea applied to git diff

Install

brew install bat

Links

This post is licensed under CC BY 4.0 by the author.
Last updated on