Why the Starship prompt is better than your default on Linux and MacOS


Richard McManus/Getty Images

The terminal prompt. The command line interface. The CLI. The shell.

Not the most exciting things, right?

To most Linux users, the terminal is a tool to accomplish important work. It’s not a playground or something used to make others jealous of your setup.

That doesn’t mean the prompt has to be boring or uninformative. 

Also: This terminal app uses AI to help you understand the command line

Starship aims to be the better prompt for Linux and MacOS users. This shell replacement is minimal, fast, and highly customizable. Starship is an open-source tool designed to enhance your prompt with at-a-glance information while presenting a sleek and efficient appearance.

I started using Starship some time ago and have found it to be a great replacement for the default on most Linux distributions (and even MacOS).

Let me show you how to install it and then how to customize it.

How to install Starship prompt

What you’ll need: To get Starship running, you’ll need a running instance of either Linux or MacOS. The installation on either platform can be achieved using the same simple method.

The first thing you must do is log into your desktop and open your default terminal app. On Linux this could be any number of terminal apps and on MacOS it’s probably just the default (which is, aptly named, Terminal.app).


Show more

There’s only one command to run for the Starship installation and that is:


Show more

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

After running the command, you’ll be asked to OKy the installation location (just type “y”) and then type your user password. The installation will start and finish much faster than you think, so don’t worry if you blink your eyes and have your prompt returned to you… the installation was successful.

If you receive an error on MacOS, it’s most likely because the /usr/local/bin directory doesn’t exist. If that’s the case, create it and then re-run the installation command. You can create that directory with:

sudo mkdir /usr/local/bin

Although Starship has been successfully installed, you’ll notice your prompt hasn’t changed. That’s because we have to configure your shell to use it. On Linux, open the necessary file with:


Show more

nano ~/.bashrc

At the bottom of that file, add the following line:

eval “$(starship init bash)”

Save and close the file.

To enable Starship on MacOS, you must first create the .zsch file with the command:


Show more

nano ~/.zsch

In that file, add the following:

eval “$(starship init zsch)”

Save and close the file.

Before you close your current terminal window, open another instance and make sure that Starship has been successfully installed and running. If so, your terminal will look something like this:


Show more

~
>

How to customize Starship

The customization of Starship is done in the starship.toml file. By default, that file does not exist, so we’ll create it with:

nano ~/.config/starship.toml

The configuration of Starship is done in blocks, and there are blocks for certain things such as global settings, character, battery, time, directory, git, language-specific modules, container and cloud modules, OS, username, and hostname. I will show you how to configure a Starship prompt with my custom layout. You can then change that customization to meet your needs. 

Also: How to generate random passwords from the Linux command line

You customize your prompt by adding or modifying different modules in the format string. The basic layout is:

format = “””
$directory$git_branch$character
“””

First, let’s configure a global layout, followed by layouts for directories and even battery status (which only works on a device that uses a battery). These configuration options are added to the starship.toml file.

My global section looks like this:

format = “””
[┌───────────────────>](bold green)
[│](bold green)[Welcome to Hive](bold blue)
[│](bold green)$directory$rust$package$symbol🌿
[└─>](bold green) “””

The above encases the statement “Welcome to Hive” (the name of my desktop machine) and the current working directory (with the addition of a cute leaf symbol) within a green box that wraps around the top and the left side. The text “Welcome to Hive” is printed in bold blue.

Next, we’ll configure how the directory section looks (which is called from the global section above), and that looks like this:

[directory]
style = “blue”
truncation_length = 3
truncation_symbol = “…/”

The above section configures the directory path to be printed in blue, truncates the list to the last three directories, and then adds …/ as the truncation symbol.

Next, we configure a section for battery status, which looks like this:

# Show battery status
[battery]
threshold = 10
format = “🔋 $percentage%”

The entire file looks like:

format = “””
[┌───────────────────>](bold green)
[│](bold green)[Welcome to Hive](bold blue)
[│](bold green)$directory$rust$package$symbol🌿
[└─>](bold green) “””

[directory]
style = “blue”
truncation_length = 3
truncation_symbol = “…/”

# Show battery status
[battery]
threshold = 10
format = “🔋 $percentage%”

Save and close the file. 

You should see the changes happen automatically. If you don’t like what you see (or there are errors), go back to the original window and make the necessary adjustments. Just make sure you do not close your terminal app until you get Starship exactly how you want it.

To learn about advanced configurations with Starship, check out the official documentation for the app.

Also: The first 5 Linux commands every new user should learn

And that’s all there is to giving your Linux and MacOS prompt a bit of panache and even making it more informative.





Source link

Leave a Comment