Some Bits: Nelson's log

starship shell prompt magic

It’s been nearly a decade since I indulged in customizing my shell prompt, so here I am. I’m trying Starship, a very nicely engineered solution that’s cross-platform.

Last time I customized things I settled on liquidprompt, a very complicated set of shell scripts that works pretty well. It shows me things like Git status, Python venv activation, whether I have suspended screen sessions.

Here’s the default starship in the same context.

The big difference is that second line; Starship wants to stuff so much stuff in the command line they wrap. (Do I really need to know the Python version?!)

The other obvious difference is the weird symbols; Starship relies on you using a Nerd Font, a regular font patched with like 4000 symbols stuffed in the Unicode private use area. I can’t decide if that’s clever or a terrible idea, AFAICT there’s no graceful fallback so if you don’t happen to have the special font you get a lot of broken glyphs. (Or else you have to have a second nerdfont-free configuation.)

But what I really like about Starship is the very clean implementation. It’s a single 8MB Rust binary. It seems to run very fast. And front-and-center in the config are timeouts for if scanning files or running a command take too long. The last thing you want is a slow prompt! That’s a real problem with liquidprompt in large Git repos.

Configurating Starship

The config file is reasonable; there’s a top level prompt which is basically “combine these modules”. And then lots of modules. For instance Python is defaulting to display

'via [${symbol}${pyenv_prefix}(${version} )(\($virtualenv\) )]($style)'

So that’s where the text “via”, the Python verison, etc is coming from. You can both override the format string itself and the values of variables like $style.

When reading through the docs pay particular attention to $format since that’s what actually displays. Also note some modules are $disabled by default. The docs are out of date with the binary I installed; starship print-config shows the current active config. There’s a bunch of other neat commands too; explain, timings, etc.

There’s a strange combination of using lots of extra text (like “via” or brackets around git status). And yet also having everything color coded, so the textual delineation is superfluous.

I can’t find a way to make general conditional behaviors. There’s support for conditionals on the empty string, and some modules are hard-coded to do conditional display (ie: only show hostname if remote). But no general purpose conditioning.

It’s quite voracious about showing language details. If you have a directory with both Python and Javascript files in it, you get “via  v18.7.0” and “via 🐍 v3.10.4” in every prompt.

git status bears some consideration. It often shows up as red !? which to me suggests an error state, but really it’s just saying “you have uncommitted work”.

My configuration

I spent most of an hour reading and tinkering and landed here.

That’s in a git repo with +3/-3 changes pending, a job in the background, and the last command exiting with status 1. This all runs in 1-2ms except for the git_metrics count of lines changed; that’s 10ms for this very small status. (git_metrics is off by default.) That’s a pretty maxi-prompt btw, this is what I get with a new local shell in my home directory

My config is below. Mostly what I did here was remove extra words like “via” or “in” from the various modules, also suppressed language version numbers entirely. No doubt I’ll keep tinkering.

add_newline = false
[line_break]
disabled = true

[username]
format = "[$user]($style)"
[hostname]
format = "[@$hostname]($style) "
[cmd_duration]
format = "[$duration]($style) "
[status]
disabled = false
symbol = ""

[git_branch]
symbol = ""
format = "[$symbol$branch(:$remote_branch) ]($style)"
ignore_branches = [ "master", "main" ]
[git_metrics]
disabled = false
[git_status]
format = '([$all_status$ahead_behind]($style) )'

[python]
format = '[($virtualenv )]($style)'
[nodejs]
disabled = true
[gcloud]
disabled = true