From ec76fafff08933f6f31fb99ea974bdb5ae97a0af Mon Sep 17 00:00:00 2001 From: Zhenhui Xie Date: Wed, 8 Jul 2020 06:45:32 +0800 Subject: [PATCH] feat: refactor modules to use format strings (#1374) --- Cargo.lock | 10 + Cargo.toml | 1 + docs/config/README.md | 1408 ++++++++++++++++++++--------- src/config.rs | 130 ++- src/configs/aws.rs | 40 +- src/configs/battery.rs | 31 +- src/configs/character.rs | 23 +- src/configs/cmd_duration.rs | 9 +- src/configs/conda.rs | 21 +- src/configs/crystal.rs | 13 +- src/configs/custom.rs | 17 +- src/configs/directory.rs | 9 +- src/configs/docker_context.rs | 15 +- src/configs/dotnet.rs | 49 +- src/configs/elixir.rs | 17 +- src/configs/elm.rs | 15 +- src/configs/env_var.rs | 17 +- src/configs/erlang.rs | 15 +- src/configs/git_branch.rs | 15 +- src/configs/git_commit.rs | 15 +- src/configs/git_state.rs | 39 +- src/configs/git_status.rs | 75 +- src/configs/go.rs | 15 +- src/configs/hg_branch.rs | 15 +- src/configs/hostname.rs | 11 +- src/configs/java.rs | 13 +- src/configs/jobs.rs | 13 +- src/configs/julia.rs | 15 +- src/configs/kubernetes.rs | 17 +- src/configs/memory_usage.rs | 23 +- src/configs/nim.rs | 15 +- src/configs/nix_shell.rs | 23 +- src/configs/nodejs.rs | 13 +- src/configs/ocaml.rs | 15 +- src/configs/package.rs | 13 +- src/configs/php.rs | 13 +- src/configs/purescript.rs | 15 +- src/configs/python.rs | 17 +- src/configs/ruby.rs | 13 +- src/configs/rust.rs | 15 +- src/configs/singularity.rs | 19 +- src/configs/starship_root.rs | 108 +-- src/configs/terraform.rs | 19 +- src/configs/time.rs | 11 +- src/configs/username.rs | 15 +- src/configs/zig.rs | 15 +- src/formatter/mod.rs | 1 + src/formatter/model.rs | 86 ++ src/formatter/parser.rs | 71 +- src/formatter/spec.pest | 51 +- src/formatter/string_formatter.rs | 616 ++++++++++--- src/module.rs | 130 +-- src/modules/aws.rs | 100 +- src/modules/battery.rs | 92 +- src/modules/character.rs | 57 +- src/modules/cmd_duration.rs | 37 +- src/modules/conda.rs | 32 +- src/modules/crystal.rs | 31 +- src/modules/custom.rs | 56 +- src/modules/directory.rs | 51 +- src/modules/docker_context.rs | 47 +- src/modules/dotnet.rs | 91 +- src/modules/elixir.rs | 42 +- src/modules/elm.rs | 32 +- src/modules/env_var.rs | 36 +- src/modules/erlang.rs | 30 +- src/modules/git_branch.rs | 64 +- src/modules/git_commit.rs | 44 +- src/modules/git_state.rs | 169 ++-- src/modules/git_status.rs | 493 +++++----- src/modules/golang.rs | 34 +- src/modules/hg_branch.rs | 36 +- src/modules/hostname.rs | 27 +- src/modules/java.rs | 30 +- src/modules/jobs.rs | 44 +- src/modules/julia.rs | 35 +- src/modules/kubernetes.rs | 54 +- src/modules/line_break.rs | 11 +- src/modules/memory_usage.rs | 83 +- src/modules/mod.rs | 2 +- src/modules/nim.rs | 37 +- src/modules/nix_shell.rs | 58 +- src/modules/nodejs.rs | 35 +- src/modules/ocaml.rs | 34 +- src/modules/package.rs | 42 +- src/modules/php.rs | 32 +- src/modules/purescript.rs | 31 +- src/modules/python.rs | 49 +- src/modules/ruby.rs | 36 +- src/modules/rust.rs | 43 +- src/modules/singularity.rs | 40 +- src/modules/terraform.rs | 42 +- src/modules/time.rs | 38 +- src/modules/username.rs | 36 +- src/modules/zig.rs | 27 +- src/print.rs | 204 +++-- tests/testsuite/aws.rs | 32 +- tests/testsuite/character.rs | 49 +- tests/testsuite/cmd_duration.rs | 4 +- tests/testsuite/common.rs | 2 +- tests/testsuite/conda.rs | 15 +- tests/testsuite/configuration.rs | 21 - tests/testsuite/directory.rs | 87 +- tests/testsuite/dotnet.rs | 53 +- tests/testsuite/env_var.rs | 6 +- tests/testsuite/git_branch.rs | 84 ++ tests/testsuite/git_commit.rs | 15 +- tests/testsuite/git_state.rs | 67 +- tests/testsuite/git_status.rs | 113 +-- tests/testsuite/hostname.rs | 42 - tests/testsuite/line_break.rs | 13 - tests/testsuite/main.rs | 1 - tests/testsuite/nix_shell.rs | 20 +- tests/testsuite/terraform.rs | 6 +- tests/testsuite/time.rs | 3 +- 115 files changed, 4133 insertions(+), 2544 deletions(-) delete mode 100644 tests/testsuite/line_break.rs diff --git a/Cargo.lock b/Cargo.lock index d9ad9d52..17026fa6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -867,6 +867,15 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +[[package]] +name = "quick-xml" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cc440ee4802a86e357165021e3e255a9143724da31db1e2ea540214c96a0f82" +dependencies = [ + "memchr", +] + [[package]] name = "quote" version = "1.0.7" @@ -1151,6 +1160,7 @@ dependencies = [ "pest", "pest_derive", "pretty_env_logger", + "quick-xml", "rayon", "regex", "remove_dir_all", diff --git a/Cargo.toml b/Cargo.toml index 111675f2..b4dbf110 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,6 +59,7 @@ open = "1.4.0" unicode-width = "0.1.8" textwrap = "0.12.1" term_size = "0.3.2" +quick-xml = "0.18.1" # Optional/http: attohttpc = { version = "0.15.0", optional = true, default-features = false, features = ["tls", "form"] } diff --git a/docs/config/README.md b/docs/config/README.md index 01750a60..7dd33952 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -20,8 +20,8 @@ All configuration for starship is done in this [TOML](https://github.com/toml-la add_newline = false # Replace the "❯" symbol in the prompt with "➜" -[character] # The name of the module we are configuring is "character" -symbol = "➜" # The "symbol" segment is being set to "➜" +[character] # The name of the module we are configuring is "character" +success_symbol = "[➜](bold green)" # The "success_symbol" segment is being set to "➜" with the color "bold green" # Disable the package module, hiding it from the prompt completely [package] @@ -29,11 +29,13 @@ disabled = true ``` You can change default `starship.toml` file location with `STARSHIP_CONFIG` environment variable: + ```sh export STARSHIP_CONFIG=~/.starship ``` Equivalently in PowerShell (Windows) would be adding this line to your `$PROFILE`: + ```ps1 $ENV:STARSHIP_CONFIG = "$HOME\.starship" ``` @@ -42,17 +44,43 @@ $ENV:STARSHIP_CONFIG = "$HOME\.starship" **Module**: A component in the prompt giving information based on contextual information from your OS. For example, the "nodejs" module shows the version of NodeJS that is currently installed on your computer, if your current directory is a NodeJS project. -**Segment**: Smaller sub-components that compose a module. For example, the "symbol" segment in the "nodejs" module contains the character that is shown before the version number (⬢ by default). +**Variable**: Smaller sub-components that contains information provided by the module. For example, the "version" variable in the "nodejs" module contains the current version of NodeJS. -Here is the representation of the node module. In the following example, "symbol" and "version" -are segments within it. Every module also has a prefix and suffix that are the default terminal color. +By convention, most modules have a prefix of default terminal color (e.g. `via ` in "nodejs") and an empty space as a suffix. -``` -[prefix] [symbol] [version] [suffix] - "via " "⬢" "v10.4.1" "" -``` +### Format Strings -### Style Strings +Format strings are the format that a module prints all its variables with. +Most modules have an entry called `format` that configures the display format of the module. +You can use texts, variables and text groups in a format string. + +#### Variable + +A variable contains a `$` symbol followed by the name of the variable. +The name of a variable only contains letters, numbers and `_`. + +For example: + +- `$version` is a format string with a variable named `version`. +- `$git_branch$git_commit` is a format string with two variables named `git_branch` and `git_commit`. +- `$git_branch $git_commit` has the two variables separated with a space. + +#### Text Group + +A text group is made up of two different parts. + +The first part, which is enclosed in a `[]`, is a [format string](#format-strings). +You can add texts, variables, or even nested text groups in it. + +In the second part, which is enclosed in a `()`, is a [style string](#style-strings). This can be used style the first part. + +For example: + +- `[on](red bold)` will print a string `on` with bold text colored red. +- `[⬢ $version](bold green)` will print a symbol `⬢ ` followed by the content of variable `version`, with bold text colored green. +- `[a [b](red) c](green)` will print `a b c` with `b` red, and `a` and `c` green. + +#### Style Strings Most modules in starship allow you to configure their display styles. This is done with an entry (usually called `style`) which is a string specifying the configuration. Here are some examples of style strings along with what they do. For details on the full syntax, consult the [advanced config guide](/advanced-config/). @@ -65,17 +93,60 @@ Most modules in starship allow you to configure their display styles. This is do Note that what styling looks like will be controlled by your terminal emulator. For example, some terminal emulators will brighten the colors instead of bolding text, and some color themes use the same values for the normal and bright colors. Also, to get italic text, your terminal must support italics. +#### Conditional Format Strings + +A conditional format string wrapped in `(` and `)` will not render if all variables inside are empty. + +For example: + +- `(@$region)` will show nothing if the variable `region` is `None`, otherwise `@` followed by the value of region. +- `(some text)` will always show nothing since there are no variables wrapped in the braces. +- When `$all` is a shortcut for `\[$a$b\] `, `($all)` will show nothing only if `$a` and `$b` are both `None`. + This works the same as `(\[$a$b\] )`. + +#### Escapable characters + +The following symbols have special usage in a format string. +If you want to print the following symbols, you have to escape them with a backslash (`\`). + +- $ +- \\ +- [ +- ] +- ( +- ) + +Note that `toml` has [its own escape syntax](https://github.com/toml-lang/toml#user-content-string). +It is recommended to use a literal string (`''`) in your config. +If you want to use a basic string (`""`), pay attention to escape the backslash `\`. + +For example, when you want to print a `$` symbol on a new line, the following configs for `format` are equivalent: + +```toml +# with basic string +format = "\n\\$" + +# with multiline basic string +format = """ + +\\$""" + +# with literal string +format = ''' + +\$''' +``` + ## Prompt This is the list of prompt-wide configuration options. ### Options -| Variable | Default | Description | -| -------------- | ----------------------------- | ------------------------------------------------------ | -| `add_newline` | `true` | Add a new line before the start of the prompt. | -| `prompt_order` | [link](#default-prompt-order) | Configure the order in which the prompt module occurs. | -| `scan_timeout` | `30` | Timeout for starship to scan files (in milliseconds). | +| Option | Default | Description | +| -------------- | ------------------------------ | ----------------------------------------------------- | +| `format` | [link](#default-prompt-format) | Configure the format of the prompt. | +| `scan_timeout` | `30` | Timeout for starship to scan files (in milliseconds). | ### Example @@ -83,61 +154,69 @@ This is the list of prompt-wide configuration options. # ~/.config/starship.toml # Disable the newline at the start of the prompt -add_newline = false -# Overwrite a default_prompt_order and use custom prompt_order -prompt_order=["rust","line_break","package","line_break","character"] +format = "$all" + +# Use custom format +format = """ +[┌───────────────────>](bold green) +[│](bold green)$directory$rust$package +[└─>](bold green) """ + # Wait 10 milliseconds for starship to check files under the current directory. scan_timeout = 10 ``` -### Default Prompt Order +### Default Prompt Format -The default `prompt_order` is used to define the order in which modules are shown in the prompt, if empty or no `prompt_order` is provided. The default is as shown: +The default `format` is used to define the format of the prompt, if empty or no `format` is provided. The default is as shown: ```toml -prompt_order = [ - "username", - "hostname", - "kubernetes", - "directory", - "git_branch", - "git_commit", - "git_state", - "git_status", - "hg_branch", - "docker_context", - "package", - "dotnet", - "elixir", - "elm", - "erlang", - "golang", - "java", - "julia", - "nim", - "nodejs", - "ocaml", - "php", - "purescript", - "python", - "ruby", - "rust", - "terraform", - "zig", - "nix_shell", - "conda", - "memory_usage", - "aws", - "env_var", - "crystal", - "cmd_duration", - "custom", - "line_break", - "jobs", - "battery", - "time", - "character", -] +format = "\n$all" + +# Which is equivalent to +format = """ + +$username\ +$hostname\ +$kubernetes\ +$directory\ +$git_branch\ +$git_commit\ +$git_state\ +$git_status\ +$hg_branch\ +$docker_context\ +$package\ +$dotnet\ +$elixir\ +$elm\ +$erlang\ +$golang\ +$java\ +$julia\ +$nim\ +$nodejs\ +$ocaml\ +$php\ +$purescript\ +$python\ +$ruby\ +$rust\ +$terraform\ +$zig\ +$nix_shell\ +$conda\ +$memory_usage\ +$aws\ +$env_var\ +$crystal\ +$cmd_duration\ +$custom\ +$line_break\ +$jobs\ +$battery\ +$time\ +$character""" ``` ## AWS @@ -151,28 +230,66 @@ is read from the `AWS_VAULT` env var. ### Options -| Variable | Default | Description | -| ----------------- | --------------- | --------------------------------------------------------------------------- | -| `symbol` | `"☁️ "` | The symbol used before displaying the current AWS profile. | -| `displayed_items` | `all` | Choose which item to display. Possible values: [`all`, `profile`, `region`] | -| `region_aliases` | | Table of region aliases to display in addition to the AWS name. | -| `style` | `"bold yellow"` | The style for the module. | -| `disabled` | `false` | Disables the `AWS` module. | +| Option | Default | Description | +| ---------------- | ------------------------------------------------ | --------------------------------------------------------------- | +| `format` | `"on [$symbol$profile(\\($region\\))]($style) "` | The format for the module. | +| `symbol` | `"☁️ "` | The symbol used before displaying the current AWS profile. | +| `region_aliases` | | Table of region aliases to display in addition to the AWS name. | +| `style` | `"bold yellow"` | The style for the module. | +| `disabled` | `false` | Disables the `AWS` module. | -### Example +### Variables + +| Variable | Example | Description | +| -------- | ---------------- | ------------------------------------ | +| region | `ap-northeast-1` | The current AWS region | +| profile | `astronauts` | The current AWS profile | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string + +### Examples + +#### Display everything ```toml # ~/.config/starship.toml [aws] +format = "on [$symbol$profile(\\($region\\))]($style) " style = "bold blue" symbol = "🅰 " -displayed_items = "region" [aws.region_aliases] ap-southeast-2 = "au" us-east-1 = "va" ``` +#### Display region + +```toml +# ~/.config/starship.toml + +[aws] +format = "on [$symbol$region]($style) " +style = "bold blue" +symbol = "🅰 " +[aws.region_aliases] +ap-southeast-2 = "au" +us-east-1 = "va" +``` + +#### Display profile + +```toml +# ~/.config/starship.toml + +[aws] +format = "on [$symbol$profile]($style) " +style = "bold blue" +symbol = "🅰 " +``` + ## Battery The `battery` module shows how charged the device's battery is and its current charging status. @@ -180,13 +297,14 @@ The module is only visible when the device's battery is below 10%. ### Options -| Variable | Default | Description | -| -------------------- | ------------------------ | ------------------------------------------------- | -| `full_symbol` | `"•"` | The symbol shown when the battery is full. | -| `charging_symbol` | `"⇡"` | The symbol shown when the battery is charging. | -| `discharging_symbol` | `"⇣"` | The symbol shown when the battery is discharging. | -| `display` | [link](#battery-display) | Display threshold and style for the module. | -| `disabled` | `false` | Disables the `battery` module. | +| Option | Default | Description | +| -------------------- | --------------------------------- | ------------------------------------------------- | +| `full_symbol` | `"•"` | The symbol shown when the battery is full. | +| `charging_symbol` | `"⇡"` | The symbol shown when the battery is charging. | +| `discharging_symbol` | `"⇣"` | The symbol shown when the battery is discharging. | +| `format` | `"[$symbol$percentage]($style) "` | The format for the module. | +| `display` | [link](#battery-display) | Display threshold and style for the module. | +| `disabled` | `false` | Disables the `battery` module. |
There are also options for some uncommon battery states. @@ -252,30 +370,59 @@ The `character` module shows a character (usually an arrow) beside where the tex is entered in your terminal. The character will tell you whether the last command was successful or not. It -can do this in two ways: by changing color (red/green) or by changing its shape -(❯/✖). The latter will only be done if `use_symbol_for_status` is set to `true`. +can do this in two ways: + +- changing color (`red`/`green`) +- changing shape (`❯`/`✖`) + +By default it only changes color. If you also want to change it's shape take a +look at [this example](#with-custom-error-shape). ### Options -| Variable | Default | Description | -| ----------------------- | -------------- | ----------------------------------------------------------------------------------- | -| `symbol` | `"❯"` | The symbol used before the text input in the prompt. | -| `error_symbol` | `"✖"` | The symbol used before text input if the previous command failed. | -| `use_symbol_for_status` | `false` | Indicate error status by changing the symbol. | -| `vicmd_symbol` | `"❮"` | The symbol used before the text input in the prompt if shell is in vim normal mode. | -| `style_success` | `"bold green"` | The style used if the last command was successful. | -| `style_failure` | `"bold red"` | The style used if the last command failed. | -| `disabled` | `false` | Disables the `character` module. | +| Option | Default | Description | +| ---------------- | ------------------- | -------------------------------------------------------------------------------- | +| `format` | `"$symbol "` | The format string used before the text input. | +| `success_symbol` | `"[❯](bold green)"` | The format string used before the text input if the previous command succeeded. | +| `error_symbol` | `"[❯](bold red)"` | The format string used before the text input if the previous command failed. | +| `vicmd_symbol` | `"[❮](bold green)"` | The format string used before the text input if the shell is in vim normal mode. | +| `disabled` | `false` | Disables the `character` module. | -### Example +### Variables + +| Variable | Example | Description | +| -------- | ------- | --------------------------------------------------------------------- | +| symbol | | A mirror of either `success_symbol`, `error_symbol` or `vicmd_symbol` | + +### Examples + +#### With custom error shape ```toml # ~/.config/starship.toml [character] -symbol = "➜" -error_symbol = "✗" -use_symbol_for_status = true +success_symbol = "[➜](bold green) " +error_symbol = "[✗](bold red) " +``` + +#### Without custom error shape + +```toml +# ~/.config/starship.toml + +[character] +success_symbol = "[➜](bold green) " +error_symbol = "[➜](bold red) " +``` + +#### With custom vim shape + +```toml +# ~/.config/starship.toml + +[character] +vicmd_symbol = "[V](bold green) " ``` ## Command Duration @@ -298,13 +445,22 @@ running `eval $(starship init $0)`, and then proceed as normal. ### Options -| Variable | Default | Description | -| ------------------- | --------------- | ---------------------------------------------------------- | -| `min_time` | `2_000` | Shortest duration to show time for (in milliseconds). | -| `show_milliseconds` | `false` | Show milliseconds in addition to seconds for the duration. | -| `prefix` | `took` | Prefix to display immediately before the command duration. | -| `style` | `"bold yellow"` | The style for the module. | -| `disabled` | `false` | Disables the `cmd_duration` module. | +| Option | Default | Description | +| ------------------- | ----------------------------- | ---------------------------------------------------------- | +| `min_time` | `2_000` | Shortest duration to show time for (in milliseconds). | +| `show_milliseconds` | `false` | Show milliseconds in addition to seconds for the duration. | +| `format` | `"took [$duration]($style) "` | The format for the module. | +| `style` | `"bold yellow"` | The style for the module. | +| `disabled` | `false` | Disables the `cmd_duration` module. | + +### Variables + +| Variable | Example | Description | +| -------- | -------- | --------------------------------------- | +| duration | `16m40s` | The time it took to execute the command | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -313,7 +469,7 @@ running `eval $(starship init $0)`, and then proceed as normal. [cmd_duration] min_time = 500 -prefix = "underwent " +format = "underwent [$duration](bold yellow)" ``` ## Conda @@ -328,12 +484,23 @@ This does not suppress conda's own prompt modifier, you may want to run `conda c ### Options -| Variable | Default | Description | -| ------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `truncation_length` | `1` | The number of directories the environment path should be truncated to, if the environment was created via `conda create -p [path]`. `0` means no truncation. Also see the [`directory`](#directory) module. | -| `symbol` | `"C "` | The symbol used before the environment name. | -| `style` | `"bold green"` | The style for the module. | -| `disabled` | `false` | Disables the `conda` module. | +| Option | Default | Description | +| ------------------- | ---------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `truncation_length` | `1` | The number of directories the environment path should be truncated to, if the environment was created via `conda create -p [path]`. `0` means no truncation. Also see the [`directory`](#directory) module. | +| `symbol` | `"🅒 "` | The symbol used before the environment name. | +| `style` | `"bold green"` | The style for the module. | +| `format` | `"[$symbol$environment]($style) "` | The format for the module. | +| `disabled` | `false` | Disables the `conda` module. | + +### Variables + +| Variable | Example | Description | +| ----------- | ------------ | ------------------------------------ | +| environment | `astronauts` | The current conda environment | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -341,7 +508,7 @@ This does not suppress conda's own prompt modifier, you may want to run `conda c # ~/.config/starship.toml [conda] -style = "dimmed green" +format = "[$symbol$environment](dimmed green) " ``` ## Crystal @@ -354,11 +521,22 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | ------------ | --------------------------------------------------------- | -| `symbol` | `"🔮 "` | The symbol used before displaying the version of crystal. | -| `style` | `"bold red"` | The style for the module. | -| `disabled` | `false` | Disables the `crystal` module. | +| Option | Default | Description | +| ---------- | ---------------------------------- | --------------------------------------------------------- | +| `symbol` | `"🔮 "` | The symbol used before displaying the version of crystal. | +| `style` | `"bold red"` | The style for the module. | +| `format` | `"via [$symbol$version]($style) "` | The format for the module. | +| `disabled` | `false` | Disables the `crystal` module. | + +### Variables + +| Variable | Example | Description | +| -------- | --------- | ------------------------------------ | +| version | `v0.32.1` | The version of `crystal` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -366,8 +544,7 @@ The module will be shown if any of the following conditions are met: # ~/.config/starship.toml [crystal] -symbol = "✨ " -style = "bold blue" +format = "via [✨ $version](bold blue) " ``` ## Directory @@ -386,18 +563,18 @@ it would have been `nixpkgs/pkgs`. ### Options -| Variable | Default | Description | -| ------------------- | ------------- | -------------------------------------------------------------------------------- | -| `truncation_length` | `3` | The number of parent folders that the current directory should be truncated to. | -| `truncate_to_repo` | `true` | Whether or not to truncate to the root of the git repo that you're currently in. | -| `prefix` | `"in "` | Prefix to display immediately before the directory. | -| `style` | `"bold cyan"` | The style for the module. | -| `disabled` | `false` | Disables the `directory` module. | +| Option | Default | Description | +| ------------------- | -------------------- | -------------------------------------------------------------------------------- | +| `truncation_length` | `3` | The number of parent folders that the current directory should be truncated to. | +| `truncate_to_repo` | `true` | Whether or not to truncate to the root of the git repo that you're currently in. | +| `format` | `"[$path]($style) "` | The format for the module. | +| `style` | `"bold cyan"` | The style for the module. | +| `disabled` | `false` | Disables the `directory` module. |
This module has a few advanced configuration options that control how the directory is displayed. -| Variable | Default | Description | +| Advanced Option | Default | Description | | --------------------------- | ------- | ---------------------------------------------------------------------------------------- | | `substitutions` | | A table of substitutions to be made to the path. | | `fish_style_pwd_dir_length` | `0` | The number of characters to use when applying fish shell pwd path logic. | @@ -420,6 +597,15 @@ a single character. For `fish_style_pwd_dir_length = 2`, it would be `/bu/th/ci/
+### Variables + +| Variable | Example | Description | +| -------- | --------------------- | ----------------------------------- | +| path | `"D:/Projects"` | The current directory path | +| style\* | `"black bold dimmed"` | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string + ### Example ```toml @@ -437,12 +623,23 @@ The `docker_context` module shows the currently active ### Options -| Variable | Default | Description | -| ----------------- | ------------- | ---------------------------------------------------------------------------- | -| `symbol` | `"🐳 "` | The symbol used before displaying the Docker context . | -| `only_with_files` | `false` | Only show when there's a `docker-compose.yml` or `Dockerfile` in the current directory. | -| `style` | `"bold blue"` | The style for the module. | -| `disabled` | `true` | Disables the `docker_context` module. | +| Option | Default | Description | +| ----------------- | ---------------------------------- | --------------------------------------------------------------------------------------- | +| `format` | `"via [$symbol$context]($style) "` | The format for the module. | +| `symbol` | `"🐳 "` | The symbol used before displaying the Docker context. | +| `style` | `"blue bold"` | The style for the module. | +| `only_with_files` | `false` | Only show when there's a `docker-compose.yml` or `Dockerfile` in the current directory. | +| `disabled` | `true` | Disables the `docker_context` module. | + +### Variables + +| Variable | Example | Description | +| -------- | -------------- | ------------------------------------ | +| context | `test_context` | The current docker context | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -450,7 +647,7 @@ The `docker_context` module shows the currently active # ~/.config/starship.toml [docker_context] -symbol = "🐋 " +format = "via [🐋 $context](blue bold)" ``` ## Dotnet @@ -461,15 +658,16 @@ shows the latest installed version of the SDK. This module will only be shown in your prompt when one or more of the following files are present in the current directory: -* `global.json` -* `project.json` -* `Directory.Build.props` -* `Directory.Build.targets` -* `Packages.props` -* `*.sln` -* `*.csproj` -* `*.fsproj` -* `*.xproj` + +- `global.json` +- `project.json` +- `Directory.Build.props` +- `Directory.Build.targets` +- `Packages.props` +- `*.sln` +- `*.csproj` +- `*.fsproj` +- `*.xproj` You'll also need the .NET Core SDK installed in order to use it correctly. @@ -478,14 +676,30 @@ as running `dotnet --version`, but it may show an incorrect version if your .NET unusual directory layout. If accuracy is more important than speed, you can disable the mechanism by setting `heuristic = false` in the module options. +The module will also show the Target Framework Moniker +() +when there is a csproj file in the current directory. + ### Options -| Variable | Default | Description | -| ----------- | ------------- | -------------------------------------------------------- | -| `symbol` | `"•NET "` | The symbol used before displaying the version of dotnet. | -| `heuristic` | `true` | Use faster version detection to keep starship snappy. | -| `style` | `"bold blue"` | The style for the module. | -| `disabled` | `false` | Disables the `dotnet` module. | +| Option | Default | Description | +| ----------- | ----------------------------------------- | -------------------------------------------------------- | +| `format` | `"v[$symbol$version( 🎯 $tfm)]($style) "` | The format for the module. | +| `symbol` | `"•NET "` | The symbol used before displaying the version of dotnet. | +| `heuristic` | `true` | Use faster version detection to keep starship snappy. | +| `style` | `"bold blue"` | The style for the module. | +| `disabled` | `false` | Disables the `dotnet` module. | + +### Variables + +| Variable | Example | Description | +| -------- | ---------------- | ------------------------------------------------------------------ | +| version | `v3.1.201` | The version of `dotnet` sdk | +| tfm | `netstandard2.0` | The Target Framework Moniker that the current project is targeting | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -507,11 +721,23 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | --------------- | --------------------------------------------------------------- | -| `symbol` | `"💧 "` | The symbol used before displaying the version of Elixir/Erlang. | -| `style` | `"bold purple"` | The style for the module. | -| `disabled` | `false` | Disables the `elixir` module. | +| Option | Default | Description | +| ---------- | --------------------------------------------------------- | --------------------------------------------------------------- | +| `symbol` | `"💧 "` | The symbol used before displaying the version of Elixir/Erlang. | +| `style` | `"bold purple"` | The style for the module. | +| `format` | `"via [$symbol$version \\(OTP $otp_version\\)]($style) "` | The format for the module elixir. | +| `disabled` | `false` | Disables the `elixir` module. | + +### Variables + +| Variable | Example | Description | +| ----------- | ------- | ------------------------------------ | +| version | `v1.10` | The version of `elixir` | +| otp_version | | The otp version of `elixir` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -535,12 +761,22 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | ------------- | ----------------------------------------------------- | -| `symbol` | `"🌳 "` | The symbol used before displaying the version of Elm. | -| `style` | `"bold cyan"` | The style for the module. | -| `disabled` | `false` | Disables the `elm` module. | +| Option | Default | Description | +| ---------- | ---------------------------------- | ----------------------------------------------- | +| `format` | `"via [$symbol$version]($style) "` | The format for the module. | +| `symbol` | `"🌳 "` | A format string representing the symbol of Elm. | +| `style` | `"cyan bold"` | The style for the module. | +| `disabled` | `false` | Disables the `elm` module. | +### Variables + +| Variable | Example | Description | +| -------- | --------- | ------------------------------------ | +| version | `v0.19.1` | The version of `elm` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -548,7 +784,7 @@ The module will be shown if any of the following conditions are met: # ~/.config/starship.toml [elm] -symbol = " " +format = "via [ $version](cyan bold) " ``` ## Environment Variable @@ -561,15 +797,23 @@ The module will be shown only if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | --------------------- | ---------------------------------------------------------------------------- | -| `symbol` | | The symbol used before displaying the variable value. | -| `variable` | | The environment variable to be displayed. | -| `default` | | The default value to be displayed when the selected variable is not defined. | -| `prefix` | `""` | Prefix to display immediately before the variable value. | -| `suffix` | `""` | Suffix to display immediately after the variable value. | -| `style` | `"dimmed bold black"` | The style for the module. | -| `disabled` | `false` | Disables the `env_var` module. | +| Option | Default | Description | +| ---------- | ------------------------------ | ---------------------------------------------------------------------------- | +| `symbol` | | The symbol used before displaying the variable value. | +| `variable` | | The environment variable to be displayed. | +| `default` | | The default value to be displayed when the selected variable is not defined. | +| `format` | `"with [$env_value]($style) "` | The format for the module. | +| `disabled` | `false` | Disables the `env_var` module. | + +### Variables + +| Variable | Example | Description | +| --------- | ------------------------------------------- | ------------------------------------------ | +| env_value | `Windows NT` (if *variable* would be `$OS`) | The environment value of option `variable` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | `black bold dimmed` | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -591,11 +835,22 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | ---------- | --------------------------------------------------------------- | -| `symbol` | `"🖧 "` | The symbol used before displaying the version of Erlang. | -| `style` | `bold red` | The style for this module. | -| `disabled` | `false` | Disables the `erlang` module. | +| Option | Default | Description | +| ---------- | ---------------------------------- | -------------------------------------------------------- | +| `symbol` | `"🖧 "` | The symbol used before displaying the version of erlang. | +| `style` | `"bold red"` | The style for the module. | +| `format` | `"via [$symbol$version]($style) "` | The format for the module. | +| `disabled` | `false` | Disables the `erlang` module. | + +### Variables + +| Variable | Example | Description | +| -------- | --------- | ------------------------------------ | +| version | `v22.1.3` | The version of `erlang` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -603,7 +858,7 @@ The module will be shown if any of the following conditions are met: # ~/.config/starship.toml [erlang] -symbol = "e " +format = "via [e $version](bold red) " ``` ## Git Branch @@ -612,13 +867,24 @@ The `git_branch` module shows the active branch of the repo in your current dire ### Options -| Variable | Default | Description | -| ------------------- | --------------- | ------------------------------------------------------------------------------------- | -| `symbol` | `" "` | The symbol used before the branch name of the repo in your current directory. | -| `truncation_length` | `2^63 - 1` | Truncates a git branch to X graphemes | -| `truncation_symbol` | `"…"` | The symbol used to indicate a branch name was truncated. You can use "" for no symbol | -| `style` | `"bold purple"` | The style for the module. | -| `disabled` | `false` | Disables the `git_branch` module. | +| Option | Default | Description | +| ------------------- | -------------------------------- | ---------------------------------------------------------------------------------------- | +| `format` | `"on [$symbol$branch]($style) "` | The format for the module. Use `"$branch"` to refer to the current branch name. | +| `symbol` | `" "` | A format string representing the symbol of git branch. | +| `style` | `"bold purple"` | The style for the module. | +| `truncation_length` | `2^63 - 1` | Truncates a git branch to X graphemes. | +| `truncation_symbol` | `"…"` | The symbol used to indicate a branch name was truncated. You can use `""` for no symbol. | +| `disabled` | `false` | Disables the `git_branch` module. | + +### Variables + +| Variable | Example | Description | +| -------- | -------- | ---------------------------------------------------------------------------------------------------- | +| branch | `master` | The current branch name, falls back to `HEAD` if there's no current branch (e.g. git detached HEAD). | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -637,14 +903,22 @@ The `git_commit` module shows the current commit hash of the repo in your curren ### Options -| Variable | Default | Description | -| -------------------- | -------------- | ----------------------------------------------------- | -| `commit_hash_length` | `7` | The length of the displayed git commit hash. | -| `prefix` | `"("` | Prefix to display immediately before git commit. | -| `suffix` | `")"` | Suffix to display immediately after git commit. | -| `style` | `"bold green"` | The style for the module. | -| `only_detached` | `true` | Only show git commit hash when in detached HEAD state | -| `disabled` | `false` | Disables the `git_commit` module. | +| Option | Default | Description | +| -------------------- | -------------------------- | ----------------------------------------------------- | +| `commit_hash_length` | `7` | The length of the displayed git commit hash. | +| `format` | `"[\\($hash\\)]($style) "` | The format for the module. | +| `style` | `"bold green"` | The style for the module. | +| `only_detached` | `true` | Only show git commit hash when in detached HEAD state | +| `disabled` | `false` | Disables the `git_commit` module. | + +### Variables + +| Variable | Example | Description | +| -------- | --------- | ----------------------------------- | +| hash | `b703eb3` | The current git commit hash | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -664,18 +938,29 @@ that information will be shown too. ### Options -| Variable | Default | Description | -| ------------------ | ------------------ | ---------------------------------------------------------------------------------------------------------------- | -| `rebase` | `"REBASING"` | The text displayed when a `rebase` is in progress. | -| `merge` | `"MERGING"` | The text displayed when a `merge` is in progress. | -| `revert` | `"REVERTING"` | The text displayed when a `revert` is in progress. | -| `cherry_pick` | `"CHERRY-PICKING"` | The text displayed when a `cherry-pick` is in progress. | -| `bisect` | `"BISECTING"` | The text displayed when a `bisect` is in progress. | -| `am` | `"AM"` | The text displayed when an `apply-mailbox` (`git am`) is in progress. | -| `am_or_rebase` | `"AM/REBASE"` | The text displayed when an ambiguous `apply-mailbox` or `rebase` is in progress. | -| `progress_divider` | `"/"` | The symbol or text which will separate the current and total progress amounts. (e.g., `" of "`, for `"3 of 10"`) | -| `style` | `"bold yellow"` | The style for the module. | -| `disabled` | `false` | Disables the `git_state` module. | +| Option | Default | Description | +| -------------- | --------------------------------------------------------------- | --------------------------------------------------------------------------------------- | +| `rebase` | `"REBASING"` | A format string displayed when a `rebase` is in progress. | +| `merge` | `"MERGING"` | A format string displayed when a `merge` is in progress. | +| `revert` | `"REVERTING"` | A format string displayed when a `revert` is in progress. | +| `cherry_pick` | `"CHERRY-PICKING"` | A format string displayed when a `cherry-pick` is in progress. | +| `bisect` | `"BISECTING"` | A format string displayed when a `bisect` is in progress. | +| `am` | `"AM"` | A format string displayed when an `apply-mailbox` (`git am`) is in progress. | +| `am_or_rebase` | `"AM/REBASE"` | A format string displayed when an ambiguous `apply-mailbox` or `rebase` is in progress. | +| `style` | `"bold yellow"` | The style for the module. | +| `format` | `"[\\($state( $progress_current/$progress_total)\\)]($style) "` | The format for the module. | +| `disabled` | `false` | Disables the `git_state` module. | + +### Variables + +| Variable | Example | Description | +| ---------------- | ---------- | ----------------------------------- | +| state | `REBASING` | The current state of the repo | +| progress_current | `1` | The current operation progress | +| progress_total | `2` | The total operation progress | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -683,8 +968,8 @@ that information will be shown too. # ~/.config/starship.toml [git_state] -progress_divider = " of " -cherry_pick = "🍒 PICKING" +format = "[\\($state( $progress_current of $progress_total)\\)]($style) " +cherry_pick = "[🍒 PICKING](bold red)" ``` ## Git Status @@ -694,37 +979,54 @@ current directory. ### Options -| Variable | Default | Description | -| ------------------ | -------------------------- | ------------------------------------------------------- | -| `conflicted` | `"="` | This branch has merge conflicts. | -| `conflicted_count` | [link](#git-status-counts) | Show and style the number of conflicts. | -| `ahead` | `"⇡"` | This branch is ahead of the branch being tracked. | -| `behind` | `"⇣"` | This branch is behind of the branch being tracked. | -| `diverged` | `"⇕"` | This branch has diverged from the branch being tracked. | -| `untracked` | `"?"` | There are untracked files in the working directory. | -| `untracked_count` | [link](#git-status-counts) | Show and style the number of untracked files. | -| `stashed` | `"$"` | A stash exists for the local repository. | -| `stashed_count` | [link](#git-status-counts) | Show and style the number of stashes. | -| `modified` | `"!"` | There are file modifications in the working directory. | -| `modified_count` | [link](#git-status-counts) | Show and style the number of modified files. | -| `staged` | `"+"` | A new file has been added to the staging area. | -| `staged_count` | [link](#git-status-counts) | Show and style the number of files staged files. | -| `renamed` | `"»"` | A renamed file has been added to the staging area. | -| `renamed_count` | [link](#git-status-counts) | Show and style the number of renamed files. | -| `deleted` | `"✘"` | A file's deletion has been added to the staging area. | -| `deleted_count` | [link](#git-status-counts) | Show and style the number of deleted files. | -| `show_sync_count` | `false` | Show ahead/behind count of the branch being tracked. | -| `prefix` | `[` | Prefix to display immediately before git status. | -| `suffix` | `]` | Suffix to display immediately after git status. | -| `style` | `"bold red"` | The style for the module. | -| `disabled` | `false` | Disables the `git_status` module. | +| Option | Default | Description | +| ----------------- | ------------------------------------------- | ---------------------------------------------------- | +| `format` | "([\[$all_status$ahead_behind\]]($style) )" | The default format for `git_status` | +| `conflicted` | `"="` | This branch has merge conflicts. | +| `ahead` | `"⇡"` | The format of `ahead` | +| `behind` | `"⇣"` | The format of `behind` | +| `diverged` | `"⇕"` | The format of `diverged` | +| `untracked` | `"?"` | The format of `untracked` | +| `stashed` | `"$"` | The format of `stashed` | +| `modified` | `"!"` | The format of `modified` | +| `staged` | `"+"` | The format of `staged` | +| `renamed` | `"»"` | The format of `renamed` | +| `deleted` | `"✘"` | The format of `deleted` | +| `show_sync_count` | `false` | Show ahead/behind count of the branch being tracked. | +| `style` | `"bold red"` | The style for the module. | +| `disabled` | `false` | Disables the `git_status` module. | -#### Git Status Counts +### Variables -| Variable | Default | Description | -| --------- | ------- | ------------------------------------------------------ | -| `enabled` | `false` | Show the number of files | -| `style` | | Optionally style the count differently than the module | +The following variables can be used in `format`: + +| Variable | Description | +| -------------- | --------------------------------------------------------------------------------------------- | +| `all_status` | Shortcut for`$conflicted$stashed$deleted$renamed$modified$staged$untracked` | +| `ahead_behind` | Displays `diverged` `ahead` or `behind` format string based on the current status of the repo | +| `conflicted` | Displays `conflicted` when this branch has merge conflicts. | +| `untracked` | Displays `untracked` when there are untracked files in the working directory. | +| `stashed` | Displays `stashed` when a stash exists for the local repository. | +| `modified` | Displays `modified` when there are file modifications in the working directory. | +| `staged` | Displays `staged` when a new file has been added to the staging area. | +| `renamed` | Displays `renamed` when a renamed file has been added to the staging area. | +| `deleted` | Displays `deleted` when a file's deletion has been added to the staging area. | +| style\* | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string + +The following variables can be used in `diverged`: + +| Variable | Description | +| -------------- | ---------------------------------------------- | +| `ahead_count` | Number of commits ahead of the tracking branch | +| `behind_count` | Number of commits behind the tracking branch | + +The following variables can be used in `conflicted`, `ahead`, `behind`, `untracked`, `stashed`, `modified`, `staged`, `renamed` and `deleted`: + +| Variable | Description | +| -------- | ------------------------ | +| `count` | Show the number of files | ### Example @@ -739,10 +1041,7 @@ diverged = "😵" untracked = "🤷‍" stashed = "📦" modified = "📝" -staged.value = "++" -staged.style = "green" -staged_count.enabled = true -staged_count.style = "green" +staged = '[++\($count\)](green)' renamed = "👅" deleted = "🗑" ``` @@ -763,11 +1062,22 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | ------------- | -------------------------------------------------------- | -| `symbol` | `"🐹 "` | The symbol used before displaying the version of Golang. | -| `style` | `"bold cyan"` | The style for the module. | -| `disabled` | `false` | Disables the `golang` module. | +| Option | Default | Description | +| ---------- | ---------------------------------- | ---------------------------------------------- | +| `format` | `"via [$symbol$version]($style) "` | The format for the module. | +| `symbol` | `"🐹 "` | A format string representing the symbol of Go. | +| `style` | `"bold cyan"` | The style for the module. | +| `disabled` | `false` | Disables the `golang` module. | + +### Variables + +| Variable | Example | Description | +| -------- | --------- | ------------------------------------ | +| version | `v1.12.1` | The version of `go` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -775,7 +1085,7 @@ The module will be shown if any of the following conditions are met: # ~/.config/starship.toml [golang] -symbol = "🏎💨 " +format = "via [🏎💨 $version](bold cyan) " ``` ## Hostname @@ -784,14 +1094,23 @@ The `hostname` module shows the system hostname. ### Options -| Variable | Default | Description | -| ---------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | -| `ssh_only` | `true` | Only show hostname when connected to an SSH session. | -| `prefix` | `""` | Prefix to display immediately before the hostname. | -| `suffix` | `""` | Suffix to display immediately after the hostname. | -| `trim_at` | `"."` | String that the hostname is cut off at, after the first match. `"."` will stop after the first dot. `""` will disable any truncation | -| `style` | `"bold dimmed green"` | The style for the module. | -| `disabled` | `false` | Disables the `hostname` module. | +| Option | Default | Description | +| ---------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | +| `ssh_only` | `true` | Only show hostname when connected to an SSH session. | +| `trim_at` | `"."` | String that the hostname is cut off at, after the first match. `"."` will stop after the first dot. `""` will disable any truncation | +| `format` | `"on [$hostname]($style) "` | The format for the module. | +| `style` | `"bold dimmed green"` | The style for the module. | +| `disabled` | `false` | Disables the `hostname` module. | + +### Variables + +| Variable | Example | Description | +| -------- | ------- | ------------------------------------ | +| number | `1` | The number of jobs | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -800,8 +1119,7 @@ The `hostname` module shows the system hostname. [hostname] ssh_only = false -prefix = "⟪" -suffix = "⟫" +format = "on [$hostname](bold red) " trim_at = ".companyname.com" disabled = false ``` @@ -816,11 +1134,22 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | -------------- | ------------------------------------------------------ | -| `symbol` | `"☕ "` | The symbol used before displaying the version of Java. | -| `style` | `"dimmed red"` | The style for the module. | -| `disabled` | `false` | Disables the `java` module. | +| Option | Default | Description | +| ---------- | -------------------------------------- | ----------------------------------------------- | +| `format` | `"via [${symbol}${version}]($style) "` | The format for the module. | +| `symbol` | `"☕ "` | A format string representing the symbol of Java | +| `style` | `"red dimmed"` | The style for the module. | +| `disabled` | `false` | Disables the `java` module. | + +### Variables + +| Variable | Example | Description | +| -------- | ------- | ------------------------------------ | +| version | `v14` | The version of `java` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -840,12 +1169,23 @@ more than the `threshold` config value, if it exists. ### Options -| Variable | Default | Description | -| ----------- | ------------- | ----------------------------------------------------- | -| `symbol` | `"✦"` | The symbol used before displaying the number of jobs. | -| `threshold` | `1` | Show number of jobs if exceeded. | -| `style` | `"bold blue"` | The style for the module. | -| `disabled` | `false` | Disables the `jobs` module. | +| Option | Default | Description | +| ----------- | ----------------------------- | ------------------------------------------------ | +| `threshold` | `1` | Show number of jobs if exceeded. | +| `format` | `"[$symbol$number]($style) "` | The format for the module. | +| `symbol` | `"✦"` | A format string representing the number of jobs. | +| `style` | `"bold blue"` | The style for the module. | +| `disabled` | `false` | Disables the `jobs` module. | + +### Variables + +| Variable | Example | Description | +| -------- | ------- | ------------------------------------ | +| number | `1` | The number of jobs | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -868,11 +1208,22 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | ------------- | -------------------------------------------------------- | -| `symbol` | `"ஃ "` | The symbol used before displaying the version of Julia. | -| `style` | `"bold purple"` | The style for the module. | -| `disabled` | `false` | Disables the `julia` module. | +| Option | Default | Description | +| ---------- | ---------------------------------- | ------------------------------------------------- | +| `format` | `"via [$symbol$version]($style) "` | The format for the module. | +| `symbol` | `"ஃ "` | A format string representing the symbol of Julia. | +| `style` | `"bold purple"` | The style for the module. | +| `disabled` | `false` | Disables the `julia` module. | + +### Variables + +| Variable | Example | Description | +| -------- | -------- | ------------------------------------ | +| version | `v1.4.0` | The version of `julia` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -882,12 +1233,13 @@ The module will be shown if any of the following conditions are met: [julia] symbol = "∴ " ``` + ## Kubernetes -Displays the current Kubernetes context name and, if set, the namespace from -the kubeconfig file. The namespace needs to be set in the kubeconfig file, this -can be done via `kubectl config set-context starship-cluster --namespace astronaut`. If the `$KUBECONFIG` env var is set the module will use that if -not it will use the `~/.kube/config`. +Displays the current Kubernetes context name and, if set, the namespace from the kubeconfig file. +The namespace needs to be set in the kubeconfig file, this can be done via +`kubectl config set-context starship-cluster --namespace astronaut`. +If the `$KUBECONFIG` env var is set the module will use that if not it will use the `~/.kube/config`. ::: tip @@ -898,12 +1250,25 @@ To enable it, set `disabled` to `false` in your configuration file. ### Options -| Variable | Default | Description | -| ---------------- | ------------- | --------------------------------------------------- | -| `symbol` | `"☸ "` | The symbol used before displaying the Cluster info. | -| `context_aliases` | | Table of context aliases to display | -| `style` | `"bold blue"` | The style for the module. | -| `disabled` | `true` | Disables the `kubernetes` module | +| Option | Default | Description | +| ----------------------- | ---------------------------------------------------- | --------------------------------------------------------------------- | +| `symbol` | `"☸ "` | A format string representing the symbol displayed before the Cluster. | +| `format` | `"on [$symbol$context( \\($namespace\\))]($style) "` | The format for the module. | +| `style` | `"cyan bold"` | The style for the module. | +| `namespace_spaceholder` | `none` | The value to display if no namespace was found. | +| `context_aliases` | | Table of context aliases to display. | +| `disabled` | `true` | Disables the `kubernetes` module. | + +### Variables + +| Variable | Example | Description | +| --------- | -------------------- | ---------------------------------------- | +| context | `starship-cluster` | The current kubernetes context | +| namespace | `starship-namespace` | If set, the current kubernetes namespace | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -911,8 +1276,7 @@ To enable it, set `disabled` to `false` in your configuration file. # ~/.config/starship.toml [kubernetes] -symbol = "⛵ " -style = "dimmed green" +format = "on [⛵ $context \\($namespace\\)](dimmed green) " disabled = false [kubernetes.context_aliases] "dev.local.cluster.k8s" = "dev" @@ -924,7 +1288,7 @@ The `line_break` module separates the prompt into two lines. ### Options -| Variable | Default | Description | +| Option | Default | Description | | ---------- | ------- | ------------------------------------------------------------------ | | `disabled` | `false` | Disables the `line_break` module, making the prompt a single line. | @@ -952,15 +1316,27 @@ To enable it, set `disabled` to `false` in your configuration file. ### Options -| Variable | Default | Description | -| ----------------- | --------------------- | ------------------------------------------------------------- | -| `show_percentage` | `false` | Display memory usage as a percentage of the available memory. | -| `show_swap` | `true` | Display swap usage if total swap is non-zero. | -| `threshold` | `75` | Hide the memory usage unless it exceeds this percentage. | -| `symbol` | `"🐏 "` | The symbol used before displaying the memory usage. | -| `separator` | `" | "` | The symbol or text that will seperate the ram and swap usage. | -| `style` | `"bold dimmed white"` | The style for the module. | -| `disabled` | `true` | Disables the `memory_usage` module. | +| Option | Default | Description | +| ----------- | --------------------------------------------- | -------------------------------------------------------- | +| `threshold` | `75` | Hide the memory usage unless it exceeds this percentage. | +| `format` | `"via $symbol [${ram}( | ${swap})]($style) "` | The format for the module. | +| `symbol` | `"🐏"` | The symbol used before displaying the memory usage. | +| `style` | `"bold dimmed white"` | The style for the module. | +| `disabled` | `true` | Disables the `memory_usage` module. | + +### Variables + +| Variable | Example | Description | +| ----------- | ------------- | ------------------------------------------------------------------ | +| ram | `31GiB/65GiB` | The usage/total RAM of the current system memory. | +| ram_pct | `48%` | The percentage of the current system memory. | +| swap\** | `1GiB/4GiB` | The swap memory size of the current system swap memory file. | +| swap_pct\** | `77%` | The swap memory percentage of the current system swap memory file. | +| symbol | `🐏` | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string +\*\*: The SWAP file information is only displayed if detected on the current system ### Example @@ -983,13 +1359,24 @@ The `hg_branch` module shows the active branch of the repo in your current direc ### Options -| Variable | Default | Description | -| ------------------- | --------------- | -------------------------------------------------------------------------------------------- | -| `symbol` | `" "` | The symbol used before the hg bookmark or branch name of the repo in your current directory. | -| `truncation_length` | `2^63 - 1` | Truncates the hg branch name to X graphemes | -| `truncation_symbol` | `"…"` | The symbol used to indicate a branch name was truncated. | -| `style` | `"bold purple"` | The style for the module. | -| `disabled` | `true` | Disables the `hg_branch` module. | +| Option | Default | Description | +| ------------------- | -------------------------------- | -------------------------------------------------------------------------------------------- | +| `symbol` | `" "` | The symbol used before the hg bookmark or branch name of the repo in your current directory. | +| `style` | `"bold purple"` | The style for the module. | +| `format` | `"on [$symbol$branch]($style) "` | The format for the module. | +| `truncation_length` | `2^63 - 1` | Truncates the hg branch name to X graphemes | +| `truncation_symbol` | `"…"` | The symbol used to indicate a branch name was truncated. | +| `disabled` | `true` | Disables the `hg_branch` module. | + +### Variables + +| Variable | Example | Description | +| -------- | -------- | ------------------------------------ | +| branch | `master` | The active mercurial branch | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -997,7 +1384,7 @@ The `hg_branch` module shows the active branch of the repo in your current direc # ~/.config/starship.toml [hg_branch] -symbol = "🌱 " +format = "on [🌱 $branch](bold purple)" truncation_length = 4 truncation_symbol = "" ``` @@ -1006,6 +1393,7 @@ truncation_symbol = "" The `nim` module shows the currently installed version of Nim. The module will be shown if any of the following conditions are met: + - The current directory contains a `nim.cfg` file - The current directory contains a file with the `.nim` extension - The current directory contains a file with the `.nims` extension @@ -1013,11 +1401,22 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | --------------- | ------------------------------------------------------ | -| `symbol` | `"👑 "` | The symbol used before displaying the version of Nim. | -| `style` | `"bold yellow"` | The style for the module. | -| `disabled` | `false` | Disables the `nim` module. | +| Option | Default | Description | +| ---------- | ---------------------------------- | ----------------------------------------------------- | +| `format` | `"via [$symbol$version]($style) "` | The format for the module | +| `symbol` | `"👑 "` | The symbol used before displaying the version of Nim. | +| `style` | `"bold yellow"` | The style for the module. | +| `disabled` | `false` | Disables the `nim` module. | + +### Variables + +| Variable | Example | Description | +| -------- | -------- | ------------------------------------ | +| version | `v1.2.0` | The version of `nimc` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -1036,14 +1435,25 @@ The module will be shown when inside a nix-shell environment. ### Options -| Variable | Default | Description | -| ------------ | ------------- | ------------------------------------------------- | -| `use_name` | `false` | Display the name of the nix-shell. | -| `impure_msg` | `"impure"` | Customize the "impure" msg. | -| `pure_msg` | `"pure"` | Customize the "pure" msg. | -| `symbol` | `"❄️ "` | The symbol used before displaying the shell name. | -| `style` | `"bold blue"` | The style for the module. | -| `disabled` | `false` | Disables the `nix_shell` module. | +| Option | Default | Description | +| ------------ | ---------------------------------------------- | ----------------------------------------------------- | +| `format` | `"via [$symbol$state( \\($name\\))]($style) "` | The format for the module. | +| `symbol` | `"❄️ "` | A format string representing the symbol of nix-shell. | +| `style` | `"bold blue"` | The style for the module. | +| `impure_msg` | `"impure"` | A format string shown when the shell is impure. | +| `pure_msg` | `"pure"` | A format string shown when the shell is pure. | +| `disabled` | `false` | Disables the `nix_shell` module. | + +### Variables + +| Variable | Example | Description | +| -------- | ------- | ------------------------------------ | +| state | `pure` | The state of the nix-shell | +| name | `lorri` | The name of the nix-shell | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -1052,10 +1462,9 @@ The module will be shown when inside a nix-shell environment. [nix_shell] disabled = true -use_name = true -impure_msg = "impure shell" -pure_msg = "pure shell" -symbol = "☃️ " +impure_msg = "[impure shell](bold red)" +pure_msg = "[pure shell](bold green)" +format = "via [☃️ $state( \\($name\\))](bold blue) " ``` ## NodeJS @@ -1071,11 +1480,22 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | -------------- | -------------------------------------------------------- | -| `symbol` | `"⬢ "` | The symbol used before displaying the version of NodeJS. | -| `style` | `"bold green"` | The style for the module. | -| `disabled` | `false` | Disables the `nodejs` module. | +| Option | Default | Description | +| ---------- | ---------------------------------- | -------------------------------------------------- | +| `format` | `"via [$symbol$version]($style) "` | The format for the module. | +| `symbol` | `"⬢ "` | A format string representing the symbol of NodeJS. | +| `style` | `"bold green"` | The style for the module. | +| `disabled` | `false` | Disables the `nodejs` module. | + +### Variables + +| Variable | Example | Description | +| -------- | ---------- | ------------------------------------ | +| version | `v13.12.0` | The version of `node` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -1083,7 +1503,7 @@ The module will be shown if any of the following conditions are met: # ~/.config/starship.toml [nodejs] -symbol = "🤖 " +format = "via [🤖 $version](bold green) " ``` ## Package Version @@ -1109,12 +1529,23 @@ package, and shows its current version. The module currently supports `npm`, `ca ### Options -| Variable | Default | Description | -| ----------------- | ------------ | ---------------------------------------------------------- | -| `symbol` | `"📦 "` | The symbol used before displaying the version the package. | -| `style` | `"bold 208"` | The style for the module. | -| `display_private` | `false` | Enable displaying version for packages marked as private. | -| `disabled` | `false` | Disables the `package` module. | +| Option | Default | Description | +| ----------------- | ---------------------------------- | ---------------------------------------------------------- | +| `format` | `"via [$symbol$version]($style) "` | The format for the module. | +| `symbol` | `"📦 "` | The symbol used before displaying the version the package. | +| `style` | `"bold 208"` | The style for the module. | +| `display_private` | `false` | Enable displaying version for packages marked as private. | +| `disabled` | `false` | Disables the `package` module. | + +### Variables + +| Variable | Example | Description | +| -------- | -------- | ------------------------------------ | +| version | `v1.0.0` | The version of your package | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -1122,7 +1553,7 @@ package, and shows its current version. The module currently supports `npm`, `ca # ~/.config/starship.toml [package] -symbol = "🎁 " +format = "via [🎁 $version](208 bold) " ``` ## OCaml @@ -1139,11 +1570,22 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | --------------- | ------------------------------------------------------- | -| `symbol` | `"🐫 "` | The symbol used before displaying the version of OCaml. | -| `style` | `"bold yellow"` | The style for the module. | -| `disabled` | `false` | Disables the `ocaml` module. | +| Option | Default | Description | +| ---------- | ---------------------------------- | ------------------------------------------------------- | +| `format` | `"via [$symbol$version]($style) "` | The format string for the module. | +| `symbol` | `"🐫 "` | The symbol used before displaying the version of OCaml. | +| `style` | `"bold yellow"` | The style for the module. | +| `disabled` | `false` | Disables the `ocaml` module. | + +### Variables + +| Variable | Example | Description | +| -------- | --------- | ------------------------------------ | +| version | `v4.10.0` | The version of `ocaml` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -1151,7 +1593,7 @@ The module will be shown if any of the following conditions are met: # ~/.config/starship.toml [ocaml] -symbol = "🐪 " +format = "via [🐪 $version]($style) " ``` ## PHP @@ -1165,11 +1607,22 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | ------------ | ----------------------------------------------------- | -| `symbol` | `"🐘 "` | The symbol used before displaying the version of PHP. | -| `style` | `"bold 147"` | The style for the module. | -| `disabled` | `false` | Disables the `php` module. | +| Option | Default | Description | +| ---------- | ---------------------------------- | ----------------------------------------------------- | +| `format` | `"via [$symbol$version]($style) "` | The format for the module. | +| `symbol` | `"🐘 "` | The symbol used before displaying the version of PHP. | +| `style` | `"147 bold"` | The style for the module. | +| `disabled` | `false` | Disables the `php` module. | + +### Variables + +| Variable | Example | Description | +| -------- | -------- | ------------------------------------ | +| version | `v7.3.8` | The version of `php` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -1177,7 +1630,7 @@ The module will be shown if any of the following conditions are met: # ~/.config/starship.toml [php] -symbol = "🔹 " +format = "via [🔹 $version](147 bold) " ``` ## Python @@ -1202,20 +1655,29 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| -------------------- | --------------- | --------------------------------------------------------------------------- | -| `symbol` | `"🐍 "` | The symbol used before displaying the version of Python. | -| `pyenv_version_name` | `false` | Use pyenv to get Python version | -| `pyenv_prefix` | `"pyenv "` | Prefix before pyenv version display (default display is `pyenv MY_VERSION`) | -| `scan_for_pyfiles` | `true` | If false, Python files in the current directory will not show this module. | -| `style` | `"bold yellow"` | The style for the module. | -| `disabled` | `false` | Disables the `python` module. | +| Option | Default | Description | +| -------------------- | ---------------------------------------------------------- | -------------------------------------------------------------------------- | +| `format` | `"via [${symbol}${version}( \\($virtualenv\\))]($style) "` | The format for the module. | +| `symbol` | `"🐍 "` | A format string representing the symbol of Python | +| `style` | `"yellow bold"` | The style for the module. | +| `pyenv_version_name` | `false` | Use pyenv to get Python version | +| `scan_for_pyfiles` | `true` | If false, Python files in the current directory will not show this module. | +| `disabled` | `false` | Disables the `python` module. | + +### Variables + +| Variable | Example | Description | +| ---------- | --------------- | ------------------------------------ | +| version | `"v3.8.1"` | The version of `python` | +| symbol | `"🐍 "` | Mirrors the value of option `symbol` | +| style | `"yellow bold"` | Mirrors the value of option `style` | +| virtualenv | `"venv"` | The current `virtualenv` name |
This module has some advanced configuration options. -| Variable | Default | Description | -| --------------- | -------- | ---------------------------------------------------------------------------- | +| Variable | Default | Description | +| --------------- | -------- | ----------------------------------------------------------------------------- | | `python_binary` | `python` | Configures the python binary that Starship executes when getting the version. | The `python_binary` variable changes the binary that Starship executes to get @@ -1252,11 +1714,22 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | ------------ | ------------------------------------------------------ | -| `symbol` | `"💎 "` | The symbol used before displaying the version of Ruby. | -| `style` | `"bold red"` | The style for the module. | -| `disabled` | `false` | Disables the `ruby` module. | +| Option | Default | Description | +| ---------- | ---------------------------------- | ------------------------------------------------ | +| `format` | `"via [$symbol$version]($style) "` | The format for the module. | +| `symbol` | `"💎 "` | A format string representing the symbol of Ruby. | +| `style` | `"bold red"` | The style for the module. | +| `disabled` | `false` | Disables the `ruby` module. | + +### Variables + +| Variable | Example | Description | +| -------- | -------- | ------------------------------------ | +| version | `v2.5.1` | The version of `ruby` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -1277,11 +1750,22 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | ------------ | ------------------------------------------------------ | -| `symbol` | `"🦀 "` | The symbol used before displaying the version of Rust. | -| `style` | `"bold red"` | The style for the module. | -| `disabled` | `false` | Disables the `rust` module. | +| Option | Default | Description | +| ---------- | ---------------------------------- | ----------------------------------------------- | +| `format` | `"via [$symbol$version]($style) "` | The format for the module. | +| `symbol` | `"🦀 "` | A format string representing the symbol of Rust | +| `style` | `"bold red"` | The style for the module. | +| `disabled` | `false` | Disables the `rust` module. | + +### Variables + +| Variable | Example | Description | +| -------- | ----------------- | ------------------------------------ | +| version | `v1.43.0-nightly` | The version of `rustc` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -1289,7 +1773,7 @@ The module will be shown if any of the following conditions are met: # ~/.config/starship.toml [rust] -symbol = "⚙️ " +format = "via [⚙️ $version](red bold)" ``` ## Singularity @@ -1299,14 +1783,22 @@ and `$SINGULARITY_NAME` is set. ### Options -| Variable | Default | Description | -| ---------- | -------------------- | ------------------------------------------------ | -| `label` | `""` | Prefix before the image name display. | -| `prefix` | `"["` | Prefix to display immediately before image name. | -| `suffix` | `"]"` | Suffix to display immediately after image name. | -| `symbol` | `""` | The symbol used before the image name. | -| `style` | `"bold dimmed blue"` | The style for the module. | -| `disabled` | `false` | Disables the `singularity` module. | +| Option | Default | Description | +| ---------- | -------------------------------- | ------------------------------------------------ | +| `format` | `"[$symbol\\[$env\\]]($style) "` | The format for the module. | +| `symbol` | `""` | A format string displayed before the image name. | +| `style` | `"bold dimmed blue"` | The style for the module. | +| `disabled` | `false` | Disables the `singularity` module. | + +### Variables + +| Variable | Example | Description | +| -------- | ------------ | ------------------------------------ | +| env | `centos.img` | The current singularity image | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -1314,13 +1806,14 @@ and `$SINGULARITY_NAME` is set. # ~/.config/starship.toml [singularity] -symbol = "📦 " +format = "[📦 \\[$env\\]]($style) " ``` ## Terraform The `terraform` module shows the currently selected terraform workspace and version. By default the terraform version is not shown, since this is slow on current versions of terraform when a lot of plugins are in use. +If you still want to enable it, [follow the example shown below](#with-version). The module will be shown if any of the following conditions are met: - The current directory contains a `.terraform` folder @@ -1328,20 +1821,42 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| -------------- | ------------ | ----------------------------------------------------------- | -| `symbol` | `"💠 "` | The symbol used before displaying the terraform workspace. | -| `show_version` | `false` | Shows the terraform version. Very slow on large workspaces. | -| `style` | `"bold 105"` | The style for the module. | -| `disabled` | `false` | Disables the `terraform` module. | +| Option | Default | Description | +| ---------- | ------------------------------------ | ----------------------------------------------------- | +| `format` | `"via [$symbol$workspace]($style) "` | The format string for the module. | +| `symbol` | `"💠 "` | A format string shown before the terraform workspace. | +| `style` | `"bold 105"` | The style for the module. | +| `disabled` | `false` | Disables the `terraform` module. | + +### Variables + +| Variable | Example | Description | +| --------- | ---------- | ------------------------------------ | +| version | `v0.12.24` | The version of `terraform` | +| workspace | `default` | The current terraform workspace | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example +#### With Version + ```toml # ~/.config/starship.toml [terraform] -symbol = "🏎💨 " +format = "[🏎💨 $version$workspace]($style) " +``` + +#### Without version + +```toml +# ~/.config/starship.toml + +[terraform] +format = "[🏎💨 $workspace]($style) " ``` ## Time @@ -1358,17 +1873,27 @@ To enable it, set `disabled` to `false` in your configuration file. ### Options -| Variable | Default | Description | -| ----------------- | --------------- | ------------------------------------------------------------------------------------------------------------------- | -| `use_12hr` | `false` | Enables 12 hour formatting. | -| `format` | see below | The [chrono format string](https://docs.rs/chrono/0.4.7/chrono/format/strftime/index.html) used to format the time. | -| `style` | `"bold yellow"` | The style for the module time. | -| `utc_time_offset` | `"local"` | Sets the UTC offset to use. Range from -24 < x < 24. Allows floats to accommodate 30/45 minute timezone offsets. | -| `disabled` | `true` | Disables the `time` module. | -| `time_range` | `"-"` | Sets the time range during which the module will be shown. Times must be specified in 24-hours format | +| Option | Default | Description | +| ----------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------- | +| `format` | `"at [$time]($style) "` | The format string for the module. | +| `use_12hr` | `false` | Enables 12 hour formatting | +| `time_format` | see below | The [chrono format string](https://docs.rs/chrono/0.4.7/chrono/format/strftime/index.html) used to format the time. | +| `style` | `"bold yellow"` | The style for the module time | +| `utc_time_offset` | `"local"` | Sets the UTC offset to use. Range from -24 < x < 24. Allows floats to accommodate 30/45 minute timezone offsets. | +| `disabled` | `true` | Disables the `time` module. | +| `time_range` | `"-"` | Sets the time range during which the module will be shown. Times must be specified in 24-hours format | -If `use_12hr` is `true`, then `format` defaults to `"%r"`. Otherwise, it defaults to `"%T"`. -Manually setting `format` will override the `use_12hr` setting. +If `use_12hr` is `true`, then `time_format` defaults to `"%r"`. Otherwise, it defaults to `"%T"`. +Manually setting `time_format` will override the `use_12hr` setting. + +### Variables + +| Variable | Example | Description | +| -------- | ---------- | ----------------------------------- | +| time | `13:08:10` | The current time. | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -1377,7 +1902,8 @@ Manually setting `format` will override the `use_12hr` setting. [time] disabled = false -format = "🕙[ %T ]" +format = "🕙[\\[ $time \\]]($style) " +time_format = "%T" utc_time_offset = "-5" time_range = "10:00:00-14:00:00" ``` @@ -1394,12 +1920,20 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ------------- | --------------- | ------------------------------------- | -| `style_root` | `"bold red"` | The style used when the user is root. | -| `style_user` | `"bold yellow"` | The style used for non-root users. | -| `show_always` | `false` | Always shows the `username` module. | -| `disabled` | `false` | Disables the `username` module. | +| Option | Default | Description | +| ------------- | ------------------------ | ------------------------------------- | +| `style_root` | `"bold red"` | The style used when the user is root. | +| `style_user` | `"bold yellow"` | The style used for non-root users. | +| `format` | `"via [$user]($style) "` | The format for the module. | +| `show_always` | `false` | Always shows the `username` module. | +| `disabled` | `false` | Disables the `username` module. | + +### Variables + +| Variable | Example | Description | +| -------- | ------------ | ------------------------------------------------------------------------------------------- | +| `style` | `"red bold"` | Mirrors the value of option `style_root` when root is logged in and `style_user` otherwise. | +| `user` | `"matchai"` | The currently logged-in user ID. | ### Example @@ -1407,10 +1941,13 @@ The module will be shown if any of the following conditions are met: # ~/.config/starship.toml [username] -disabled = true +style_user = "white bold" +style_root = "black bold" +format = "user: [$user]($style) " +disabled = false +show_always = true ``` - ## Zig The `zig` module shows the currently installed version of Zig. @@ -1420,11 +1957,22 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | ------------ | ------------------------------------------------------ | -| `symbol` | `"↯ "` | The symbol used before displaying the version of Zig. | -| `style` | `"bold yellow"` | The style for the module. | -| `disabled` | `false` | Disables the `zig` module. | +| Option | Default | Description | +| ---------- | ---------------------------------- | ----------------------------------------------------- | +| `symbol` | `"↯ "` | The symbol used before displaying the version of Zig. | +| `style` | `"bold yellow"` | The style for the module. | +| `format` | `"via [$symbol$version]($style) "` | The format for the module. | +| `disabled` | `false` | Disables the `zig` module. | + +### Variables + +| Variable | Example | Description | +| -------- | -------- | ------------------------------------ | +| version | `v0.6.0` | The version of `zig` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -1440,6 +1988,7 @@ symbol = "⚡️ " The `custom` modules show the output of some arbitrary commands. These modules will be shown if any of the following conditions are met: + - The current directory contains a file whose name is in `files` - The current directory contains a directory whose name is in `directories` - The current directory contains a file whose extension is in `extensions` @@ -1461,24 +2010,34 @@ will simply show all custom modules in the order they were defined. ### Options -| Variable | Default | Description | -| ------------- | ------------------- | ---------------------------------------------------------------------------- | -| `command` | | The command whose output should be printed. | -| `when` | | A shell command used as a condition to show the module. The module will be shown if the command returns a `0` status code. | -| `shell` | | [See below](#custom-command-shell) | -| `description` | `""` | The description of the module that is shown when running `starship explain`. | -| `files` | `[]` | The files that will be searched in the working directory for a match. | -| `directories` | `[]` | The directories that will be searched in the working directory for a match. | -| `extensions` | `[]` | The extensions that will be searched in the working directory for a match. | -| `symbol` | `""` | The symbol used before displaying the command output. | -| `style` | `"bold green"` | The style for the module. | -| `prefix` | `""` | Prefix to display immediately before the command output. | -| `suffix` | `""` | Suffix to display immediately after the command output. | -| `disabled` | `false` | Disables this `custom` module. | +| Option | Default | Description | +| ------------- | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------- | +| `command` | | The command whose output should be printed. | +| `when` | | A shell command used as a condition to show the module. The module will be shown if the command returns a `0` status code. | +| `shell` | | [See below](#custom-command-shell) | +| `description` | `""` | The description of the module that is shown when running `starship explain`. | +| `files` | `[]` | The files that will be searched in the working directory for a match. | +| `directories` | `[]` | The directories that will be searched in the working directory for a match. | +| `extensions` | `[]` | The extensions that will be searched in the working directory for a match. | +| `symbol` | `""` | The symbol used before displaying the command output. | +| `style` | `"bold green"` | The style for the module. | +| `format` | `"[$symbol$output]($style) "` | The format for the module. | +| `disabled` | `false` | Disables this `custom` module. | + +### Variables + +| Variable | Description | +| -------- | -------------------------------------- | +| output | The output of shell command in `shell` | +| symbol | Mirrors the value of option `symbol` | +| style\* | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string #### Custom command shell `shell` accepts a non-empty list of strings, where: + - The first string is the path to the shell to use to execute the command. - Other following arguments are passed to the shell. @@ -1543,11 +2102,22 @@ The module will be shown if any of the following conditions are met: ### Options -| Variable | Default | Description | -| ---------- | -------------- | ------------------------------------------------------------ | -| `symbol` | `"<=> "` | The symbol used before displaying the version of PureScript. | -| `style` | `"bold white"` | The style for the module. | -| `disabled` | `false` | Disables the `purescript` module. | +| Option | Default | Description | +| ---------- | ---------------------------------- | ------------------------------------------------------------ | +| `format` | `"via [$symbol$version]($style) "` | The format for the module. | +| `symbol` | `"<=> "` | The symbol used before displaying the version of PureScript. | +| `style` | `"bold white"` | The style for the module. | +| `disabled` | `false` | Disables the `purescript` module. | + +### Variables + +| Variable | Example | Description | +| -------- | -------- | ------------------------------------ | +| version | `0.13.5` | The version of `purescript` | +| symbol | | Mirrors the value of option `symbol` | +| style\* | | Mirrors the value of option `style` | + +\*: This variable can only be used as a part of a style string ### Example @@ -1555,5 +2125,5 @@ The module will be shown if any of the following conditions are met: # ~/.config/starship.toml [purescript] -symbol = "<=> " +format = "via [$symbol$version](bold white)" ``` diff --git a/src/config.rs b/src/config.rs index fe60edad..be55af0f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -235,37 +235,84 @@ impl StarshipConfig { /// Get the subset of the table for a module by its name pub fn get_module_config(&self, module_name: &str) -> Option<&Value> { - let module_config = self.config.as_ref()?.as_table()?.get(module_name); + let module_config = self.get_config(&[module_name]); if module_config.is_some() { log::debug!( "Config found for \"{}\": \n{:?}", &module_name, &module_config ); - } else { - log::trace!("No config found for \"{}\"", &module_name); } module_config } + /// Get the value of the config in a specific path + pub fn get_config(&self, path: &[&str]) -> Option<&Value> { + let mut prev_table = self.config.as_ref()?.as_table()?; + + assert_ne!( + path.len(), + 0, + "Starship::get_config called with an empty path" + ); + + let (table_options, _) = path.split_at(path.len() - 1); + + // Assumes all keys except the last in path has a table + for option in table_options { + match prev_table.get(*option) { + Some(value) => match value.as_table() { + Some(value) => { + prev_table = value; + } + None => { + log::trace!( + "No config found for \"{}\": \"{}\" is not a table", + path.join("."), + &option + ); + return None; + } + }, + None => { + log::trace!( + "No config found for \"{}\": Option \"{}\" not found", + path.join("."), + &option + ); + return None; + } + } + } + + let last_option = path.last().unwrap(); + let value = prev_table.get(*last_option); + if value.is_none() { + log::trace!( + "No config found for \"{}\": Option \"{}\" not found", + path.join("."), + &last_option + ); + }; + value + } + /// Get the subset of the table for a custom module by its name pub fn get_custom_module_config(&self, module_name: &str) -> Option<&Value> { - let module_config = self.get_custom_modules()?.get(module_name); + let module_config = self.get_config(&["custom", module_name]); if module_config.is_some() { log::debug!( "Custom config found for \"{}\": \n{:?}", &module_name, &module_config ); - } else { - log::trace!("No custom config found for \"{}\"", &module_name); } module_config } /// Get the table of all the registered custom modules, if any pub fn get_custom_modules(&self) -> Option<&toml::value::Table> { - self.config.as_ref()?.as_table()?.get("custom")?.as_table() + self.get_config(&["custom"])?.as_table() } pub fn get_root_config(&self) -> StarshipRootConfig { @@ -277,75 +324,6 @@ impl StarshipConfig { } } -#[derive(Clone)] -pub struct SegmentConfig<'a> { - pub value: &'a str, - pub style: Option