A special thank you goes to our biggest <a href="doc/sponsors.md">sponsors</a>:<br> <a href="https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=bat&utm_source=github"> <img src="doc/sponsors/workos-logo-white-bg.svg" width="200" alt="WorkOS"> <br> <strong>Your app, enterprise-ready.</strong> <br> <sub>Start selling to enterprise customers with just a few lines of code.</sub> <br> <sup>Add Single Sign-On (and more) in minutes instead of months.</sup> </a>
<a href="https://www.warp.dev/?utm_source=github&utm_medium=referral&utm_campaign=bat_20231001"> <img src="doc/sponsors/warp-logo.png" width="200" alt="Warp"> <br> <strong>Warp is a modern, Rust-based terminal with AI built in<br>so you and your team can build great software, faster.</strong> <br> <sub>Feel more productive on the command line with parameterized commands,</sub> <br> <sup>autosuggestions, and an IDE-like text editor.</sup> </a>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 side bar):

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.md
Display multiple files at once
> bat src/*.rs
Read 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 | bat
Read from stdin, specify the language explicitly
> yaml2json .travis.yml | json_pp | bat -l json
Show and highlight non-printable characters:
> bat -A /etc/hosts
Use 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 bats --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 bat
ripgrepWith 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 log
Note 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 rs
git 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 | xargs 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 | xclip
bat 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="sh -c 'col -bx | bat -l man -p'" man 2 select
(replace bat with batcat if you are on Debian or Ubuntu)
It might also be necessary to set MANROFFOPT="-c" if you experience
formatting problems.
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.
Also, note that this will not work with Mandocs man implementation.
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'
This way, you can keep on using cp --help, but get colorized help pages.
Be aware that in some cases, -h may not be a shorthand of --help (for example with ls).
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 bat
Important: If you install bat this way, please note that the executable may be installed as batcat instead of bat (due to a name
clash with another package). 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/bat
.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 architecture
You can install the bat package
from the official sources, provided you have the appropriate repository enabled:
apk add bat
You can install the bat package
from the official sources:
pacman -S bat
You can install the bat package from the official Fedora Modular repository.
dnf install bat
You can install the bat package from dev-kit.
emerge sys-apps/bat
You can install the bat package
from the official sources:
emerge sys-apps/bat
You can install bat via xbps-install:
xbps-install -S bat
You can install bat via pkg:
pkg install bat
You can install a precompiled bat package with pkg:
pkg install bat
or build it on your own from the FreeBSD ports:
cd /usr/ports/textproc/bat make install
You can install bat package using pkg_add(1):
pkg_add bat
You can install bat using the nix package manager:
nix-env -i bat
You can install bat using Flox
flox install bat
You can install bat with zypper:
zypper install bat
There 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 bat
Or install bat with MacPorts:
port install bat
There 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 package.
You can install bat via WinGet:
winget install sharkdp.bat
You can install bat via Chocolatey:
choco install bat
You can install bat via scoop:
scoop install bat
You 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.70.0 or
higher. You can then use cargo to build everything:
cargo install --locked bat
Note that additional files like the man page or shell completion
files can not be installed in this way. They will be generated by cargo and should be available in the cargo target folder (under build).
Use bat --list-themes to get a list of all available themes for syntax
highlighting. To select the TwoDark theme, call bat with the
--theme=TwoDark option or set the BAT_THEME environment variable to
TwoDark. Use export BAT_THEME="TwoDark" in your shell's startup file to
make the change permanent. Alternatively, use bats
configuration file.
If you want to preview the different themes on a custom file, you can use
the following command (you need fzf for this):
bat --list-themes | fzf --preview="bat --theme={} --color=always


职场AI,就用扣子
AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!


多风格AI绘画神器
堆友平台由阿里巴巴设计团队创建,作为一款AI驱动的设计工具,专为设计师提供一站式增长服务。功能覆盖海量3D素材、AI绘画、实时渲染以及专业抠图,显著提升设计品质和效率。平台不仅提供工具,还是一个促进创意交流和个人发展的空间,界面友好,适合所有级别的设计师和创意工作者。


零代码AI应用开发平台
零代码AI应用开发平台,用户只需一句话简单描述需求,AI能自动生成小程序、APP或H5网页应用,无需编写代码。


免费创建高清无水印Sora视频
Vora是一个免费创建高清无水印Sora视频的AI工具


最适合小白的AI自动化工作流平台
无需编码,轻松生成可复用、可变现的AI自动化工作流

大模型驱动的Excel数据处理工具
基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度 保持在0.8秒以内,支持超过100万行数据的即时分析。


AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。


AI论文写作指导平 台
AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。


AI一键生成PPT,就用博思AIPPT!
博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。


AI赋能电商视觉革命,一站式智能商拍平台
潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。
最新AI工具、AI资讯
独家AI资源、AI项目落地

微信扫一扫关注公众号