Bat: How to Hide the File Header

Updated

Learn how to hide the file header in bat and keep the line numbers

Bat: How to Hide the File Header

Before we start, make sure you have bat installed on your computer and your file ready in a folder. If you don't have bat yet, you can install it with Homebrew:

brew install bat

First, open your terminal and navigate to the folder that has your file. If you run bat filename on its own, bat prints a header with the file name, then the line numbers and a grid around your code.

To hide just the header, run this command:

bat --style=-header filename

Just remember to replace filename with your actual file name. The minus sign in front of header means "take this part away and keep everything else", so you still get the line numbers and the grid.

If you want something even cleaner, list only the parts you want. This one keeps the line numbers and Git changes, but drops the grid:

bat --style=numbers,changes filename

You can also use bat -p filename, which is short for --style=plain and prints just the code.

undefined

To make the header disappear every time, without typing the flag, add this line to your ~/.zshrc file:

export BAT_STYLE="-header"

Then open a new terminal window, or run source ~/.zshrc, and plain bat filename will hide the header by default.