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>
- Update the config-schema
- Apply suggestions from code review
- Revert string formatter tests
- Rename to use pwsh
- Fix config-schema after rename.
- Fix tests after rename
  • Loading branch information
HeyItsGilbert committed Oct 13, 2023
1 parent 81c7d0c commit b0a4027
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .github/config-schema.json
Expand Up @@ -5286,6 +5286,12 @@
"default": "psh",
"type": "string"
},
"pwsh_indicator": {
"type": [
"string",
"null"
]
},
"ion_indicator": {
"default": "ion",
"type": "string"
Expand Down
1 change: 1 addition & 0 deletions docs/config/README.md
Expand Up @@ -3814,6 +3814,7 @@ To enable it, set `disabled` to `false` in your configuration file.
| `fish_indicator` | `'fsh'` | A format string used to represent fish. |
| `zsh_indicator` | `'zsh'` | A format string used to represent zsh. |
| `powershell_indicator` | `'psh'` | A format string used to represent powershell. |
| `pwsh_indicator` | `'psh'` | A format string used to represent pwsh. |
| `ion_indicator` | `'ion'` | A format string used to represent ion. |
| `elvish_indicator` | `'esh'` | A format string used to represent elvish. |
| `tcsh_indicator` | `'tsh'` | A format string used to represent tcsh. |
Expand Down
3 changes: 3 additions & 0 deletions src/configs/shell.rs
Expand Up @@ -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,
Expand All @@ -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",
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::Pwsh,
"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,
Pwsh,
PowerShell,
Zsh,
Elvish,
Expand Down
31 changes: 31 additions & 0 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::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),
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)),
"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)),
Expand Down Expand Up @@ -200,6 +202,35 @@ mod tests {
assert_eq!(expected, actual);
}

#[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_ion_default_format() {
let expected = Some(format!("{} ", Color::White.bold().paint("ion")));
Expand Down

0 comments on commit b0a4027

Please sign in to comment.