Customizing Your Shell with Starship: A Modern, Fast, and Customizable Prompt
Your command-line interface (CLI) is one of the most important tools in your development workflow. If you spend a significant amount of time in the terminal, why not make it more efficient and visually appealing? This is where Starship comes in — a blazing-fast, highly customizable, and minimalistic prompt designed for any shell. Whether you’re using Bash, Zsh, Fish, or something else, Starship brings flexibility, functionality, and beauty to your terminal experience.
In this article, we’ll explore how to get started with Starship, customize it, and take full advantage of its features to boost your productivity.
What is Starship?
Starship is a cross-shell prompt that works on almost any shell. It’s written in Rust, which makes it fast and efficient. The idea behind Starship is simple: give users an easy way to create a personalized, feature-rich prompt that works out of the box and can be easily tweaked.
Starship displays essential information about your environment, including:
- Current Git branch and status
- Python, Node.js, Go, and Rust versions in the current directory
- Kubernetes context
- Battery level
- Command execution time
- And much more
Now, let’s dive into how you can install and customize Starship for your shell.
Installing Starship
1. Prerequisites
Before installing Starship, ensure you have a shell and a package manager installed. If you’re on Linux, MacOS, or WSL, this is typically already set up.
2. Installation
Starship provides installation instructions for different platforms. Here’s how you can install it using a package manager:
Install Latest Version
With Shell:
curl -sS https://starship.rs/install.sh | sh
Homebrew (macOS/Linux):
brew install starship
Scoop (Windows):
scoop install starship
You can also install Starship via other methods like `curl`, or check the official installation guide for your specific setup.
3. Adding Starship to Your Shell
Once installed, you need to add Starship to your shell configuration file. This step ensures that Starship is loaded when you open a new terminal window.
- For Bash, add this line to your .bashrc:
eval "$(starship init bash)"
2. For Zsh, add this to your .zshrc:
eval "$(starship init zsh)"
3. For Fish, add this to your config.fish:
starship init fish | source
Afterward, restart your terminal or run
source ~/.bashrc
(or your shell’s equivalent) to load Starship.
Customizing Starship:
Out of the box, Starship is minimalistic but functional. To unlock its full potential, you’ll want to customize it. All of Starship’s configurations are done in a simple TOML file.
1. Create the Configuration File
The configuration file is usually placed in your home directory under .config/starship.toml. You can create it using:
mkdir -p ~/.config && touch ~/.config/starship.toml
2. Basic Customization
Starship’s prompt is modular, meaning you can enable or disable specific sections or customize how they appear. Below is an example of a basic configuration that changes the appearance of the prompt:
# ~/.config/starship.toml
# Customize the prompt symbol
[character]
symbol = "➜"
success_symbol = "[✔](bold green)"
error_symbol = "[✗](bold red)"
# Show the current directory
[directory]
truncation_length = 3
In this configuration:
- The character module customizes the command prompt symbol (`➜` by default).
- The `directory` module controls how the current directory is displayed. By setting `truncation_length = 3`, Starship shows only the last three directories in the path.
3. Advanced Customization
Let’s take it a step further with more advanced customizations, such as displaying programming language versions or battery levels.
# ~/.config/starship.toml
# Change Node.js version display
[nodejs]
format = "via [ $version](bold green) "
# Display Python virtual environment
[python]
symbol = "🐍 "
# Show battery status
[battery]
threshold = 10
format = "🔋 $percentage%"
Here’s what these configurations do:
- The node.js module displays the Node.js version in a bold green format with a custom symbol.
- The python module adds a Python snake icon when a virtual environment is activated.
- The battery module displays the battery percentage when it’s below 10%.
These are just a few examples of what’s possible with Starship. You can find the full list of modules and their customizable options in the Starship documentation.
Using Starship with Git
One of the most useful features of Starship is its Git integration. It shows you the current branch, whether you have staged changes, untracked files, and more.
Here’s an example configuration for Git:
# ~/.config/starship.toml
[git_branch]
symbol = "🌿 "
[git_status]
staged = "[+](green)"
untracked = "[?](red)"
modified = "[*](yellow)"
Now, whenever you’re in a Git repository, Starship will display the current branch with a leaf symbol and show the status of your files using symbols for staged, modified, or untracked files.
Performance Considerations
Starship is incredibly fast because it only runs the modules you configure. However, if you have many modules that require external commands (like checking the version of a programming language), it can slow down your prompt slightly. To avoid this, you can fine-tune the modules you load based on the directories you’re working in.
For example, you can configure Starship to only show the node.js version if a package.json file exists in the current directory:
[nodejs]
disabled = false
This way, Starship won’t run unnecessary checks when you’re not in a Node.js project.
Final Thoughts
Starship is an excellent choice for developers who want a fast, modern, and customizable shell prompt. Its ease of use and extensive configuration options make it perfect for both beginners and advanced users.
If you haven’t already, give Starship a try! It’s a game-changer for anyone who spends time in the terminal. By tweaking it to show only the information you need, you’ll have a clean, informative, and efficient CLI experience.
Head over to Starship’s website to get started, and start customizing your shell today.
— -
Feel free to share your favorite Starship configurations or tips in the comments!