Photo by Brian McGowan / Unsplash

Bash - Starship Prompt

Bash Jun 1, 2022

The customization of a prompt is very often just some "optical enhancements". Some colors here and maybe some behavior there. If you want to have additional functionality, you may want to have a look at Starship. A blazing fast prompt with lots of cool features.

Starship

The Starship Prompt is fast, customizable and packed with features. It also supports multiple shells, but I will focus on Bash for this article.

Integrations

Other prompts offer things like a Git indicator or coloring, based on the user. Starship can do the same, but also much more. It can detect various settings and the context of your working directory to show all kind of things like:

Screenshot - Tilix + Starship Prompt

Fast and minimal

By default, the prompt is as fast (or even faster) than Powerline-Go. This makes it a breeze to use, since you will never wait that your prompt is ready.

It comes in a really minimal way. All modules can be enabled or disabled to your personal liking.

Customizable

When it comes to customizations, you can tweak the behavior, modules and optical setup in nearly every way. Even better, you can do this with a quite simple TOML configuration file.

💡
This guide is tested on Fedora 36 with Starship 1.2.1.

Installation

So, how do you get it installed and running?

Starship uses so called Nerdfonts to display symbols and enhanced characters. Nerdfonts are patched sets of Fonts that allow these special characters. As a prerequisite, you should ensure that one is installed on your system and your terminal is configured to use these.

I opted for FiraCode. You just need to download the ZIP archive and install one of the fonts, that you like. Afterwards, you can configure the font in your Terminal. You can also configure the new Font via GNOME Tweaks, so it is used for all Monospace characters.

Screenshot - GNOME Tweaks

Starship is already packaged for Fedora and the installation is just a command away.

# Install starship
$ sudo dnf install starship

Afterwards, you can enable the prompt for your current user with a simple addition to the end of your .bashrc file.

# .bashrc

...SNIP...

eval "$(starship init bash)"
~/.bashrc

Afterwards, you can start to enjoy and customize your prompt.

Customization

By default, Starship comes with several modules enabled and looks pretty minimal. As already stated, you can tune this with a single configuration file. Let's explore this a bit.

First, you need to create a configuration file in your home directory.

# Create the directory (if not existing)
$ mkdir ~/.config

# Create the starship configuration file
$ touch ~/.config/starship.toml

Afterwards, you can put your configurations in there and after writing the file, the changes will be effective immediately. The below snippet is my current configuration.

# Keep the newline after each prompt
add_newline = true

# Show the battery level if under 20%
[[battery.display]]
threshold = 20

# Show the regular bash prompt symbols
[character]
success_symbol = "[\\$](bold green)"
error_symbol = "[\\$](bold red)"

# Enable the Kubernetes module
[kubernetes]
disabled = false

You can configure really everything to your liking, and all modules are documented on the Starship website.

In case you want to add your own custom functions, you can do this as described in the advanced configuration.

Presets

Configuring everything from scratch can be a huge effort. If you need some ideas, the Starship website provides some cool presets to start from.

Here you can find all the links that were helpful for me.

Starship: Cross-Shell Prompt
Starship is the minimal, blazing fast, and extremely customizable prompt for any shell! Shows the information you need, while staying sleek and minimal. Quick installation available for Bash, Fish, ZSH, Ion, Tcsh, Elvish, Nu, Xonsh, Cmd, and Powershell.
Nerd Fonts - Iconic font aggregator, glyphs/icons collection, & fonts patcher
Iconic font aggregator, collection, & patcher: 3,600+ glyph/icons, 40+ patched fonts: Hack, Source Code Pro, more. Popular glyph collections: Font Awesome, Octicons, Material Design Icons, and more
Customize your Bash prompt on Linux with Starship
Explore how the principles behind open source--collaboration, transparency, and rapid prototyping--are proven catalysts for innovation.

Conclusion

Starship really impressed me. I already switched it to my defaults and will ensure to update my Dotfiles repository and the Ansinle whiletruedoio.general bash role very soon.

Which prompt do you use? How have you customized it? I would love to get a screenshot or configuration preset that demonstrates your prompt.

Tags

Daniel Schier

Just a guy doing stuff. Mostly #FLOSS like #Linux, #Ansible, #Podman, #k8s, #Python, #Nextcloud or whatever comes next.