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 linesWiring 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
| Alternative | Type | Trade-off |
|---|---|---|
cat | Built in | The right tool when the output is being piped |
less -R | Built in | Paging with colour, no syntax highlighting |
pygmentize | — | Highlighting via Python, slower, more languages |
delta | Open source | The same author’s sibling idea applied to git diff |
Install
brew install bat