fix: use suffixes for modules before directory (#1645)

Previously, all modules would have prefixes, which lead to the first
module having a dangling prefix. This change ensures that the first
few modules would instead have suffixes so that we don't start or
end with a prefix or suffix.
This commit is contained in:
Matan Kushner 2020-09-08 12:09:21 -04:00 committed by GitHub
parent 17e8115f16
commit d3100c5c82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 76 additions and 77 deletions

View File

@ -7,6 +7,7 @@ mkdir -p ~/.config && touch ~/.config/starship.toml
``` ```
All configuration for starship is done in this [TOML](https://github.com/toml-lang/toml) file: All configuration for starship is done in this [TOML](https://github.com/toml-lang/toml) file:
```toml ```toml
# Don't print a new line at the start of the prompt # Don't print a new line at the start of the prompt
add_newline = false add_newline = false
@ -101,7 +102,7 @@ For example:
The following symbols have special usage in a format string. 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 (`\`). If you want to print the following symbols, you have to escape them with a backslash (`\`).
- $ - \$
- \\ - \\
- [ - [
- ] - ]
@ -874,7 +875,7 @@ The module will be shown only if any of the following conditions are met:
| Variable | Example | Description | | Variable | Example | Description |
| --------- | ------------------------------------------- | ------------------------------------------ | | --------- | ------------------------------------------- | ------------------------------------------ |
| env_value | `Windows NT` (if *variable* would be `$OS`) | The environment value of option `variable` | | env_value | `Windows NT` (if _variable_ would be `$OS`) | The environment value of option `variable` |
| symbol | | Mirrors the value of option `symbol` | | symbol | | Mirrors the value of option `symbol` |
| style\* | `black bold dimmed` | Mirrors the value of option `style` | | style\* | `black bold dimmed` | Mirrors the value of option `style` |
@ -902,7 +903,7 @@ The module will be shown if any of the following conditions are met:
| Option | Default | Description | | Option | Default | Description |
| ---------- | ---------------------------------- | -------------------------------------------------------- | | ---------- | ---------------------------------- | -------------------------------------------------------- |
| `symbol` | `"🖧 "` | The symbol used before displaying the version of erlang. | | `symbol` | `"🖧 "` | The symbol used before displaying the version of erlang. |
| `style` | `"bold red"` | The style for the module. | | `style` | `"bold red"` | The style for the module. |
| `format` | `"via [$symbol$version]($style) "` | The format for the module. | | `format` | `"via [$symbol$version]($style) "` | The format for the module. |
| `disabled` | `false` | Disables the `erlang` module. | | `disabled` | `false` | Disables the `erlang` module. |
@ -933,13 +934,13 @@ This is based on the `~/.config/gcloud/active_config` file and the `~/.config/gc
### Options ### Options
| Variable | Default | Description | | Variable | Default | Description |
| ----------------- | ------------------------------------------------- | --------------------------------------------------------------------------- | | ---------------- | ------------------------------------------------ | --------------------------------------------------------------- |
| `format` | `"on [$symbol$account(\\($region\\))]($style) "` | The format for the module. | | `format` | `"on [$symbol$account(\\($region\\))]($style) "` | The format for the module. |
| `symbol` | `"☁️ "` | The symbol used before displaying the current GCP profile. | | `symbol` | `"☁️ "` | The symbol used before displaying the current GCP profile. |
| `region_aliases` | | Table of region aliases to display in addition to the GCP name. | | `region_aliases` | | Table of region aliases to display in addition to the GCP name. |
| `style` | `"bold blue"` | The style for the module. | | `style` | `"bold blue"` | The style for the module. |
| `disabled` | `false` | Disables the `gcloud` module. | | `disabled` | `false` | Disables the `gcloud` module. |
### Variables ### Variables
@ -995,7 +996,7 @@ The `git_branch` module shows the active branch of the repo in your current dire
| Option | Default | Description | | Option | Default | Description |
| ------------------- | -------------------------------- | ---------------------------------------------------------------------------------------- | | ------------------- | -------------------------------- | ---------------------------------------------------------------------------------------- |
| `format` | `"on [$symbol$branch]($style) "` | The format for the module. Use `"$branch"` to refer to the current branch name. | | `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. | | `symbol` | `" "` | A format string representing the symbol of git branch. |
| `style` | `"bold purple"` | The style for the module. | | `style` | `"bold purple"` | The style for the module. |
| `truncation_length` | `2^63 - 1` | Truncates a git branch to X graphemes. | | `truncation_length` | `2^63 - 1` | Truncates a git branch to X graphemes. |
@ -1131,12 +1132,12 @@ The following variables can be used in `format`:
| `all_status` | Shortcut for`$conflicted$stashed$deleted$renamed$modified$staged$untracked` | | `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 | | `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. | | `conflicted` | Displays `conflicted` when this branch has merge conflicts. |
| `untracked` | Displays `untracked` when there are untracked files in the working directory. | | `untracked` | Displays `untracked` when there are untracked files in the working directory. |
| `stashed` | Displays `stashed` when a stash exists for the local repository. | | `stashed` | Displays `stashed` when a stash exists for the local repository. |
| `modified` | Displays `modified` when there are file modifications in the working directory. | | `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. | | `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. | | `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. | | `deleted` | Displays `deleted` when a file's deletion has been added to the staging area. |
| style\* | Mirrors the value of option `style` | | style\* | Mirrors the value of option `style` |
\*: This variable can only be used as a part of a style string \*: This variable can only be used as a part of a style string
@ -1224,20 +1225,20 @@ The module will be shown if any of the following conditions are met:
### Options ### Options
| Option | Default | Description | | Option | Default | Description |
| ---------- | ---------------------------------- | ---------------------------------------------- | | ---------- | ---------------------------------- | ------------------------------------------------ |
| `format` | `"via [$symbol$version]($style) "` | The format for the module. | | `format` | `"via [$symbol$version]($style) "` | The format for the module. |
| `symbol` | `"⎈ "` | A format string representing the symbol of Helm. | | `symbol` | `"⎈ "` | A format string representing the symbol of Helm. |
| `style` | `"bold white"` | The style for the module. | | `style` | `"bold white"` | The style for the module. |
| `disabled` | `false` | Disables the `helm` module. | | `disabled` | `false` | Disables the `helm` module. |
### Variables ### Variables
| Variable | Example | Description | | Variable | Example | Description |
| -------- | --------- | ------------------------------------ | | -------- | -------- | ------------------------------------ |
| version | `v3.1.1` | The version of `helm` | | version | `v3.1.1` | The version of `helm` |
| symbol | | Mirrors the value of option `symbol` | | symbol | | Mirrors the value of option `symbol` |
| style\* | | Mirrors the value of option `style` | | style\* | | Mirrors the value of option `style` |
\*: This variable can only be used as a part of a style string \*: This variable can only be used as a part of a style string
@ -1260,7 +1261,7 @@ The `hostname` module shows the system hostname.
| ---------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | | ---------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `ssh_only` | `true` | Only show hostname when connected to an SSH session. | | `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 | | `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. | | `format` | `"[$hostname]($style) in "` | The format for the module. |
| `style` | `"bold dimmed green"` | The style for the module. | | `style` | `"bold dimmed green"` | The style for the module. |
| `disabled` | `false` | Disables the `hostname` module. | | `disabled` | `false` | Disables the `hostname` module. |
@ -1413,8 +1414,8 @@ To enable it, set `disabled` to `false` in your configuration file.
| Option | Default | Description | | Option | Default | Description |
| ----------------------- | ---------------------------------------------------- | --------------------------------------------------------------------- | | ----------------------- | ---------------------------------------------------- | --------------------------------------------------------------------- |
| `symbol` | `"☸ "` | A format string representing the symbol displayed before the Cluster. | | `symbol` | `"☸ "` | A format string representing the symbol displayed before the Cluster. |
| `format` | `"on [$symbol$context( \\($namespace\\))]($style) "` | The format for the module. | | `format` | `"[$symbol$context( \\($namespace\\))]($style) in "` | The format for the module. |
| `style` | `"cyan bold"` | The style for the module. | | `style` | `"cyan bold"` | The style for the module. |
| `namespace_spaceholder` | `none` | The value to display if no namespace was found. | | `namespace_spaceholder` | `none` | The value to display if no namespace was found. |
| `context_aliases` | | Table of context aliases to display. | | `context_aliases` | | Table of context aliases to display. |
@ -1487,14 +1488,14 @@ To enable it, set `disabled` to `false` in your configuration file.
### Variables ### Variables
| Variable | Example | Description | | Variable | Example | Description |
| ----------- | ------------- | ------------------------------------------------------------------ | | ------------ | ------------- | ------------------------------------------------------------------ |
| ram | `31GiB/65GiB` | The usage/total RAM of the current system memory. | | ram | `31GiB/65GiB` | The usage/total RAM of the current system memory. |
| ram_pct | `48%` | The percentage 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\*\* | `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. | | swap_pct\*\* | `77%` | The swap memory percentage of the current system swap memory file. |
| symbol | `🐏` | Mirrors the value of option `symbol` | | symbol | `🐏` | Mirrors the value of option `symbol` |
| style\* | | Mirrors the value of option `style` | | style\* | | Mirrors the value of option `style` |
\*: This variable can only be used as a part of a style string \*: 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 \*\*: The SWAP file information is only displayed if detected on the current system
@ -1599,7 +1600,7 @@ The module will be shown when inside a nix-shell environment.
| Option | Default | Description | | Option | Default | Description |
| ------------ | ---------------------------------------------- | ----------------------------------------------------- | | ------------ | ---------------------------------------------- | ----------------------------------------------------- |
| `format` | `"via [$symbol$state( \\($name\\))]($style) "` | The format for the module. | | `format` | `"via [$symbol$state( \\($name\\))]($style) "` | The format for the module. |
| `symbol` | `"❄️ "` | A format string representing the symbol of nix-shell. | | `symbol` | `"❄️ "` | A format string representing the symbol of nix-shell. |
| `style` | `"bold blue"` | The style for the module. | | `style` | `"bold blue"` | The style for the module. |
| `impure_msg` | `"impure"` | A format string shown when the shell is impure. | | `impure_msg` | `"impure"` | A format string shown when the shell is impure. |
| `pure_msg` | `"pure"` | A format string shown when the shell is pure. | | `pure_msg` | `"pure"` | A format string shown when the shell is pure. |
@ -1759,7 +1760,6 @@ The module will be shown if any of the following conditions are met:
format = "via [🐪 $version]($style) " format = "via [🐪 $version]($style) "
``` ```
## Perl ## Perl
The `perl` module shows the currently installed version of Perl. The `perl` module shows the currently installed version of Perl.
@ -1774,8 +1774,8 @@ The module will be shown if any of the following conditions are met:
### Options ### Options
| Variable | Default | Description | | Variable | Default | Description |
| ---------- |----------------------------------- | ----------------------------------------------------- | | ---------- | ---------------------------------- | ----------------------------------------------------- |
| `format` | `"via [$symbol$version]($style) "` | The format string for the module.| | `format` | `"via [$symbol$version]($style) "` | The format string for the module. |
| `symbol` | `"🐪 "` | The symbol used before displaying the version of Perl | | `symbol` | `"🐪 "` | The symbol used before displaying the version of Perl |
| `style` | `"bold 149"` | The style for the module. | | `style` | `"bold 149"` | The style for the module. |
| `disabled` | `false` | Disables the `perl` module. | | `disabled` | `false` | Disables the `perl` module. |
@ -1797,7 +1797,6 @@ The module will be shown if any of the following conditions are met:
format = "via [🦪 $version]($style) " format = "via [🦪 $version]($style) "
``` ```
## PHP ## PHP
The `php` module shows the currently installed version of PHP. The `php` module shows the currently installed version of PHP.
@ -1985,21 +1984,21 @@ set to a number and meets or exceeds the specified threshold.
### Options ### Options
| Variable | Default | Description | | Variable | Default | Description |
| ----------- | ---------------------------- | ------------------------------------------------ | | ----------- | ---------------------------- | --------------------------------------- |
| `threshold` | `2` | Display threshold. | | `threshold` | `2` | Display threshold. |
| `format` | `"[$symbol$shlvl]($style) "` | The format for the module. | | `format` | `"[$symbol$shlvl]($style) "` | The format for the module. |
| `symbol` | `"↕️ "` | The symbol used to represent the SHLVL. | | `symbol` | `"↕️ "` | The symbol used to represent the SHLVL. |
| `style` | `"bold yellow"` | The style for the module. | | `style` | `"bold yellow"` | The style for the module. |
| `disabled` | `true` | Disables the `shlvl` module. | | `disabled` | `true` | Disables the `shlvl` module. |
### Variables ### Variables
| Variable | Example | Description | | Variable | Example | Description |
| -------- | --------- | ------------------------------------ | | -------- | ------- | ------------------------------------ |
| shlvl | `3` | The current value of SHLVL | | shlvl | `3` | The current value of SHLVL |
| symbol | | Mirrors the value of option `symbol` | | symbol | | Mirrors the value of option `symbol` |
| style\* | | Mirrors the value of option `style` | | style\* | | Mirrors the value of option `style` |
\*: This variable can only be used as a part of a style string \*: This variable can only be used as a part of a style string
@ -2194,13 +2193,13 @@ The module will be shown if any of the following conditions are met:
### Options ### Options
| Option | Default | Description | | Option | Default | Description |
| ------------- | ------------------------ | ------------------------------------- | | ------------- | ----------------------- | ------------------------------------- |
| `style_root` | `"bold red"` | The style used when the user is root. | | `style_root` | `"bold red"` | The style used when the user is root. |
| `style_user` | `"bold yellow"` | The style used for non-root users. | | `style_user` | `"bold yellow"` | The style used for non-root users. |
| `format` | `"via [$user]($style) "` | The format for the module. | | `format` | `"[$user]($style) in "` | The format for the module. |
| `show_always` | `false` | Always shows the `username` module. | | `show_always` | `false` | Always shows the `username` module. |
| `disabled` | `false` | Disables the `username` module. | | `disabled` | `false` | Disables the `username` module. |
### Variables ### Variables
@ -2276,8 +2275,8 @@ Multiple custom modules can be defined by using a `.`.
::: tip ::: tip
The order in which custom modules are shown can be individually set by including The order in which custom modules are shown can be individually set by including
`${custom.foo}` in the top level `format` (as it includes a dot, you need to use `${...}`). `${custom.foo}` in the top level `format` (as it includes a dot, you need to use `${...}`).
By default, the `custom` module will simply show all custom modules in the order they were defined. By default, the `custom` module will simply show all custom modules in the order they were defined.
::: :::

View File

@ -16,7 +16,7 @@ impl<'a> RootModuleConfig<'a> for HostnameConfig<'a> {
HostnameConfig { HostnameConfig {
ssh_only: true, ssh_only: true,
trim_at: ".", trim_at: ".",
format: "on [$hostname]($style) ", format: "[$hostname]($style) in ",
style: "green dimmed bold", style: "green dimmed bold",
disabled: false, disabled: false,
} }

View File

@ -16,7 +16,7 @@ impl<'a> RootModuleConfig<'a> for KubernetesConfig<'a> {
fn new() -> Self { fn new() -> Self {
KubernetesConfig { KubernetesConfig {
symbol: "", symbol: "",
format: "on [$symbol$context( \\($namespace\\))]($style) ", format: "[$symbol$context( \\($namespace\\))]($style) in ",
style: "cyan bold", style: "cyan bold",
disabled: true, disabled: true,
context_aliases: HashMap::new(), context_aliases: HashMap::new(),

View File

@ -14,7 +14,7 @@ pub struct UsernameConfig<'a> {
impl<'a> RootModuleConfig<'a> for UsernameConfig<'a> { impl<'a> RootModuleConfig<'a> for UsernameConfig<'a> {
fn new() -> Self { fn new() -> Self {
UsernameConfig { UsernameConfig {
format: "via [$user]($style) ", format: "[$user]($style) in ",
style_root: "red bold", style_root: "red bold",
style_user: "yellow bold", style_user: "yellow bold",
show_always: false, show_always: false,

View File

@ -6,7 +6,7 @@ use std::fmt;
// List of all modules // List of all modules
// Keep these ordered alphabetically. // Keep these ordered alphabetically.
// Default ordering is handled in configs/mod.rs // Default ordering is handled in configs/starship_root.rs
pub const ALL_MODULES: &[&str] = &[ pub const ALL_MODULES: &[&str] = &[
"aws", "aws",
#[cfg(feature = "battery")] #[cfg(feature = "battery")]

View File

@ -95,7 +95,7 @@ mod tests {
trim_at = "" trim_at = ""
}) })
.collect(); .collect();
let expected = Some(format!("on {} ", style().paint(hostname))); let expected = Some(format!("{} in ", style().paint(hostname)));
assert_eq!(expected, actual); assert_eq!(expected, actual);
Ok(()) Ok(())
@ -126,7 +126,7 @@ mod tests {
}) })
.env("SSH_CONNECTION", "something") .env("SSH_CONNECTION", "something")
.collect(); .collect();
let expected = Some(format!("on {} ", style().paint(hostname))); let expected = Some(format!("{} in ", style().paint(hostname)));
assert_eq!(expected, actual); assert_eq!(expected, actual);
Ok(()) Ok(())
@ -142,7 +142,7 @@ mod tests {
trim_at = "" trim_at = ""
}) })
.collect(); .collect();
let expected = Some(format!("on {} ", style().paint(hostname))); let expected = Some(format!("{} in ", style().paint(hostname)));
assert_eq!(expected, actual); assert_eq!(expected, actual);
Ok(()) Ok(())
@ -159,7 +159,7 @@ mod tests {
trim_at = trim_at trim_at = trim_at
}) })
.collect(); .collect();
let expected = Some(format!("on {} ", style().paint(remainder))); let expected = Some(format!("{} in ", style().paint(remainder)));
assert_eq!(expected, actual); assert_eq!(expected, actual);
Ok(()) Ok(())

View File

@ -59,7 +59,7 @@ use crate::module::Module;
pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> { pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
match module { match module {
// Keep these ordered alphabetically. // Keep these ordered alphabetically.
// Default ordering is handled in configs/mod.rs // Default ordering is handled in configs/starship_root.rs
"aws" => aws::module(context), "aws" => aws::module(context),
#[cfg(feature = "battery")] #[cfg(feature = "battery")]
"battery" => battery::module(context), "battery" => battery::module(context),

View File

@ -111,7 +111,7 @@ mod tests {
.env("LOGNAME", "astronaut") .env("LOGNAME", "astronaut")
.env("USER", "cosmonaut") .env("USER", "cosmonaut")
.collect(); .collect();
let expected = Some(format!("via {} ", Color::Yellow.bold().paint("cosmonaut"))); let expected = Some(format!("{} in ", Color::Yellow.bold().paint("cosmonaut")));
assert_eq!(expected, actual); assert_eq!(expected, actual);
Ok(()) Ok(())
@ -123,7 +123,7 @@ mod tests {
.env("USER", "astronaut") .env("USER", "astronaut")
.env("SSH_CONNECTION", "192.168.223.17 36673 192.168.223.229 22") .env("SSH_CONNECTION", "192.168.223.17 36673 192.168.223.229 22")
.collect(); .collect();
let expected = Some(format!("via {} ", Color::Yellow.bold().paint("astronaut"))); let expected = Some(format!("{} in ", Color::Yellow.bold().paint("astronaut")));
assert_eq!(expected, actual); assert_eq!(expected, actual);
Ok(()) Ok(())
@ -138,7 +138,7 @@ mod tests {
show_always = true show_always = true
}) })
.collect(); .collect();
let expected = Some(format!("via {} ", Color::Yellow.bold().paint("astronaut"))); let expected = Some(format!("{} in ", Color::Yellow.bold().paint("astronaut")));
assert_eq!(expected, actual); assert_eq!(expected, actual);
Ok(()) Ok(())