placeholder

OUTER SPACE TERMINAL - STARSHIP

March 22nd, 2024
placeholder Ben Di Giorgio, Maison Di Giorgio・Asia Quest

Preface

I just want to preface this by saying that this tutorial will focus on adding starship to a zsh terminal on a Mac. If you are using a different shell, you can still follow along, but you will need to adjust the installation steps accordingly.

Have you ever wanted a nicer terminal?

I have always been a fan of customizing my terminal. I spend a lot of time in it, so I want it to be a place that I enjoy being. I came across a project called Starship, which is a minimal, blazing-fast, and infinitely customizable prompt for any shell. I have been using it for a few weeks now, and I love it. It is highly customizable, and you can make it look however you want. The video that introduced me to this project was this one by Andrew Burgess. I highly recommend you check out his other videos especially if you have an interest in typescript.

If you are interested in adding Starship to your terminal, keep reading!

Installation

1. Fonts

One thing you may need to do is install a Nerd Font. This is because Starship uses icons in the prompt, and these icons are provided by the Nerd Font. You can download a Nerd Font from the website and install it on your system. I use Roboto Mono Nerd Font. This will let you add icons to your terminal prompt and customise it even further. It’s a small thing but I love having the icons for git branches and other things in my prompt.

2. Change your terminal (optional)

The default Apple terminal at the time of this article doesn’t support the full range of colors and emojis that Starship can use. I recommend using iTerm2. It is a great terminal emulator for macOS and has a lot of features that the default terminal doesn’t have. After installing iTerm2 you will need to set up a profile which uses the font your just installed.

You can do this through the iTerm2 preferences. Go to Profiles -> Text -> Font and select the Nerd Font you installed.

Also feel free to customise the overall look of your profile. I’ll include the JSON for my profile at the end of this article1.

3. Install Starship

Alright, let’s actually install Starship now.

You can install Starship by running the following command in your terminal:

curl -sS https://starship.rs/install.sh | sh

or with brew (my preferred methof):

brew install starship

Setup with shell

For this we are just focusing on zsh. You’re going to want to add the following to your .zshrc file:

eval "$(starship init zsh)"

This will initialize Starship for zsh.

Your .zshrc file is located in your home directory. You can open it with any text editor but I find it easiest to just use vim in the terminal:

vim ~/.zshrc

Then you can add the line at the end of the file and save it (: wq).

Configuration

Now for the fun part, customizing your prompt!

You can configure Starship by creating a starship.toml file in your a directory called .config home directory. This file will be used to configure the prompt. You can find the full list of options in the Starship documentation.

This is an easy way of creating this file and directory:

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

There is so much you can do with Starship and I think it’s worth checking out the documentation to see what you can do. Here is a quick overview of how you can setup a prompt.

format

Format strings are the format that a module prints all its variables with. Most modules have an entry called format that configures the display format of the module. You can use texts, variables and text groups in a format string.

You define a format for the prompt which determines what is displayed and in what order. Here is an example of the format I use:

# ~/.config/starship.toml
format = """
$username\
$hostname\
$directory\
$git_branch\
$git_state\
$git_status\
$git_metrics\
$fill\
$rust\
$nodejs\
$python\
$docker_context\
$cmd_duration $jobs $time\
$line_break\
$character"""

Variables

You can now define the variables which are used in the format string. Here is an example of how you can define the variables:

[character]
format = "❯❯ "
success_symbol = "❯❯(bold green) "
error_symbol = "❯❯(bold red) "

There is built in support for many frequently used tools/languages and these three for git are some of my favourite additions to my terminal.

[git_branch]
symbol = ' '
format = "[$symbol$branch]($style) "
style = "bright-black"

[git_status]
format = '([\[$all_status$ahead_behind\]]($style) )'
style = "cyan"

[git_state]
format = '\([$state( $progress_current/$progress_total)]($style)\) '
style = "bright-black"

Final thoughts

I hope this article has been helpful and that you have fun customizing your terminal. I have found that having a nice terminal has made me more productive and I enjoy using it more. If you have any questions or need help with anything, feel free to reach out to me. I am always happy to help or just chat. I’ll link my full starship.toml file below so you can see how I have set up my prompt2.

Footnotes

  1. If you want to import my profile settings, you can do so by going to Profiles -> Other Actions -> Import JSON Profiles and pasting the JSON in this gist.

  2. starship.toml