Skip to content

Starship Prompt

I have introduced to Starship Prompt a week ago and it makes my shell prompt amazing.

Prerequisites

Note

  • I am using MacOS. So, for other OS the paths may differ.
  • I have used Nerd Fonts thats why there are some symbol which may not appear as they are.
  • I have defined some conventions to define my starship.toml file. If you want to know them read the sections where I describe my conventions.

🔧 Customization

You can customize your prompt for each programming languages you uses like Python, JavaScript, Rust and more. See official documentation to know more.

Example: Python

[python]
symbol = "" # (1)!
style = "arv_python"
format = "[](fg:$style)[$symbol( $version)[( \\($virtualenv\\))](bold bg:$style)](bg:$style)[](fg:$style)"

Example: Docker

[docker_context]
symbol = "" # (1)!
style = "arv_docker"
format = "[](fg:$style)[$symbol ($context)](bg:$style)[](fg:$style)"
Conventions
  1. Enclosed Modules: Each modules enclose with circular end.

🎹 Color Palette

Did you see style = "arv_python" and style = "arv_docker" in above examples. Those are my custom defined palette as "arv-anshul".

palette = "arv-anshul"

[palettes.arv-anshul]
arv_dir = "203"
arv_docker = "026"
arv_git = "063"
arv_python = "028"
arv_custom = "236"
Print ANSI Colormap
# Use this function to print ANSI colormap
function colormap() {
    range_start=${1:-1}
    range_end=${2:-255}

    for i in $(seq $range_start $range_end); do
        echo -en "\e[48;5;${i}m  ${(l:3::0:)i}  \e[0m "
        [[ $((i % 10)) -eq 0 ]] && echo
    done
    return 0
}

If you doc't want to use ANSI color format then you also use starship's pre-defined colors: black, red, green, blue, yellow, purple, cyan, white. You can optionally prefix these with bright- to get the bright version (e.g. bright-white). See in documentation

palette = "arv-anshul-color"

[palettes.arv-anshul-color]
arv_dir = "bright-red"
arv_docker = "bright-blue"
arv_git = "blue"
arv_python = "green"
arv_custom = "black"
Conventions
  1. Palette Preffix: Palette's keys must have a preffix (in my case it is "arv_").
  2. ANSI Codes: I have defined colors in ANSI Codes. See this Gist to know more about ANSI Codes.
  3. Own Color Palette: I have defined programming language-wise (or module-wise) colors which makes easy to change/manipulate the color of any language.

You can also create your own custom color palette in ~/.config/starship.toml.

đŸ«‚ Extra customization with custom modules

[custom.github]
detect_folders = [".github"]
format = "[$symbol]($style)"
style = "bg:arv_custom"
symbol = "îȘ„ " # (1)!

[custom.mkdocs]
detect_files = ["mkdocs.yaml", "mkdocs.yml"]
detect_folders = ["docs"]
format = "[$symbol]($style)"
style = "bg:arv_custom"
symbol = "󱔗 " # (2)!

[custom.vscode]
detect_folders = [".vscode"]
format = "[$symbol]($style)"
style = "bg:arv_custom"
symbol = "󰚞 " # (3)!
Conventions

I have used custom modules to just show some desirable icons in the prompt but you can do a lot of thing using custom modules (the possibilities are endless).

  1. Show Custom Icons: I used custom modules to show icons by detecting files and folders. For example, prompt will show icons when .github folder is present in the current directory.

Refer to official documentation to know more about custom modules.

Tip

From official documentation

Issue #1252 contains examples of custom modules. You can go there for inspiration and if you have an interesting example not covered there, feel free to share it there!


If you want to make prompt to look like mine! Click below

  starship.toml