diff options
author | Andy Freeland <andy@andyfreeland.net> | 2021-03-23 14:20:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-23 17:20:29 -0400 |
commit | 3513aae3ed1c58670de110eaf71e6f21c330416c (patch) | |
tree | 1e88117a26fe141b6c0cd4787d1d5b0535d16bf4 /src | |
parent | 0a091bd236421cc36a8aba015915c28cdb4d0323 (diff) |
fix(shell): Support conditional format strings for `$indicator` (#2489)
Previously attempting to use conditional format strings with
`$indicator` would never display an indicator, e.g.:
```toml
[shell]
fish_indicator = ""
bash_indicator = "B "
format = "($indicator )"
disabled = false
```
This would always display an empty string.
Fixes #2474.
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/shell.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/modules/shell.rs b/src/modules/shell.rs index fc51b52f7..c8b6a2c92 100644 --- a/src/modules/shell.rs +++ b/src/modules/shell.rs @@ -28,6 +28,16 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { }, _ => None, }) + .map(|var| match var { + "bash_indicator" => Some(Ok(config.bash_indicator)), + "fish_indicator" => Some(Ok(config.fish_indicator)), + "zsh_indicator" => Some(Ok(config.zsh_indicator)), + "powershell_indicator" => Some(Ok(config.powershell_indicator)), + "ion_indicator" => Some(Ok(config.ion_indicator)), + "elvish_indicator" => Some(Ok(config.elvish_indicator)), + "tcsh_indicator" => Some(Ok(config.tcsh_indicator)), + _ => None, + }) .parse(None) }); @@ -237,4 +247,36 @@ mod tests { assert_eq!(expected, actual); } + + #[test] + fn test_custom_format_conditional_indicator_match() { + let expected = Some(format!("{} ", "B")); + let actual = ModuleRenderer::new("shell") + .shell(Shell::Bash) + .config(toml::toml! { + [shell] + bash_indicator = "B" + format = "($bash_indicator )" + disabled = false + }) + .collect(); + + assert_eq!(expected, actual); + } + + #[test] + fn test_custom_format_conditional_indicator_no_match() { + let expected = None; + let actual = ModuleRenderer::new("shell") + .shell(Shell::Fish) + .config(toml::toml! { + [shell] + bash_indicator = "B" + format = "($indicator )" + disabled = false + }) + .collect(); + + assert_eq!(expected, actual); + } } |