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` |
@ -934,7 +935,7 @@ 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. |
@ -1225,7 +1226,7 @@ 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. |
@ -1234,7 +1235,7 @@ The module will be shown if any of the following conditions are met:
### 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` |
@ -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. |
@ -1414,7 +1415,7 @@ 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. |
@ -1488,11 +1489,11 @@ 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` |
@ -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,7 +1774,7 @@ 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. |
@ -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.
@ -1986,7 +1985,7 @@ 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. |
@ -1996,7 +1995,7 @@ set to a number and meets or exceeds the specified threshold.
### 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` |
@ -2195,10 +2194,10 @@ 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. |

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(())