diff options
author | Gilbert Sanchez <me@gilbertsanchez.com> | 2023-11-25 05:06:03 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-25 14:06:03 +0100 |
commit | d7a34b45f88ced63bd79a582c14a6b2f8ebd9544 (patch) | |
tree | 78edadcfad4c9871b7388de83f34c789534fac26 /src | |
parent | cb6df1d142a4ef345afd1867db9f465b4c11a97a (diff) |
feat(shell): allow distinguishing between pwsh and powershell (#5478)
* Distinguish between pwsh and powershell
Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/configs/shell.rs | 3 | ||||
-rw-r--r-- | src/context.rs | 4 | ||||
-rw-r--r-- | src/modules/shell.rs | 46 |
3 files changed, 52 insertions, 1 deletions
diff --git a/src/configs/shell.rs b/src/configs/shell.rs index 540ea8e32..9d0bd3aa0 100644 --- a/src/configs/shell.rs +++ b/src/configs/shell.rs @@ -13,6 +13,8 @@ pub struct ShellConfig<'a> { pub fish_indicator: &'a str, pub zsh_indicator: &'a str, pub powershell_indicator: &'a str, + #[serde(skip_serializing_if = "Option::is_none")] + pub pwsh_indicator: Option<&'a str>, pub ion_indicator: &'a str, pub elvish_indicator: &'a str, pub tcsh_indicator: &'a str, @@ -32,6 +34,7 @@ impl<'a> Default for ShellConfig<'a> { fish_indicator: "fsh", zsh_indicator: "zsh", powershell_indicator: "psh", + pwsh_indicator: None, ion_indicator: "ion", elvish_indicator: "esh", tcsh_indicator: "tsh", diff --git a/src/context.rs b/src/context.rs index 83af209a0..0a498c999 100644 --- a/src/context.rs +++ b/src/context.rs @@ -372,7 +372,8 @@ impl<'a> Context<'a> { "bash" => Shell::Bash, "fish" => Shell::Fish, "ion" => Shell::Ion, - "powershell" | "pwsh" => Shell::PowerShell, + "pwsh" => Shell::Pwsh, + "powershell" => Shell::PowerShell, "zsh" => Shell::Zsh, "elvish" => Shell::Elvish, "tcsh" => Shell::Tcsh, @@ -810,6 +811,7 @@ pub enum Shell { Bash, Fish, Ion, + Pwsh, PowerShell, Zsh, Elvish, diff --git a/src/modules/shell.rs b/src/modules/shell.rs index c9b6df157..98502a266 100644 --- a/src/modules/shell.rs +++ b/src/modules/shell.rs @@ -20,6 +20,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { Shell::Bash => Some(config.bash_indicator), Shell::Fish => Some(config.fish_indicator), Shell::Zsh => Some(config.zsh_indicator), + Shell::Pwsh => config.pwsh_indicator.or(Some(config.powershell_indicator)), Shell::PowerShell => Some(config.powershell_indicator), Shell::Ion => Some(config.ion_indicator), Shell::Elvish => Some(config.elvish_indicator), @@ -40,6 +41,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { "fish_indicator" => Some(Ok(config.fish_indicator)), "zsh_indicator" => Some(Ok(config.zsh_indicator)), "powershell_indicator" => Some(Ok(config.powershell_indicator)), + "pwsh_indicator" => config.pwsh_indicator.map(Ok), "ion_indicator" => Some(Ok(config.ion_indicator)), "elvish_indicator" => Some(Ok(config.elvish_indicator)), "tcsh_indicator" => Some(Ok(config.tcsh_indicator)), @@ -201,6 +203,50 @@ mod tests { } #[test] + fn test_pwsh_default_format() { + let expected = Some(format!("{} ", Color::White.bold().paint("psh"))); + let actual = ModuleRenderer::new("shell") + .shell(Shell::Pwsh) + .config(toml::toml! { + [shell] + disabled = false + }) + .collect(); + + assert_eq!(expected, actual); + } + + #[test] + fn test_pwsh_custom_format() { + let expected = Some(format!("{} ", Color::Cyan.bold().paint("pwsh"))); + let actual = ModuleRenderer::new("shell") + .shell(Shell::Pwsh) + .config(toml::toml! { + [shell] + pwsh_indicator = "[pwsh](bold cyan)" + disabled = false + }) + .collect(); + + assert_eq!(expected, actual); + } + + #[test] + fn test_pwsh_custom_format_fallback() { + let expected = Some(format!("{} ", Color::Cyan.bold().paint("pwsh"))); + let actual = ModuleRenderer::new("shell") + .shell(Shell::Pwsh) + .config(toml::toml! { + [shell] + powershell_indicator = "[pwsh](bold cyan)" + disabled = false + }) + .collect(); + + assert_eq!(expected, actual); + } + + #[test] fn test_ion_default_format() { let expected = Some(format!("{} ", Color::White.bold().paint("ion"))); let actual = ModuleRenderer::new("shell") |