Skip to content

🐱 bat

bat is a cat clone with syntax highlighting and Git integration.

🛠 Installation

bat is available in the reprepro repository.

sudo apt update
sudo apt install bat
sudo apt update
sudo apt install bat

On Debian and Ubuntu, the executable might be installed as batcat instead of bat due to a name conflict with another package. To use bat directly, you can create a symbolic link or an alias:

Symbolic Link

mkdir -p ~/.local/bin
ln -s /usr/bin/batcat ~/.local/bin/bat

Alias

echo "alias bat='batcat'" >> ~/.bashrc
source ~/.bashrc

⚙ Config

bat can be configured using a configuration file. You can find the default configuration directory by running bat --config-dir.

To set a theme permanently, you can export the BAT_THEME environment variable in your shell's configuration file (e.g., .bashrc or .zshrc).

Set Theme

export BAT_THEME="TwoDark"

You can also add new themes by creating a themes folder within bat's configuration directory and rebuilding the cache.

Add Themes

mkdir -p "$(bat --config-dir)/themes"
# Add theme files to the directory
bat cache --build

🐱 Catppuccin Theme

To install the Catppuccin theme for bat, follow these steps:

Install Catppuccin Theme

mkdir -p "$(bat --config-dir)/themes"
curl -Lo "$(bat --config-dir)/themes/Catppuccin-mocha.tmTheme" https://github.com/catppuccin/bat/raw/main/themes/Catppuccin-mocha.tmTheme
bat cache --build

To use the Catppuccin theme, set BAT_THEME to Catppuccin-mocha:

Set Catppuccin Theme

export BAT_THEME="Catppuccin-mocha"

📝 Usage

To view a file:

bat filename.txt

To not show line numbers:

bat -p config.yaml

To show line numbers:

bat -n config.yaml

To concatenate multiple files:

bat file1.txt file2.txt

Troubleshooting

When using bat and pressing Tab

Failure

bash: _get_comp_words_by_ref: command not found

This error indicates that bash-completion is not correctly set up or sourced. To resolve this, ensure the following:

  1. Install bash-completion: Make sure the bash-completion package is installed on your system.

    sudo apt install bash-completion
    
  2. Source bash_completion.sh: Verify that /etc/profile.d/bash_completion.sh is sourced in your shell's startup files (e.g., .bashrc or .profile). This file sets up the bash-completion environment.

    source /etc/profile.d/bash_completion.sh
    
  3. Run bat completion command: Ensure that the bat completion script is loaded. Add the following line to your ~/.bashrc file:

    eval "$(bat --completion bash)"
    

    After adding, reload your shell configuration:

    source ~/.bashrc
    

🔗 References