Favicon of bat

bat

bat is a cat(1) clone with syntax highlighting for many languages, Git integration showing file changes, and automatic paging for long output.

bat is a clone of the classic cat command that adds syntax highlighting, Git integration, and automatic paging on top of the same basic job of printing file contents to the terminal. It's built for developers who read source files, configs, and logs in the terminal often and want that output easier to scan than plain cat gives you.

Key features

  • Syntax highlighting: supports a large number of programming and markup languages out of the box, with the ability to add custom Sublime Text .sublime-syntax definitions for anything missing.
  • Git integration: shows modifications relative to the Git index directly in the sidebar, so you can see added, changed, or removed lines while viewing a file.
  • Automatic paging: pipes output to a pager like less when it's too large for one screen, while still behaving like plain cat when output is piped elsewhere.
  • Non-printable character display: the -A/--show-all flag reveals and highlights non-printable characters in a file.
  • Configurable output style: components like line numbers, file headers, grid lines, and change markers can be toggled individually via --style.
  • Theme support: ships with themes such as Monokai Extended by default, auto-selects based on terminal background, and supports custom .tmTheme themes.
  • Tool integrations: works as a preview command for fzf, a printer for ripgrep results via batgrep, a colorizing man pager, and a --help colorizer.
  • Configuration file: settings can be saved permanently in a config file (generated with --generate-config-file) instead of passed as flags every time, and a systemwide config file is also supported.
  • Dark mode awareness: on macOS and GNOME, bat can be wired up to switch themes automatically based on the OS's light/dark setting.

Ideal use cases

bat is a good fit for anyone who wants a nicer default for viewing files in the terminal, whether that's aliasing it over cat, using it as a git diff/git show colorizer, or wiring it into fzf or ripgrep as a preview pane. It's especially useful if you spend a lot of time reading code or config files in a terminal with truecolor support.

It's not meant to replace a text editor, since it's read-only output rather than an editing tool, and it's not the best choice for scripting where you need guaranteed plain output (the --plain flag or piping bypasses the decorations, but a plain cat is simpler for that job). On terminals without truecolor support, some default themes look worse, so picking one of the 8-bit themes matters more there.

Installation

bat is packaged for most major systems. A few examples from the README:

Ubuntu/Debian:

sudo apt install bat

(on some older releases the binary is named batcat instead of bat)

Arch Linux:

pacman -S bat

Fedora:

dnf install bat

macOS or Linux via Homebrew:

brew install bat

Windows via WinGet:

winget install sharkdp.bat

To build from source, you need Rust 1.79.0 or higher:

cargo install --path . --locked

or, from crates.io:

cargo install --locked bat

Prebuilt binaries, including statically-linked musl builds, are also available from the GitHub releases page for a wide range of architectures.

Once installed, bat --list-themes and bat --list-languages show what's available, and bat --config-file prints the path to your configuration file for that system. The project also documents troubleshooting steps for common issues: garbled output from files containing raw ANSI escape sequences can be fixed with --strip-ansi=auto or by disabling highlighting and wrapping, and non-UTF-8 files typically need converting with iconv first since encodings can't reliably be auto-detected.

For untrusted input specifically, the --sanitize option goes further than --strip-ansi alone, also replacing terminal-active control bytes and Unicode formatting characters that could otherwise manipulate the terminal display. The project maintains a small, named group of maintainers, and security issues can be reported through the process documented in SECURITY.md rather than as a public issue.

Categories:

Frequently asked questions

Share:

Stars
59.6K
Forks
1.6K
Last commit
8 days ago
Repository age
8 years
License
Apache-2.0
Self-hosted
No
Activity score
85/100
View Repository
Built with:

Similar to bat

Favicon

 

  
  
Favicon

 

  
  
Favicon