Working noteSep 23, 2024

Bat > Cat

Bat replaces cat

Cover graphic for Bat > Cat

The bat command enhances the behavior of cat by adding several cool features, such as:

  • Syntax highlighting: Support most of the languages
  • Git integration: Displays changes with Git.
  • Show hidden characters: with options –show-all or -A
  • Automatic paging: Similar to less, bat automatically handles long output.

To replace cat with bat, you can simply add an alias:

bash
alias cat='bat --paging never --theme DarkNeon --style plain'

The style option defines the type of output you'd like:

  • plain: Standard output (text with syntax highlighting).
  • numbers: Shows line numbers.
  • changes: Displays Git diff changes.

For standard cat, I leave the default style. However, for fzf integration, I add an alias to preview files with line numbers and Git diffs:

bash
alias fzfb='fzf --preview "bat --color always --style numbers, changes {}"'

FZF with Bat

A useful integration with bat:

zsh
tail -f /var/log/pacman.log | bat --paging=never -l log

Also with Git: Git with Bat You can customize the preview style with different themes:

bash
bat --list-themes # Default themes
# you can add others
git clone https://github.com/greggb/sublime-snazzy
# Update the binary cache
bat cache --build

More info on official git

↗ Open for work

Need the person
who ships it?

I'm looking for platform engineering and DevSecOps roles in regulated, product or cloud native teams. Kubernetes, supply-chain security and self-service platforms are the core. Also open to select technical writing and open-source collaborations.

Work with me See the experience
← All notes

Search the site

esc

Jump to

    ↑↓ to navigate ↵ to open esc to close