A cat(1) clone with wings.
A cat(1) clone with syntax highlighting and Git integration.
Key Features •
How To Use •
Installation •
Customization •
Project goals, alternatives
[English]
[中文]
[日本語]
[한국어]
[Русский]
bat supports syntax highlighting for a large number of programming and markup
languages:
bat communicates with git to show modifications with respect to the index
(see left sidebar):
You can use the -A/--show-all option to show and highlight non-printable
characters:
By default, bat pipes its own output to a pager (e.g. less) if the output is too large for one screen.
If you would rather bat work like cat all the time (never page output), you can set --paging=never as an option, either on the command line or in your configuration file.
If you intend to alias cat to bat in your shell configuration, you can use alias cat='bat --paging=never' to preserve the default behavior.
Even with a pager set, you can still use bat to concatenate files :wink:.
Whenever bat detects a non-interactive terminal (i.e. when you pipe into another process or into a file), bat will act as a drop-in replacement for cat and fall back to printing the plain file contents, regardless of the --pager option's value.
Display a single file on the terminal
bat README.mdDisplay multiple files at once
bat src/*.rsRead from stdin, determine the syntax automatically (note, highlighting will
only work if the syntax can be determined from the first line of the file,
usually through a shebang such as #!/bin/sh)
curl -s https://sh.rustup.rs | batRead from stdin, specify the language explicitly
yaml2json .travis.yml | json_pp | bat -l jsonShow and highlight non-printable characters:
bat -A /etc/hostsUse it as a cat replacement:
bat > note.md # quickly create a new file
bat header.md content.md footer.md > document.md
bat -n main.rs # show line numbers (only)
bat f - g # output 'f', then stdin, then 'g'.fzfYou can use bat as a previewer for fzf. To do this,
use bat's --color=always option to force colorized output. You can also use --line-range
option to restrict the load times for long files:
fzf --preview "bat --color=always --style=numbers --line-range=:500 {}"For more information, see fzf's README.
find or fdYou can use the -exec option of find to preview all search results with bat:
find … -exec bat {} +If you happen to use fd, you can use the -X/--exec-batch option to do the same:
fd … -X batripgrepWith batgrep, bat can be used as the printer for ripgrep search results.
batgrep needle src/tail -fbat can be combined with tail -f to continuously monitor a given file with syntax highlighting.
tail -f /var/log/pacman.log | bat --paging=never -l logNote that we have to switch off paging in order for this to work. We have also specified the syntax
explicitly (-l log), as it can not be auto-detected in this case.
gitYou can combine bat with git show to view an older version of a given file with proper syntax
highlighting:
git show v0.6.0:src/main.rs | bat -l rsgit diffYou can combine bat with git diff to view lines around code changes with proper syntax
highlighting:
batdiff() {
git diff --name-only --relative --diff-filter=d -z | xargs -0 bat --diff
}If you prefer to use this as a separate tool, check out batdiff in bat-extras.
If you are looking for more support for git and diff operations, check out delta.
xclipThe line numbers and Git modification markers in the output of bat can make it hard to copy
the contents of a file. To prevent this, you can call bat with the -p/--plain option or
simply pipe the output into xclip:
bat main.cpp | xclipbat will detect that the output is being redirected and print the plain file contents.
manbat can be used as a colorizing pager for man, by setting the
MANPAGER environment variable:
export MANPAGER="bat -plman"
man 2 select(on some older Debian or Ubuntu releases, the executable is named batcat instead of bat)
If you prefer to have this bundled in a new command, you can also use batman.
Note that the Manpage syntax is developed in this repository and still needs some work.
prettier / shfmt / rustfmtThe prettybat script is a wrapper that will format code and print it with bat.
--help messagesYou can use bat to colorize help text: $ cp --help | bat -plhelp
You can also use a wrapper around this:
# in your .bashrc/.zshrc/*rc
alias bathelp='bat --plain --language=help'
help() {
"$@" --help 2>&1 | bathelp
}Then you can do $ help cp or $ help git commit.
When you are using zsh, you can also use global aliases to override -h and --help entirely:
alias -g -- -h='-h 2>&1 | bat --language=help --style=plain'
alias -g -- --help='--help 2>&1 | bat --language=help --style=plain'For fish, you can use abbreviations:
abbr -a --position anywhere -- --help '--help | bat -plhelp'
abbr -a --position anywhere -- -h '-h | bat -plhelp'This way, you can keep on using cp --help, but get colorized help pages.
[!TIP] To remove these abbreviations later, run:
abbr -e -- --help abbr -e -- -hThe
--before the abbreviation name is required because--helpand-hstart with dashes, which would otherwise be interpreted as flags toabbritself.
Be aware that in some cases, -h may not be a shorthand of --help (for example with ls). In cases where you need to use -h
as a command argument you can prepend \ to the argument (eg. ls \-h) to escape the aliasing defined above.
Please report any issues with the help syntax in this repository.
apt)... and other Debian-based Linux distributions.
bat is available on Ubuntu since 20.04 ("Focal") and Debian since August 2021 (Debian 11 - "Bullseye").
If your Ubuntu/Debian installation is new enough you can simply run:
sudo apt install batImportant: On some older Ubuntu/Debian releases, the executable is installed as batcat instead of bat (due to a name
clash with another package). On newer releases, the executable is available as bat. If bat --version does not work after installation, try batcat --version instead. You can set up a bat -> batcat symlink or alias to prevent any issues that may come up because of this and to be consistent with other distributions:
mkdir -p ~/.local/bin
ln -s /usr/bin/batcat ~/.local/bin/batan example alias for batcat as bat:
alias bat="batcat".deb packages)... and other Debian-based Linux distributions.
If the package has not yet been promoted to your Ubuntu/Debian installation, or you want
the most recent release of bat, download the latest .deb package from the
release page and install it via:
sudo dpkg -i bat_0.18.3_amd64.deb # adapt version number and architectureYou can install the bat package
from the official sources, provided you have the appropriate repository enabled:
apk add batYou can install the bat package
from the official sources:
pacman -S batYou can install the bat package from the official sources:
dnf install batYou can install the bat package
from the official sources:
emerge sys-apps/batYou can install a precompiled bat package with pkg:
pkg install bator build it on your own from the FreeBSD ports:
cd /usr/ports/textproc/bat
make installYou can install bat package using pkg_add(1):
pkg_add batYou can install bat using the nix package manager:
nix-env -i batYou can install bat with zypper:
zypper install batThere is currently no recommended snap package available. Existing packages may be available, but are not officially supported and may contain issues.
You can install bat with Homebrew:
brew install batOr install bat with MacPorts:
port install batThere are a few options to install bat on Windows. Once you have installed bat,
take a look at the "Using bat on Windows" section.
You will need to install the Visual C++ Redistributable
You can install bat via WinGet:
winget install sharkdp.batYou can install bat via Chocolatey:
choco install batYou can install bat via scoop:
scoop install batYou can download prebuilt binaries from the Release page,
You will need to install the Visual C++ Redistributable package.
Check out the Release page for
prebuilt versions of bat for many different architectures. Statically-linked
binaries are also available: look for archives with musl in the file name.
If you want to build bat from source, you need Rust 1.79.0 or
higher. You can then use cargo to build everything:
cargo install --path . --locked[!NOTE
Extend visualization of non-printables with clear and stable characters
Add `-ppp` alias that adds `--color=never`
Discussion: a builtin pager for 'bat'
displaying latex maths in a readable way
Font color not readable in light mode
Build cache on first run of `bat`
[fish] Completion breaks under subshell completion evaluation: "command $bat --list-languages": command is empty
Support mouse instead of relying on less as a pager
Man pages displaying bold reset code 22m
C23 digit separators are not supported