How to Install and Use bat-extras in Linux for Syntax-Highlighted Terminal Utilities

While the popular command-line utility bat serves as a modern, syntax-highlighted replacement for the traditional cat command, developers frequently wish that same clean syntax formatting and Git integration extended across other everyday terminal tools. The bat-extras project is an official collection of lightweight bash wrapper scripts designed to integrate bat into manual page viewing, text searching, git diffing, command monitoring, and code formatting.

The bat-extras Tool Suite Overview

The bat-extras repository bundles five primary standalone CLI utilities:

  • batman: Uses bat as a syntax-highlighted viewer for system manual (man) pages, formatting headers, code examples, and command options with rich readability.
  • batgrep: Combines ripgrep (rg) with bat to print search matches accompanied by full syntax highlighting, context lines, and line numbers.
  • batdiff: Integrates with git diff to render color-highlighted file differences directly inside your terminal pager.
  • batwatch: Replaces the classic watch command to monitor changes in files or terminal commands over time with colored highlighting.
  • prettybat: Formats code files using language-specific formatters (such as prettier, rustfmt, or shfmt) and pipes the result into bat.

Installing Prerequisites on Linux

Before installing bat-extras, verify that bat (and optionally ripgrep and git) are installed on your distribution:

Ubuntu, Debian, and Linux Mint

sudo apt update
sudo apt install bat ripgrep git
# Note: On Debian/Ubuntu, the bat executable is named 'batcat'
# Create a symlink if necessary:
mkdir -p ~/.local/bin
ln -s /usr/bin/batcat ~/.local/bin/bat

Fedora, RHEL, and AlmaLinux

sudo dnf install bat ripgrep git

Arch Linux and Manjaro

sudo pacman -S bat ripgrep git

Installing bat-extras on Linux

Depending on your distribution and preference, you can install bat-extras via package managers or directly from source:

Installing on Arch Linux (AUR)

Arch users can install bat-extras directly from the AUR using yay or paru:

yay -S bat-extras

Installing from Source via Git (Any Distribution)

To install across Ubuntu, Debian, Fedora, or openSUSE:

  1. Clone the official GitHub repository:
    git clone --depth 1 https://github.com/eth-p/bat-extras.git /tmp/bat-extras
  2. Run the automated installation script into your user binary directory:
    cd /tmp/bat-extras
    ./build.sh --install --prefix="$HOME/.local"
  3. Verify that ~/.local/bin is in your shell $PATH:
    echo $PATH | grep -q "$HOME/.local/bin" || echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
  4. Reload your shell:
    source ~/.bashrc

Core bat-extras Commands and Daily Syntax Examples

The table below summarizes the most practical commands provided by bat-extras:

Utility Example Syntax Functional Description
batman batman tar Opens the tar manual page formatted with full color coding and syntax themes.
batgrep batgrep --context 3 "connectDB" src/ Recursively searches files for “connectDB” and displays matches inside colored code blocks.
batdiff batdiff server.js Displays git-staged or working-tree file modifications with syntax highlighting.
batwatch batwatch --interval 2 --file app.log Watches a target log file, updating every 2 seconds with line numbers and syntax themes.
prettybat prettybat config.json Beautifies JSON, HTML, or code and prints formatted syntax output to terminal.

Replacing Default System Man with batman

To automatically view all manual pages with batman whenever you run the standard man command, configure an alias in your shell profile (~/.bashrc or ~/.zshrc):

# Use batman as default manual page viewer
alias man="batman"

After saving and sourcing your configuration, running man curl or man iptables will instantly open rich, syntax-highlighted documentation complete with searchable navigation.

Using batgrep for Fast Code Searches

Unlike raw grep, which outputs solitary matching lines with minimal context, batgrep mirrors a code editor interface:

batgrep -p -A 5 -B 2 "export default" ./components
  • -p: Plain mode without excessive borders, ideal for piping into other tools.
  • -A 5 -B 2: Prints 2 lines before and 5 lines after every match, fully colorized with language-aware keyword highlighting.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.