| name | cli-bat |
| description | Covers effective use of bat, the syntax-highlighting cat replacement, for viewing files, previewing diffs, using as a MANPAGER, integrating with fzf previews, and customizing themes. Activates when the user asks about bat, syntax-highlighted file viewing, or replacing cat/less.
|
bat — cat with Syntax Highlighting
Repo: https://github.com/sharkdp/bat
A cat clone with syntax highlighting, Git integration, line numbers, and
automatic paging. Drop-in replacement for cat with a much better reading
experience for source code, configs, and diffs.
When to Activate
Manual triggers:
- "How do I use bat?"
- "Syntax highlight a file in the terminal"
- "Better cat / better less"
- "View a file with line numbers"
Auto-detect triggers:
- User wants to view source files with highlighting in the terminal
- User is building fzf previews that need syntax highlighting
- User wants to use bat as a pager for man pages or git diff
- User wants to inspect non-printable characters in a file
- User wants to view only a range of lines from a large file
Key Commands
Basic Usage
bat file.py
bat file1.py file2.py
bat -l json file.txt
bat -n file.py
bat -A file.py
bat -p file.py
bat --diff file.py
bat -r 10:50 file.py
bat -r 10: file.py
bat -r :50 file.py
bat --list-languages
bat --list-themes
Output Control
bat -P file.py
bat --paging=never file.py
bat --paging=always file.py
bat --wrap=never file.py
bat --tabs 4 file.py
bat --style=plain file.py
bat --style=numbers,header file.py
Theming
bat --theme=TwoDark file.py
bat --theme=ansi file.py
bat --theme=GitHub file.py
BAT_THEME="TwoDark" bat file.py
bat --list-themes | fzf
Advanced Patterns
Use bat as MANPAGER
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
export MANROFFOPT="-c"
man ls
man grep
Use bat as Git Diff Pager
git diff | bat --language=diff
git diff HEAD | bat -l diff --style=plain
git config --global core.pager "bat --style=plain"
git config --global pager.diff "bat"
git config --global pager.log "bat"
fzf Preview Integration
fzf --preview 'bat --color=always {}'
rg --line-number '' | fzf \
--delimiter ':' \
--preview 'bat --color=always --highlight-line {2} {1}' \
--preview-window 'up,60%,border-bottom,+{2}+3/3'
rg --line-number '' | fzf \
--delimiter ':' \
--preview 'bat --color=always --highlight-line {2} {1}' | \
awk -F: '{print "+"$2" "$1}' | xargs $EDITOR
Piping from curl / Remote Files
curl -s https://api.example.com/data | bat -l json
curl -s https://raw.githubusercontent.com/.../script.sh | bat -l sh
http GET api.example.com/endpoint | bat -l json
Custom Themes
bat --config-dir
mkdir -p $(bat --config-dir)/themes
bat cache --build
bat --theme=MyTheme file.py
bat Config File
--theme=TwoDark
--style=numbers,changes,header
--paging=auto
--map-syntax "*.conf:INI"
--map-syntax "*.env:Dotenv"
--map-syntax "Dockerfile*:Dockerfile"
Show Non-Printable Characters
bat -A file.txt
bat -A *.sh
Practical Examples
Daily Workflows
bat ~/.ssh/config
bat /etc/hosts
bat package.json
bat -r -20: app.log
diff <(bat -p file1.py) <(bat -p file2.py)
bat -r 10:30 -p main.py | pbcopy
Aliases (add to .bashrc/.zshrc)
alias cat='bat --paging=never'
alias catp='bat -p --paging=never'
alias batn='bat -n'
alias bata='bat -A'
Chaining with Other Skills
- fzf (cli-fzf): Use
--preview 'bat --color=always {}' to get syntax-highlighted previews inside any fzf selection UI
- fd (cli-fd):
fd -e py | xargs bat to view all Python files with highlighting; fd -e md | fzf --preview 'bat --color=always {}' for interactive selection
- ripgrep (cli-ripgrep): Combine rg's line-number output with bat's
--highlight-line for pinpoint preview of search matches
- git: Set
core.pager=bat or pager.diff=bat for syntax-highlighted git output across all git commands