Skip to content

Commit

Permalink
Distinguish between pwsh and powershell
Browse files Browse the repository at this point in the history
Signed-off-by: Gilbert Sanchez <me@gilbertsanchez.com>
  • Loading branch information
HeyItsGilbert committed Oct 3, 2023
1 parent 7e82cb4 commit 6e155de
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/configs/shell.rs
Expand Up @@ -13,6 +13,7 @@ pub struct ShellConfig<'a> {
pub fish_indicator: &'a str,
pub zsh_indicator: &'a str,
pub powershell_indicator: &'a str,
pub powershellcore_indicator: &'a str,
pub ion_indicator: &'a str,
pub elvish_indicator: &'a str,
pub tcsh_indicator: &'a str,
Expand All @@ -32,6 +33,7 @@ impl<'a> Default for ShellConfig<'a> {
fish_indicator: "fsh",
zsh_indicator: "zsh",
powershell_indicator: "psh",
powershellcore_indicator: "pwsh",
ion_indicator: "ion",
elvish_indicator: "esh",
tcsh_indicator: "tsh",
Expand Down
4 changes: 3 additions & 1 deletion src/context.rs
Expand Up @@ -368,7 +368,8 @@ impl<'a> Context<'a> {
"bash" => Shell::Bash,
"fish" => Shell::Fish,
"ion" => Shell::Ion,
"powershell" | "pwsh" => Shell::PowerShell,
"pwsh" => Shell::PowerShellCore,
"powershell" => Shell::PowerShell,
"zsh" => Shell::Zsh,
"elvish" => Shell::Elvish,
"tcsh" => Shell::Tcsh,
Expand Down Expand Up @@ -794,6 +795,7 @@ pub enum Shell {
Bash,
Fish,
Ion,
PowerShellCore,
PowerShell,
Zsh,
Elvish,
Expand Down
8 changes: 4 additions & 4 deletions src/formatter/string_formatter.rs
Expand Up @@ -823,7 +823,7 @@ mod tests {
r"\$(echo a)"
);
assert_eq!(
shell_prompt_escape(test.to_owned(), Shell::PowerShell),
shell_prompt_escape(test.to_owned(), Shell::PowerShellCore),
test
);

Expand All @@ -833,7 +833,7 @@ mod tests {
r"\\\$(echo a)"
);
assert_eq!(
shell_prompt_escape(test.to_owned(), Shell::PowerShell),
shell_prompt_escape(test.to_owned(), Shell::PowerShellCore),
test
);

Expand All @@ -843,7 +843,7 @@ mod tests {
r"\`echo a\`"
);
assert_eq!(
shell_prompt_escape(test.to_owned(), Shell::PowerShell),
shell_prompt_escape(test.to_owned(), Shell::PowerShellCore),
test
);
}
Expand All @@ -852,7 +852,7 @@ mod tests {
let test = "10%";
assert_eq!(shell_prompt_escape(test.to_owned(), Shell::Zsh), "10%%");
assert_eq!(
shell_prompt_escape(test.to_owned(), Shell::PowerShell),
shell_prompt_escape(test.to_owned(), Shell::PowerShellCore),
test
);
}
Expand Down
35 changes: 33 additions & 2 deletions src/modules/shell.rs
Expand Up @@ -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::PowerShellCore => Some(config.powershellcore_indicator),
Shell::PowerShell => Some(config.powershell_indicator),
Shell::Ion => Some(config.ion_indicator),
Shell::Elvish => Some(config.elvish_indicator),
Expand All @@ -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)),
"powershellcore_indicator" => Some(Ok(config.powershellcore_indicator)),

Check warning on line 44 in src/modules/shell.rs

View check run for this annotation

Codecov / codecov/patch

src/modules/shell.rs#L44

Added line #L44 was not covered by tests
"ion_indicator" => Some(Ok(config.ion_indicator)),
"elvish_indicator" => Some(Ok(config.elvish_indicator)),
"tcsh_indicator" => Some(Ok(config.tcsh_indicator)),
Expand Down Expand Up @@ -172,7 +174,36 @@ mod tests {
}

#[test]
fn test_powershell_default_format() {
fn test_powershellcore_default_format() {
let expected = Some(format!("{} ", Color::White.bold().paint("pwsh")));
let actual = ModuleRenderer::new("shell")
.shell(Shell::PowerShellCore)
.config(toml::toml! {
[shell]
disabled = false
})
.collect();

assert_eq!(expected, actual);
}

#[test]
fn test_powershellcore_custom_format() {
let expected = Some(format!("{} ", Color::Cyan.bold().paint("pwsh")));
let actual = ModuleRenderer::new("shell")
.shell(Shell::PowerShellCore)
.config(toml::toml! {
[shell]
powershellcore_indicator = "[pwsh](bold cyan)"
disabled = false
})
.collect();

assert_eq!(expected, actual);
}

#[test]
fn test_windowspowershell_default_format() {
let expected = Some(format!("{} ", Color::White.bold().paint("psh")));
let actual = ModuleRenderer::new("shell")
.shell(Shell::PowerShell)
Expand All @@ -186,7 +217,7 @@ mod tests {
}

#[test]
fn test_powershell_custom_format() {
fn test_windowspowershell_custom_format() {
let expected = Some(format!("{} ", Color::Cyan.bold().paint("powershell")));
let actual = ModuleRenderer::new("shell")
.shell(Shell::PowerShell)
Expand Down

0 comments on commit 6e155de

Please sign in to comment.