Starship is a free opensource shell prompt available for Linux, Windows and MacOS. It is extremely fast, very light and highly customizable. It works for any shell including bash, zsh and Fish. Starship is designed to intelligently show you only the information you require while working.

In this, we will be looking at how Starship is installed and used in Linux distributions, Windows and MacOS, as well how it is configured for different shells.

Features of Starship Shell prompt

Below are some of the most eye-catching features of Starship that will make you want to try it.

  • Fast: it’s fast – really really fast!
  • Customizable: configure every aspect of your prompt.
  • Universal: works on any shell, on any operating system.
  • Intelligent: shows relevant information at a glance.
  • Feature rich: support for all your favorite tools.
  • Easy: quick to install – start using it in minutes.

Install Startship Shell Prompt

The first step is to install and enable Nerd Font in the terminal. We are going to install FiraCode Nerd Font with the below commands:

# Ubuntu 
sudo apt update
sudo apt install fonts-firacode 

# Arch Linux / Manjaro 
sudo pacman -S otf-fira-code 

# Gentoo 
emerge -av media-fonts/fira-code 

# Fedora 
dnf copr enable evana/fira-code-fonts 
dnf install fira-code-fonts

# For MacOS, download TTF using curl as below:
curl -O https://github.com/tonsky/FiraCode/blob/master/distr/ttf/FiraCode-Bold.ttf
#In the downloaded TTF folder, Select all font files, right click and select Open (alternatively Open With Font Book). Select "Install Font"
#Or Install with Brew (Not officially supported)
brew tap homebrew/cask-fonts
brew cask install font-fira-code

# Windows: Run as Administrator
scoop bucket add nerd-fonts
scoop install firacode

Installing Starship Shell Prompt

To install Starship from package manager, we run the commands below:

# macOS 
$ brew install starship 

# Arch 
$ yay -S starship 

# Nix 
$ nix-env --install starship 

# Termux 
$ pkg install starship

For other platforms, we can install Starship from a pre-compiled binary. We need to download the binary and install as below:

$ curl -fsSL https://starship.rs/install.sh | bash

 Configuration 
> Bin directory: /usr/local/bin 
> Platform:      unknown-linux-musl 
> Arch:          x86_64 

> Tarball URL: https://github.com/starship/starship/releases/latest/download/starship-x86_64-unknown-linux-musl.tar.gz 
? Install Starship latest to /usr/local/bin? [y/N] y 
! Escalated permissions are required to install to /usr/local/bin 
[sudo] password for lorna:  
> Installing Starship as root, please wait… 
✓ Starship installed 

> Please follow the steps for your shell to complete the installation: 

 Bash 
 Add the following to the end of ~/.bashrc: 

     eval "$(starship init bash)" 

 Fish 
 Add the following to the end of ~/.config/fish/config.fish: 

     starship init fish | source 

 Zsh 
 Add the following to the end of ~/.zshrc: 

     eval "$(starship init zsh)" 

 Ion 
 Add the following to the end of ~/.config/ion/initrc: 

     eval $(starship init ion)

Configure Zsh, Bash and Fish to use Starship.

As explained from the above output, configure your shell to use starship as below:

# For Bash shell, add the following to the end of ~/.bashrc: 
eval "$(starship init bash)"    

# For Fish shell,  add the following to the end of ~/.config/fish/config.fish: 
starship init fish | source  
       
# For Zsh add the following to the end of ~/.zshrc: 
eval "$(starship init zsh)" 

#For Ion add the following to the end of ~/.config/ion/initrc: 
eval $(starship init ion)

# Powershell
#For PowerShell add the following to the end of Microsoft.PowerShell_profile.ps1. Verify this file location through #querying the $PROFILE variable in PowerShell. The path should #be ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 or ~/.config/powershell/Microsoft.PowerShell_profile.ps1# on -Nix.

Invoke-Expression (&starship init powershell)

Finally update the changes by sourcing shell configuration.

# Bash
source ~/.bashrc
# zsh
source ~/.zshrc

You should have Starship installed and working.

lorna in App2 in ~  
❯ ls 
alacritty 

lorna in App2 in ~  
❯ pwd 
/home/lorna 

lorna in App2 in ~  
❯ 

Configuring Starship Shell Prompt

Starship configuration file enables us to make desired changes for using starship prompt. The configuration file is a .toml. Let’s create one in ~/.config directory.

mkdir -p ~/.config && touch ~/.config/starship.toml

Add the following content

# Don't print a new line at the start of the prompt
add_newline = false

# Replace the "❯" symbol in the prompt with "➜"
[character]                            # The name of the module we are configuring is "character"
success_symbol = "[➜](bold green)"     # The "success_symbol" segment is being set to "➜" with the color "bold green"

# Disable the package module, hiding it from the prompt completely
[package]
disabled = true

Change the default starship configuration file location using STARSHIP_CONFIG environment variable

export STARSHIP_CONFIG=~/.starship

Do the below on Windows Powershell

$ENV:STARSHIP_CONFIG = "$HOME\.starship"

Now exit the terminal and login back. You should notice the change with prompt sign

lorna in App2 in ~ 
➜ ls
alacritty
lorna in App2 in ~ 
➜ pwd
/home/lorna
lorna in App2 in ~ 
➜ 

Starship Modules

A module is a prompt component which provides information based on contextual information from your OS. There are quite a number of modules that are important which using the command line and you can configure how you would like them to appear on the terminal. All configurations are dome in starship.toml file. We are going to discuss only a few of these modules.

AWS

Shows the current AWS region and profile basing on AWS_REGIONAWS_DEFAULT_REGION, and AWS_PROFILE env var with ~/.aws/config file. You can use various options and variables to configure in starship.toml file.

Options

Some options for AWS module configuration are:

OptionDefaultDescription
format‘on [$symbol$profile(\($region\))]($style) ‘The format for the module.
symbol“☁️ “The symbol used before displaying the current AWS profile.
region_aliasesTable of region aliases to display in addition to the AWS name.
style“bold yellow”The style for the module.
disabledfalseDisables the AWS module.
Variables

Some variables to use:

VariableExampleDescription
regionap-northeast-1The current AWS region
profileastronautsThe current AWS profile
symbolMirrors the value of option symbol
style*Mirrors the value of option style

Example config

# ~/.config/starship.toml

[aws]
format = 'on [$symbol$profile(\($region\))]($style) '
style = "bold blue"
symbol = "🅰 "
[aws.region_aliases]
ap-southeast-2 = "au"
us-east-1 = "va"

Battery

Shows the battery current charge status and is only visible when the battery is less than 10%

Options

Available options

OptionDefaultDescription
full_symbol“•”The symbol shown when the battery is full.
charging_symbol“⇡”The symbol shown when the battery is charging.
discharging_symbol“⇣”The symbol shown when the battery is discharging.
format“[$symbol$percentage]($style) “The format for the module.
displayDisplay threshold and style for the module.
disabledfalseDisables the battery module.

Example config

# ~/.config/starship.toml

[battery]
full_symbol = "🔋"
charging_symbol = "⚡️"
discharging_symbol = "💀"

Battery Display

Tells when the battery indicator should be shown.

Options

Available options include:

OptionDescription
thresholdThe upper bound for the display option.
styleThe style used if the display option is in use

Example

[[battery.display]]  # "bold red" style when capacity is between 0% and 10%
threshold = 10
style = "bold red"

[[battery.display]]  # "bold yellow" style when capacity is between 10% and 30%
threshold = 30
style = "bold yellow"

# when capacity is over 30%, the battery indicator will not be displayed

Kubernetes

Displays the current Kubernetes context name and, if set, the namespace from the kubeconfig file. The namespace needs to be set in the kubeconfig file, this can be done via kubectl config set-context starship-cluster --namespace astronaut. If the $KUBECONFIG env var is set the module will use that if not it will use the ~/.kube/config.

Options

Some available options are:

OptionDefaultDescription
symbol“☸ “A format string representing the symbol displayed before the Cluster.
format‘[$symbol$context( \($namespace\))]($style) in ‘The format for the module.
style“cyan bold”The style for the module.
context_aliasesTable of context aliases to display.
disabledtrueDisables the kubernetes module
Variables

You can use the following variables

VariableExampleDescription
contextstarship-clusterThe current kubernetes context
namespacestarship-namespaceIf set, the current kubernetes namespace
symbolMirrors the value of option symbol
style*Mirrors the value of option style

Example config

# ~/.config/starship.toml

[kubernetes]
format = 'on [⛵ $context \($namespace\)](dimmed green) '
disabled = false
[kubernetes.context_aliases]
"dev.local.cluster.k8s" = "dev"

Directory

Shows the path to your current directory, truncated to three parent folders

Options you can use

OptionDefaultDescription
truncation_length3The number of parent folders that the current directory should be truncated to.
truncate_to_repotrueWhether or not to truncate to the root of the git repo that you’re currently in.
format“[$path]($style)[$read_only]($read_only_style) “The format for the module.
style“bold cyan”The style for the module.
disabledfalseDisables the directory module.
read_only“🔒”The symbol indicating current directory is read only.
read_only_style“red”The style for the read only symbol.
truncation_symbol“”The symbol to prefix to truncated paths. eg: “…/”

And variables

VariableExampleDescription
path“D:/Projects”The current directory path
style*“black bold dimmed”Mirrors the value of option style

*: This variable can only be used as a part of a style string

Example

# ~/.config/starship.toml

[directory]
truncation_length = 8
truncation_symbol = "…/"

Starship version and Updating

To check the currently installed version of Starship, run the below command:

➜ starship --version
starship 0.47.0

To can always download and install the newest version to get the latest updates. For Starship installed with system packages, updating your system should update all the packages.

You have successfully installed and configured Starship for your shell. I hope the guide has been helpful. Enjoy using the fastest and highly customizable shell prompt. Do not forget to check more interesting guides below:

LEAVE A REPLY

Please enter your comment!
Please enter your name here