My Prompt: Starship
Table of Contents
In this post I’ll be go over my current prompt of choice: Starship. Starship is a cross platform prompt written in rust. It’s extremely fast, easy to extend, and not to mention it’s easy on the eyes. I use Starship on many OS’s but in this post I’ll focus on PowerShell because there are a few neat tricks.
You can see the latest copy of my config files here: HeyItsGilbert/dotfiles
My goals #
These are my overall goals with my particular setup.
- Configs that I can sync between computers of any OS.
- Allow flexibility to add machine/environment specific options (e.g. work).
- Allow ability to swap any component when I see the next new shiny thing.
Initializing #
Starship includes PowerShell instructions on it’s walk through guide (which is a good sign of support in my opinion). It’s as simple as the following:
Under the hood, starship is overwriting the prompt function. If you read the My Shell: PowerShell, you may recall how I load starship in combination with intializing my profile.
This checks if starship is available and intializes it. But what’s that pre-command? It runs before the starship prompt renders. This is how I can make sure all my stuff is initialized.
Configuration #
Configuration is all done in a single starship.toml
file.
Prompt Layout #
I was a long time user of powerline, and I created something similar. Starship is able to print unicode characters.
Transient Prompt #
Transient prompt allows you to change your prompt after you execute your command. This can be useful if you’d prefer a simpler prompt in your scrollback and only keep the relevent info on your current prompt. The example given on the site replaces the prompt with just the character.
Read more: TransientPrompt in PowerShell
Pro-Tip: Prompt Profiles #
I only just discovered this! The starship prompt
command supports a --profile
flag. You can use this to tweak your prompt in a given context (which PowerShell)
is great a determining. But you can mix this with the transient prompt, and you
can print a short prompt.
I wanted something that would print the directory and the time. So I created the following profile:
Pro-Tip: EngineEvent PowerShell.OnIdle
#
Recently on the PowerShell discord someone was asking about how they could continually update their prompt. Super Genius Jaykul recommended using the EngineEvent system to execute commands and gave this command.
Since my prompt is two lines long we need to remove the last two lines and go back the beginning.
So let’s dissect this what we’re writing. I’ll break each bit into it’s own line and add a comment explaining what it does.
Why not `e? While that’s valid, it doesn’t work in Windows PowerShell. To work
for both, we can use [char]27
.
In the past few posts in the series I’ve briefly touched on some ANSI escape codes, and in my next post I’ll be going into more depth. There is so much to cover but I’ll be hitting a few highlights and pointing to a ton of references.
How’s the technology from 1979 still shapping our daily life? Stay tuned and find out!
References #
- Starship: Cross-shell prompt.
- Powerline: Original powerline.
- about_special_characters: Escape character in PowerShell (not Windows PowerShell)
More in this series
- Terminals, Shells, and Prompts
- My Terminal: WezTerm
- My Shell: PowerShell
- My Prompt: Starship