Skip to content

Commit

Permalink
fix: Correctly detect older versions of powershell in bug-report (sta…
Browse files Browse the repository at this point in the history
…rship#3543)

* Factor out the shell version function

* Correct command to trim spaces + header
  • Loading branch information
chipbuster authored and Perniciosius committed Feb 21, 2022
1 parent 8f219a2 commit 5840984
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/bug_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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::*;
Expand Down

0 comments on commit 5840984

Please sign in to comment.