1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-28 15:56:28 +00:00

fix: Correctly detect older versions of powershell in bug-report (#3543)

* Factor out the shell version function

* Correct command to trim spaces + header
This commit is contained in:
Kevin Song 2022-02-03 12:51:39 -08:00 committed by GitHub
parent 31289e0e20
commit 5efb78bcd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -142,10 +142,7 @@ fn get_shell_info() -> ShellInfo {
let shell = shell.unwrap(); let shell = shell.unwrap();
let version = exec_cmd(&shell, &["--version"], Duration::from_millis(500)).map_or_else( let version = get_shell_version(&shell);
|| UNKNOWN_VERSION.to_string(),
|output| output.stdout.trim().to_string(),
);
let config = get_config_path(&shell) let config = get_config_path(&shell)
.and_then(|config_path| fs::read_to_string(config_path).ok()) .and_then(|config_path| fs::read_to_string(config_path).ok())
@ -225,6 +222,22 @@ fn get_starship_config() -> String {
.unwrap_or_else(|| UNKNOWN_CONFIG.to_string()) .unwrap_or_else(|| UNKNOWN_CONFIG.to_string())
} }
fn get_shell_version(shell: &str) -> String {
let time_limit = Duration::from_millis(500);
match shell {
"powershell" => exec_cmd(
&shell,
&["(Get-Host | Select Version | Format-Table -HideTableHeaders | Out-String).trim()"],
time_limit,
),
_ => exec_cmd(&shell, &["--version"], time_limit),
}
.map_or_else(
|| UNKNOWN_VERSION.to_string(),
|output| output.stdout.trim().to_string(),
)
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;