bat-extras: prettybat

August 24, 2024 ยท View on GitHub

Pretty-print source code and highlight it with bat.

The only thing better than syntax highlighting? Syntax highlighting and code formatting. This script combines the best of both worlds by using various formatters to format source files before using bat to highlight them.

Usage

prettybat [OPTIONS] [PATH...]

Options

Every option is passed through to bat. See man bat for more information.

Languages

LanguageFormatter
JavaScript (JS, JSX)prettier
TypeScript (TS, TSX)prettier
CSS, SCSS, SASSprettier
Markdownprettier
JSONyq, prettier
YAMLyq, prettier
HTMLprettier
SVGprettier
Rustrustfmt
Bashshfmt
CClangFormat
C++ClangFormat
Objective-CClangFormat
Pythonblack
Elixirmix format

Caveats

  • The header displayed by bat will show STDIN instead of the filename (bat 0.13 or older).
  • The git changes sidebar will not work with files that have been formatted.

Installation

This script is a part of the bat-extras suite of scripts. You can find install instructions here.

Issues?

If you find an issue or have a feature suggestion, make a pull request or issue through GitHub! Contributions are always welcome.