summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Song <4605384+chipbuster@users.noreply.github.com>2022-02-03 12:51:39 -0800
committerGitHub <noreply@github.com>2022-02-03 21:51:39 +0100
commit5efb78bcd3c5f28350b1af458a61bde53aaeb8a0 (patch)
tree20ddfc0bbfcecf6857056293d76f8b61c6546484
parent31289e0e20b9ed65344c65294852414ce60b514c (diff)
fix: Correctly detect older versions of powershell in bug-report (#3543)
* Factor out the shell version function * Correct command to trim spaces + header
-rw-r--r--src/bug_report.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/bug_report.rs b/src/bug_report.rs
index 4dcc7edf1..73be16100 100644
--- a/src/bug_report.rs
+++ b/src/bug_report.rs
@@ -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::*;