Most developers rely on cat for viewing files in the terminal, but it lacks syntax highlighting and modern features. Enter bat—a drop-in replacement that transforms plain text into beautifully formatted, syntax-highlighted code with minimal effort.
Why Replace ‘cat’ with ‘bat’?
cat is a basic Unix utility for concatenating and displaying files. While it’s reliable for simple text, it struggles with modern development needs. Without syntax highlighting, reading code or config files becomes tedious, especially in large projects.
Limitations of Traditional ‘cat’
The cat command outputs raw text with no formatting. This makes it hard to distinguish code elements like variables, functions, or comments. For example, viewing a JSON or Python file with cat shows uniform white text, forcing developers to squint or open editors for readability.
Additionally, cat lacks line numbers, pagination, and Git diff integration—features that are critical for efficient code navigation and debugging.
Benefits of ‘bat’
bat (short for “cat with bat”) solves these issues with elegant syntax highlighting, automatic pagination, and seamless integration with your terminal workflow. It supports over 100 programming languages and file formats out of the box, making it a versatile tool for any developer.
Unlike cat, bat automatically detects file types and applies appropriate highlighting. It also includes line numbers, Git change indicators, and a built-in pager for scrolling through large files—without needing separate tools like less.
Installing bat on Your System
Installing bat is straightforward across major platforms. Here’s how to get started:
- macOS: Use Homebrew:
brew install bat - Linux: Install via package manager (e.g.,
sudo apt install batfor Debian/Ubuntu) - Windows: Use Winget:
winget install sharkdp.bator download from the GitHub releases page
After installation, verify with bat --version. Replace cat with bat by creating an alias in your shell config (e.g., alias cat='bat' in .bashrc or .zshrc).
Basic bat Commands for Syntax Highlighting
Using bat is as simple as replacing cat with bat in your commands. Here are common use cases:
- View a Python file:
bat app.pyshows syntax-highlighted code with line numbers - Display Git diff:
git diff | bathighlights changes in color - View a JSON file:
bat config.jsonformats and colors the JSON structure
For large files, bat automatically uses a pager (like less), so you can scroll through content without overwhelming your terminal.
Advanced Features and Customization
Take bat further with these powerful features:
Custom Themes and Styles
Choose from built-in themes like “ansi”, “gruvbox”, or “monokai” using bat --theme="gruvbox". Set your default theme in the ~/.config/bat/config file for consistent styling.
Git Integration
bat shows Git annotations (e.g., changed lines) when viewing files in a repository. This helps track recent modifications without leaving the terminal.
Pager Customization
Configure the pager settings in bat‘s config file to adjust line wrapping, margins, and more. For example, enable line numbers only for code files to reduce clutter.
Integrating bat with Your Workflow
Combine bat with other developer tools for maximum efficiency:
- Use with ripgrep for syntax-highlighted search results:
rg "pattern" | bat - Pair with fzf for fuzzy-finding and viewing files:
fzf | xargs bat - Set as default for git log by configuring
core.pagerin Git
These integrations create a seamless, high-productivity terminal environment that minimizes context switching between editors and terminals.
Conclusion
Replacing cat with bat is a simple yet transformative step for any developer seeking cleaner terminal workflows. With syntax highlighting, Git integration, and customizable features, bat eliminates the friction of raw text viewing while staying lightweight and fast. Start using bat today by installing it and replacing cat with a single alias—your productivity will thank you.