Article

Custom Starship.rs Prompt Components

shell-prompt starship-rs custom-component
Posted on Saturday, November the 06, 2021
2 min read

Starship.rs is a nice framework for configuring shell prompts. This post shows how to define custom prompt components with Starship.rs and provides an example terminal prompt configuration using a custom prompt component.

This is a small addition to my previous post about ZSH prompt configuration with Starship.rs.

The last time I tried it, I couldn’t get the custom component configuration to work properly. In the meantime, I found a way to at least make a small custom component—custom time format—to be rendered in the prompt. The config is shown below:

format = """\
${custom.datetime} $directory $username$hostname $git_branch
$character """

[custom.datetime]
command = "date +'%F (%T)'"
when = "true"
format = '[$symbol($output)](bold)'

There are three important things to notice:

  1. your format configuration has to include ${custom.NAME} where NAME is the name of your custom prompt component;
  2. you have to provide a block labeled [custom.NAME] which provides a condition via when because it will not render otherwise; and,
  3. in the custom command’s format string, the $output variable can be referenced to include the output of the command passed via command.

Multiple custom components are possible, you just have to prefix every block that declares one with custom. (e.g.[custom.ANOTHER_CUSTOM_COMPONENT])and reference it with ${custom.ANOTHER_CUSTOM_COMPONENT} in the top-level format property.

The command passed to when must be a shell command which returns 0 whenever the condition is met. As in the configuration above, we can trivially set when = "true" to use the true command (which always returns 0) and the custom prompt component will be shown every time the prompt is rendered.

Other possible conditions are

Follow the link below for more custom commands. ↓

Here’s my updated prompt with some more changes including the custom time command.

friedrichkurz.me

© 2025 Friedrich Kurz

Privacy Policy