bat

bat – super charged cat – my favorite colorizer

Last Updated on September 1, 2020

I stumbled upon the bat utility rather inadvertently. I’m a devoted user of insect, a high precision scientific calculator supporting physical units. insect is written by David Peter. While looking through David’s GitHub repositories, I noticed bat had received considerable attention (and stars). My interest was aroused. So what’s bat?

bat is a drop-in replacement for the cat command adding advanced syntax highlighting and Git integration to show file modifications. It’s a really useful utility that is a massive leap up from cat. bat’s written in the Rust programming language.

For anyone new to Linux, cat is a frequently used commands on Unix-like operating systems. It has three related functions with regard to text files: displaying them, combining copies of them and creating new ones. The most common use of cat is to read the contents of files. The name comes from its function to concatenate (i.e. join) files.

Installation

The project provides 32 and 64 bit packages for Debian, as well as the usual tarballs. Compiling the source on my Ubuntu system proceeded smoothly.

In operation

Luke Baker published an interesting feature on castero, a command-line podcast player written in Python. Here’s one of its Python source files beautifully colorized by bat.

bat

Python is one of the many languages that are supported. See the end of this article for a complete list of supported programming and markup languages.

Besides colorizing programming code, bat also communicates with git to show modifications with respect to the index. And there’s the ability to pipe its own output to less if the output is too large for one screen.

bat uses the syntect library for syntax highlighting. syntect is a popular syntax highlighting library for Rust that uses Sublime Text syntax definitions.

There’s a variety of themes available for bat if you’re so inclined. The themes are DarkNeon, Default, GitHub, Monkai Extended, Monokai Extended Bright, Monokai Extended Light, Monokai Extended Origin, and TwoDark.

Other features include:

  • Gutter – shows line numbers and changes.
  • Automatic paging by integrating with less.
  • Support for text wrapping. Lines automatically wrap at a character boundary. The gutter as well as syntax coloring also wraps.
  • Support for bold, italic and underline font styles.
  • Support for writing to non-interactive terminals (pipes, files, ..).
  • Extensible (languages, themes).
  • 32 bit and 64 bit systems are supported.

Summary

bat receives my strongest recommendation. It’s such a useful utility that you’ll wonder how you managed without it.

Website: github.com/sharkdp/bat
Support: David Peter’s website
Developer: David Peter and contributors
License: Apache License Version 2.0 or MIT

bat is written in Python. Learn Python with our recommended free books and free tutorials.

Supported languages:

Bat Languages

Bat Languages


Related Software

Alternatives to cat
batSuper charged cat - Features in our Top 100 CLI Apps
mdcatSophisticated Markdown rendering for the terminal - Features in our Top 100 TUI Apps
grcatFrontend for generic colouriser grc
tacConcatenate and print files in reverse
ccatColorizing cat
seeCute cat replacement
lolcatAdd some zest to the cat command. Features in our Linux Candy series
katcat command that almost tastes like chocolate
meowRenders text using your existing Neovim configuration
mcatExtended cat command
batdoccat for Office documents and PDFs
umberDesigned to replace cat for reading source code and other text files
rucatAimed at developers and system administrators
peekMulti-buffer terminal pager
Best Free and Open Source Software Explore our comprehensive directory of recommended free and open source software. Our carefully curated collection spans every major software category.

This directory is part of our ongoing series of informative articles for Linux enthusiasts. It features hundreds of detailed reviews, along with open source alternatives to proprietary solutions from major corporations such as Google, Microsoft, Apple, Adobe, IBM, Cisco, Oracle, and Autodesk.

You’ll also find interesting projects to try, hardware coverage, free programming books and tutorials, and much more.

Discovered a useful open source Linux program that we haven’t covered yet? Let us know by completing this form.
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Oscar D
Oscar D
7 years ago

I’ve been using Pygments for a long time, but bat seems worth trying. Thanks!