# bat — A cat Clone with Wings and Syntax Highlighting > bat is a cat clone with wings — syntax highlighting, Git integration, automatic paging, and line numbers. A drop-in replacement for cat that shows code and configs beautifully in your terminal. Written in Rust. ## Install Save in your project root: ## Quick Use ```bash # Install brew install bat # macOS sudo apt install bat # Debian/Ubuntu (may be batcat) cargo install bat # From source ``` Basic usage: ```bash bat file.py # Pretty cat with syntax highlight bat *.md # Multiple files bat --plain file # Disable decorations bat --theme="Monokai Extended" file # Theme bat -n file # Line numbers only bat file --diff # Show unstaged git diff markers bat --list-themes # Available themes # Pipe into bat curl -s https://api.github.com/users/williamwangai | bat -l json kubectl get pod -o yaml | bat -l yaml # As a manpager export MANPAGER="sh -c \"col -bx | bat -l man -p\"" ``` ## Intro bat is a cat(1) clone with wings. Instead of dumping file contents like cat, bat shows them with syntax highlighting, Git modifications indicator, automatic paging, and line numbers. Written in Rust by David Peter (sharkdp). A huge quality-of-life upgrade for anyone who lives in the terminal. - **Repo**: https://github.com/sharkdp/bat - **Stars**: 58K+ - **Language**: Rust - **License**: Apache 2.0 / MIT ## What bat Does - **Syntax highlighting** — 200+ languages via syntect - **Git integration** — show modified/added lines - **Automatic paging** — pipe into `less` for long files - **Line numbers** — optional - **File concatenation** — works like cat when piped - **Themes** — 20+ built-in, Sublime Text theme compatible - **fzf integration** — beautiful previews - **man pager** — render man pages with syntax ## Architecture Rust binary using `syntect` for syntax highlighting (parses Sublime .sublime-syntax files) and `less` for paging. Detects terminal capabilities (256 colors, truecolor, piped vs tty). ## Self-Hosting CLI tool, self-contained binary. ## Key Features - 200+ languages - Git diff indicators - Auto pager (less) - Customizable themes - Works as drop-in cat replacement - Can serve as man pager - fzf preview integration - Ligature-friendly output ## Comparison | Tool | Highlight | Git | Themes | |---|---|---|---| | bat | 200+ | Yes | 20+ | | cat | No | No | No | | ccat | 25 | No | Few | | pygmentize | 300+ | No | Via CLI | | rich (Python) | 100+ | No | Via lib | ## 常见问题 FAQ **Q: Ubuntu 上叫 batcat?** A: 是的。Debian 因命名冲突改为 `batcat`。可以 `alias bat=batcat` 或 `mkdir -p ~/.local/bin && ln -s /usr/bin/batcat ~/.local/bin/bat`。 **Q: 怎么设为默认 manpager?** A: 设置 MANPAGER 环境变量为 `sh -c "col -bx | bat -l man -p"`,man 页面会变得漂亮。 **Q: 自定义语法和主题?** A: 放 .sublime-syntax / .tmTheme 到 `bat --config-dir` 对应子目录,然后 `bat cache --build`。 ## 来源与致谢 Sources - GitHub: https://github.com/sharkdp/bat - License: Apache 2.0 / MIT --- Source: https://tokrepo.com/en/workflows/85b6bed3-35bd-11f1-9bc6-00163e2b0d79 Author: AI Open Source