diff --git a/src-tauri/src/commands/misc.rs b/src-tauri/src/commands/misc.rs index fedbb71cb..8da885066 100644 --- a/src-tauri/src/commands/misc.rs +++ b/src-tauri/src/commands/misc.rs @@ -972,7 +972,7 @@ exec bash --norc --noprofile "warp" => launch_macos_warp(&script_file), "alacritty" => launch_macos_open_app("Alacritty", &script_file, true), "kitty" => launch_macos_open_app("kitty", &script_file, false), - "ghostty" => launch_macos_open_app("Ghostty", &script_file, true), + "ghostty" => launch_macos_ghostty(&script_file), "wezterm" => launch_macos_open_app("WezTerm", &script_file, true), "kaku" => launch_macos_open_app("Kaku", &script_file, true), _ => launch_macos_terminal_app(&script_file), // "terminal" or default @@ -1083,7 +1083,37 @@ fn launch_macos_iterm2(script_file: &std::path::Path) -> Result<(), String> { Ok(()) } -/// macOS: 使用 open -a 启动支持 --args 参数的终端(Alacritty/Kitty/Ghostty) +/// macOS: Ghostty — use --quit-after-last-window-closed to avoid cloning existing tabs +#[cfg(target_os = "macos")] +fn launch_macos_ghostty(script_file: &std::path::Path) -> Result<(), String> { + use std::process::Command; + + let output = Command::new("open") + .args([ + "-na", + "Ghostty", + "--args", + "--quit-after-last-window-closed=true", + "-e", + "bash", + ]) + .arg(script_file) + .output() + .map_err(|e| format!("启动 Ghostty 失败: {e}"))?; + + if !output.status.success() { + let stderr = String::from_utf8_lossy(&output.stderr); + return Err(format!( + "Ghostty 启动失败 (exit code: {:?}): {}", + output.status.code(), + stderr + )); + } + + Ok(()) +} + +/// macOS: 使用 open -na 启动支持 --args 参数的终端(Alacritty/Kitty/WezTerm/Kaku) #[cfg(target_os = "macos")] fn launch_macos_open_app( app_name: &str, @@ -1093,7 +1123,7 @@ fn launch_macos_open_app( use std::process::Command; let mut cmd = Command::new("open"); - cmd.arg("-a").arg(app_name).arg("--args"); + cmd.arg("-na").arg(app_name).arg("--args"); if use_e_flag { cmd.arg("-e"); @@ -1458,7 +1488,7 @@ read -n 1 -s "warp" => launch_macos_warp(&script_file), "alacritty" => launch_macos_open_app("Alacritty", &script_file, true), "kitty" => launch_macos_open_app("kitty", &script_file, false), - "ghostty" => launch_macos_open_app("Ghostty", &script_file, true), + "ghostty" => launch_macos_ghostty(&script_file), "wezterm" => launch_macos_open_app("WezTerm", &script_file, true), "kaku" => launch_macos_open_app("Kaku", &script_file, true), _ => launch_macos_terminal_app(&script_file),