Skip to content

Latest commit

 

History

History
147 lines (92 loc) · 2.43 KB

File metadata and controls

147 lines (92 loc) · 2.43 KB

bat

bat is a command-line file viewer with syntax highlighting, line numbers, Git integration, and paging.

It is used as a more readable alternative to the standard cat command.

The tool is installed through Homebrew and declared in the project Brewfile.

bat rendering the README with line numbers and syntax highlighting

Installation

It is part of the curated Homebrew environment; see Homebrew setup to install everything at once.

Install bat directly:

brew install bat

Verify the installation:

bat --version
brew list --formula | grep -x bat

Usage

Display a file:

bat README.md

Display several files:

bat README.md Brewfile

Display line numbers:

bat --number README.md

Disable paging:

bat --paging=never README.md

Syntax highlighting

bat automatically detects the file type and applies syntax highlighting.

Force a language when detection is incorrect:

bat --language yaml .pre-commit-config.yaml

List the supported languages:

bat --list-languages

Git integration

Inside a Git repository, bat can display modified lines in the gutter.

This makes it useful for reviewing configuration and documentation changes without opening an editor.

Relationship with cat

Use cat when raw, unformatted output is required in a script or pipeline.

Use bat for interactive reading in the terminal.

Avoid replacing cat globally in scripts because bat adds formatting and may invoke a pager.

Useful examples

Review the Brewfile:

bat Brewfile

Review the pre-commit configuration:

bat .pre-commit-config.yaml

Display a specific line range:

bat --line-range 20:60 README.md

Shell alias

An optional interactive alias can be added:

alias cat='bat --paging=never'

This alias should only be used interactively and should not be relied on in portable scripts.

Troubleshooting

Display all options:

bat --help

Confirm the executable path:

command -v bat

On some Linux distributions, the executable may be named batcat, but the Homebrew installation uses bat.

Rollback

Remove bat with Homebrew:

brew uninstall bat

Then remove its entry from profiles/full/Brewfile.


← Docs index · Project README