Skip to content
Latchkey

bat: cat With Syntax Highlighting (Plain in CI)

bat prints files like cat but adds syntax highlighting, line numbers, and a git change gutter; in CI you run it with --plain and paging off.

bat is great locally, but its defaults (a pager and decorations) are wrong for logs. The key flags for non-interactive use turn both off.

What it does

bat reads files and prints them with a syntax-highlighted, line-numbered, git-aware view, sending output through a pager (less) when the terminal is interactive. It auto-detects language from the extension or content.

Common usage

Terminal
bat src/main.rs                       # highlighted view (interactive)
bat --plain --paging=never file.log  # cat-like, no decorations, no pager
bat -pp file.txt                     # shorthand for --plain --plain
bat --color=always log.txt | head    # force color through a pipe
bat -l yaml -                         # read stdin, treat it as YAML

Options

FlagWhat it does
--plain / -pDisable decorations (line numbers, git, header)
-ppPlain AND disable the pager (most CI-friendly)
--paging never|auto|alwaysControl the pager; "never" avoids hangs
--color never|auto|alwaysForce or disable ANSI color
-l / --language <lang>Force a syntax instead of auto-detecting
--style <list>Pick decorations: numbers, grid, header, changes

In CI

There is no TTY in CI, so bat already disables the pager and color by default; but if you force --color=always to keep highlighting in logs, also force --paging=never so it never blocks. Set the env var BAT_PAGING=never once instead of repeating the flag.

Common errors in CI

"bat: command not found" on Debian/Ubuntu usually means it installed as batcat (name clash with the bacula bat tool); call batcat or symlink it. If a job hangs after a bat call, the pager is waiting on a TTY that does not exist: add --paging=never. Garbled escape codes in stored logs mean --color=always was used where plain text was expected.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →