mirror of
https://github.com/Llewellynvdm/starship.git
synced 2025-01-07 07:54:57 +00:00
feat(shell): allow distinguishing between pwsh and powershell (#5478)
* Distinguish between pwsh and powershell Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
This commit is contained in:
parent
cb6df1d142
commit
d7a34b45f8
6
.github/config-schema.json
vendored
6
.github/config-schema.json
vendored
@ -5311,6 +5311,12 @@
|
|||||||
"default": "psh",
|
"default": "psh",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"pwsh_indicator": {
|
||||||
|
"type": [
|
||||||
|
"string",
|
||||||
|
"null"
|
||||||
|
]
|
||||||
|
},
|
||||||
"ion_indicator": {
|
"ion_indicator": {
|
||||||
"default": "ion",
|
"default": "ion",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
@ -3817,22 +3817,23 @@ To enable it, set `disabled` to `false` in your configuration file.
|
|||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| ---------------------- | ------------------------- | ------------------------------------------------------------ |
|
| ---------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------ |
|
||||||
| `bash_indicator` | `'bsh'` | A format string used to represent bash. |
|
| `bash_indicator` | `'bsh'` | A format string used to represent bash. |
|
||||||
| `fish_indicator` | `'fsh'` | A format string used to represent fish. |
|
| `fish_indicator` | `'fsh'` | A format string used to represent fish. |
|
||||||
| `zsh_indicator` | `'zsh'` | A format string used to represent zsh. |
|
| `zsh_indicator` | `'zsh'` | A format string used to represent zsh. |
|
||||||
| `powershell_indicator` | `'psh'` | A format string used to represent powershell. |
|
| `powershell_indicator` | `'psh'` | A format string used to represent powershell. |
|
||||||
| `ion_indicator` | `'ion'` | A format string used to represent ion. |
|
| `pwsh_indicator` | | A format string used to represent pwsh. The default value mirrors the value of `powershell_indicator`. |
|
||||||
| `elvish_indicator` | `'esh'` | A format string used to represent elvish. |
|
| `ion_indicator` | `'ion'` | A format string used to represent ion. |
|
||||||
| `tcsh_indicator` | `'tsh'` | A format string used to represent tcsh. |
|
| `elvish_indicator` | `'esh'` | A format string used to represent elvish. |
|
||||||
| `xonsh_indicator` | `'xsh'` | A format string used to represent xonsh. |
|
| `tcsh_indicator` | `'tsh'` | A format string used to represent tcsh. |
|
||||||
| `cmd_indicator` | `'cmd'` | A format string used to represent cmd. |
|
| `xonsh_indicator` | `'xsh'` | A format string used to represent xonsh. |
|
||||||
| `nu_indicator` | `'nu'` | A format string used to represent nu. |
|
| `cmd_indicator` | `'cmd'` | A format string used to represent cmd. |
|
||||||
| `unknown_indicator` | `''` | The default value to be displayed when the shell is unknown. |
|
| `nu_indicator` | `'nu'` | A format string used to represent nu. |
|
||||||
| `format` | `'[$indicator]($style) '` | The format for the module. |
|
| `unknown_indicator` | `''` | The default value to be displayed when the shell is unknown. |
|
||||||
| `style` | `'white bold'` | The style for the module. |
|
| `format` | `'[$indicator]($style) '` | The format for the module. |
|
||||||
| `disabled` | `true` | Disables the `shell` module. |
|
| `style` | `'white bold'` | The style for the module. |
|
||||||
|
| `disabled` | `true` | Disables the `shell` module. |
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@ pub struct ShellConfig<'a> {
|
|||||||
pub fish_indicator: &'a str,
|
pub fish_indicator: &'a str,
|
||||||
pub zsh_indicator: &'a str,
|
pub zsh_indicator: &'a str,
|
||||||
pub powershell_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 ion_indicator: &'a str,
|
||||||
pub elvish_indicator: &'a str,
|
pub elvish_indicator: &'a str,
|
||||||
pub tcsh_indicator: &'a str,
|
pub tcsh_indicator: &'a str,
|
||||||
@ -32,6 +34,7 @@ impl<'a> Default for ShellConfig<'a> {
|
|||||||
fish_indicator: "fsh",
|
fish_indicator: "fsh",
|
||||||
zsh_indicator: "zsh",
|
zsh_indicator: "zsh",
|
||||||
powershell_indicator: "psh",
|
powershell_indicator: "psh",
|
||||||
|
pwsh_indicator: None,
|
||||||
ion_indicator: "ion",
|
ion_indicator: "ion",
|
||||||
elvish_indicator: "esh",
|
elvish_indicator: "esh",
|
||||||
tcsh_indicator: "tsh",
|
tcsh_indicator: "tsh",
|
||||||
|
@ -372,7 +372,8 @@ impl<'a> Context<'a> {
|
|||||||
"bash" => Shell::Bash,
|
"bash" => Shell::Bash,
|
||||||
"fish" => Shell::Fish,
|
"fish" => Shell::Fish,
|
||||||
"ion" => Shell::Ion,
|
"ion" => Shell::Ion,
|
||||||
"powershell" | "pwsh" => Shell::PowerShell,
|
"pwsh" => Shell::Pwsh,
|
||||||
|
"powershell" => Shell::PowerShell,
|
||||||
"zsh" => Shell::Zsh,
|
"zsh" => Shell::Zsh,
|
||||||
"elvish" => Shell::Elvish,
|
"elvish" => Shell::Elvish,
|
||||||
"tcsh" => Shell::Tcsh,
|
"tcsh" => Shell::Tcsh,
|
||||||
@ -810,6 +811,7 @@ pub enum Shell {
|
|||||||
Bash,
|
Bash,
|
||||||
Fish,
|
Fish,
|
||||||
Ion,
|
Ion,
|
||||||
|
Pwsh,
|
||||||
PowerShell,
|
PowerShell,
|
||||||
Zsh,
|
Zsh,
|
||||||
Elvish,
|
Elvish,
|
||||||
|
@ -20,6 +20,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
Shell::Bash => Some(config.bash_indicator),
|
Shell::Bash => Some(config.bash_indicator),
|
||||||
Shell::Fish => Some(config.fish_indicator),
|
Shell::Fish => Some(config.fish_indicator),
|
||||||
Shell::Zsh => Some(config.zsh_indicator),
|
Shell::Zsh => Some(config.zsh_indicator),
|
||||||
|
Shell::Pwsh => config.pwsh_indicator.or(Some(config.powershell_indicator)),
|
||||||
Shell::PowerShell => Some(config.powershell_indicator),
|
Shell::PowerShell => Some(config.powershell_indicator),
|
||||||
Shell::Ion => Some(config.ion_indicator),
|
Shell::Ion => Some(config.ion_indicator),
|
||||||
Shell::Elvish => Some(config.elvish_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)),
|
"fish_indicator" => Some(Ok(config.fish_indicator)),
|
||||||
"zsh_indicator" => Some(Ok(config.zsh_indicator)),
|
"zsh_indicator" => Some(Ok(config.zsh_indicator)),
|
||||||
"powershell_indicator" => Some(Ok(config.powershell_indicator)),
|
"powershell_indicator" => Some(Ok(config.powershell_indicator)),
|
||||||
|
"pwsh_indicator" => config.pwsh_indicator.map(Ok),
|
||||||
"ion_indicator" => Some(Ok(config.ion_indicator)),
|
"ion_indicator" => Some(Ok(config.ion_indicator)),
|
||||||
"elvish_indicator" => Some(Ok(config.elvish_indicator)),
|
"elvish_indicator" => Some(Ok(config.elvish_indicator)),
|
||||||
"tcsh_indicator" => Some(Ok(config.tcsh_indicator)),
|
"tcsh_indicator" => Some(Ok(config.tcsh_indicator)),
|
||||||
@ -200,6 +202,50 @@ mod tests {
|
|||||||
assert_eq!(expected, actual);
|
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_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]
|
#[test]
|
||||||
fn test_ion_default_format() {
|
fn test_ion_default_format() {
|
||||||
let expected = Some(format!("{} ", Color::White.bold().paint("ion")));
|
let expected = Some(format!("{} ", Color::White.bold().paint("ion")));
|
||||||
|
Loading…
Reference in New Issue
Block a user