Bat > Cat

Sep 23, 2024·
Alfonso Fortunato
Alfonso Fortunato
· 1 min read
zettelkasten

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:

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:

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

FZF with Bat

A useful integration with bat:

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:

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

Alfonso Fortunato
Authors
DevSecOps Engineer

Hi, I’m a DevSecOps Engineer who thrives at the intersection of development, security, and operations. My journey started as a Full Stack Developer, but I quickly found my calling in the infrastructure side of things, transitioning to a DevOps/Cloud Engineer role within my first year. That shift opened the door to the world of CI/CD pipelines, Kubernetes, and cloud-native technologies, and I never looked back. Today, I focus on building secure, automated, and reproducible infrastructure. I’m a firm believer in Open Source and actively contribute to the community that shaped my career.

Never Stop Learning