← Back to tools
View AGENTS.md for bat
bat
A cat clone with syntax highlighting and Git integration
Description
bat is a cat replacement with syntax highlighting, Git integration, and automatic paging. It supports a large number of programming and markup languages and integrates with other tools as a previewer.
Install
homebrew
brew install batapt
sudo apt install batpacman
sudo pacman -S batcargo
cargo install batAI Summary
A cat(1) clone with wings. Displays files with syntax highlighting, line numbers, and git diff markers. Excellent as a previewer for other tools like fzf.
Capabilities
- + Syntax highlighting for 200+ languages
- + Git integration showing modified lines
- + Automatic paging for long output
- + Line numbers and line range selection
- + Multiple themes (can match your terminal theme)
- + Plain mode for piping (auto-detected)
Use When
- → Viewing source code files in the terminal
- → Need a syntax-highlighted previewer for fzf or other tools
- → Want to see git changes inline while viewing a file
- → Displaying code snippets with line numbers
Avoid When
- x Piping binary data (bat auto-detects, but use cat explicitly)
- x Need to concatenate files for processing (use cat)
- x Headless environments where highlighting is wasted
Usage Patterns
View a file with syntax highlighting
bat src/main.rs Displays the file with Rust syntax highlighting and line numbers
Show specific line range
bat --line-range 10:20 file.py Display only lines 10-20 of the file
Use as a previewer in fzf
fzf --preview 'bat --color=always --line-range :500 {}' Shows syntax-highlighted preview panel in fzf
View diff with syntax highlighting
bat --diff file.old file.new Shows side-by-side diff with syntax highlighting
Input / Output
stdin: Text content to display (auto-detects language if possible)
stdout: Highlighted text with ANSI colors (plain text when piped)
Exit codes:
0 Success 1 Error Typical Pipelines
fd -e py | fzf --preview 'bat --color=always {}' | xargs code rg -l 'TODO' | xargs bat --line-range :500 git diff --name-only | xargs bat --diff