mirror of
https://github.com/starship/starship.git
synced 2024-12-26 00:58:52 +01: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:
parent
31289e0e20
commit
5efb78bcd3
@ -142,10 +142,7 @@ fn get_shell_info() -> ShellInfo {
|
||||
|
||||
let shell = shell.unwrap();
|
||||
|
||||
let version = exec_cmd(&shell, &["--version"], Duration::from_millis(500)).map_or_else(
|
||||
|| UNKNOWN_VERSION.to_string(),
|
||||
|output| output.stdout.trim().to_string(),
|
||||
);
|
||||
let version = get_shell_version(&shell);
|
||||
|
||||
let config = get_config_path(&shell)
|
||||
.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())
|
||||
}
|
||||
|
||||
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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
Loading…
Reference in New Issue
Block a user