From 4536b95ac955781d4d158b3c350a3d6448489099 Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 25 Apr 2026 17:00:36 +0800 Subject: [PATCH] refactor: prefer default shell in commands::try_get_version (#2286) Signed-off-by: tison --- src-tauri/src/commands/misc.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/commands/misc.rs b/src-tauri/src/commands/misc.rs index 1c7f99912..8818ac26b 100644 --- a/src-tauri/src/commands/misc.rs +++ b/src-tauri/src/commands/misc.rs @@ -300,8 +300,13 @@ fn try_get_version(tool: &str) -> (Option, Option) { #[cfg(not(target_os = "windows"))] let output = { - Command::new("sh") - .arg("-c") + let shell = std::env::var("SHELL") + .ok() + .filter(|s| is_valid_shell(s)) + .unwrap_or_else(|| "sh".to_string()); + let flag = default_flag_for_shell(&shell); + Command::new(shell) + .arg(flag) .arg(format!("{tool} --version")) .output() }; @@ -345,7 +350,6 @@ fn is_valid_wsl_distro_name(name: &str) -> bool { } /// Validate that the given shell name is one of the allowed shells. -#[cfg(target_os = "windows")] fn is_valid_shell(shell: &str) -> bool { matches!( shell.rsplit('/').next().unwrap_or(shell), @@ -360,7 +364,6 @@ fn is_valid_shell_flag(flag: &str) -> bool { } /// Return the default invocation flag for the given shell. -#[cfg(target_os = "windows")] fn default_flag_for_shell(shell: &str) -> &'static str { match shell.rsplit('/').next().unwrap_or(shell) { "dash" | "sh" => "-c",