Make Bash prettier on NixOS

Photo by Luca Bravo on Unsplash

Make Bash prettier on NixOS

Table of contents

Using ble.sh and Starship.

Bash by itself is pretty basic. Syntax highlighting, auto-suggestion and history matching are pretty helpful features in any shell. Users might be worried about the bloat these features bring and add delay to the startup of the shell.

I've been using these features for quite a while and have yet to see a performance hit. So it should be safe to assume you won't be having any of these problems either.

The reason why I am configuring bash instead of using other shells that have a better support these features is nix develop and nix shell expect bash and most of its functionalities are built around bash. So I do not recommend using a different shell for these.

ble.sh

ble.sh or Bash Line Editor is a command line editor written in pure Bash and replaces GNU Readline. Although it is written in Bash, it relies on POSIX stty to set up TTY states before and after the execution of user commands.

Installing ble.sh on NixOS is pretty straight forward as documented in the git repo.

# Spawn a development shell to bring in dependencies
nix develop nixpkgs#bash
# Bring build dependencies to path
nix shell nixpkgs#git nixpkgs#gnumake

# Try without installing
git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git
make -C ble.sh
source ble.sh/out/ble.sh

# Install to ~/.bashrc
git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git
make -C ble.sh install PREFIX=~/.local
echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc

Now add the following line to home.nix:

programs.bash = {
    bashrcExtra = ''
        . ~/.bashrc
    '';
};

Switch to the new configuration:

home-manager switch

Now the changes should persist across sessions.

ble.sh brings syntax highlighting, auto-completion, auto-suggestion, menu-complete and more.

Starship

Starship customizes shell prompt. The defaults are surprisingly sane for what it does. It is fast and does not get in the way. The prompt changes based on your directory. You can install it by adding it to home.nix:

home.packages = with pkgs; [ starship ];

Append the line to ~/.bashrc

eval "$(starship init bash)"

Personally, I never felt the need to change it but you can choose from the many existing configurations. Oh, and have Nerd Font enabled.

Screenshot of shell featuring Starship and ble.sh

Did you find this article valuable?

Support Aditya's blog by becoming a sponsor. Any amount is appreciated!