From eb8dfd32b3f252cc03b271dde92251376b8e3fcc Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 20 Dec 2022 08:30:07 -0700 Subject: [PATCH] macos: use interactive shell for .command scripts This is primarily so that the user's environment is set up prior to invoking the script. refs: #2871 --- Cargo.lock | 1 + wezterm-gui/Cargo.toml | 1 + wezterm-gui/src/frontend.rs | 17 +++++++++-------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 896fc6093..df7fe4644 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5932,6 +5932,7 @@ dependencies = [ "serde_json", "serial", "shared_library", + "shlex", "smol", "tabout", "terminfo", diff --git a/wezterm-gui/Cargo.toml b/wezterm-gui/Cargo.toml index da164ae9d..fddae39c7 100644 --- a/wezterm-gui/Cargo.toml +++ b/wezterm-gui/Cargo.toml @@ -77,6 +77,7 @@ regex = "1" serde = {version="1.0", features = ["rc", "derive"]} serde_json = "1.0" serial = "0.4" +shlex = "1.1" smol = "1.2" tabout = { path = "../tabout" } terminfo = "0.7" diff --git a/wezterm-gui/src/frontend.rs b/wezterm-gui/src/frontend.rs index 8b6e27f28..d948829db 100644 --- a/wezterm-gui/src/frontend.rs +++ b/wezterm-gui/src/frontend.rs @@ -162,19 +162,18 @@ impl GuiFrontEnd { ApplicationEvent::OpenCommandScript(file_name) => { promise::spawn::spawn(async move { use config::keyassignment::SpawnTabDomain; - use portable_pty::CommandBuilder; use wezterm_term::TerminalSize; - let cmd = CommandBuilder::from_argv( - ["/bin/sh", "-c", &file_name] - .iter() - .map(Into::into) - .collect(), - ); + // We send the script to execute to the shell on stdin, rather than ask the + // shell to execute it directly, so that we start the shell and read in the + // user's rc files before running the script. Without this, wezterm on macOS + // is launched with a default and very anemic path, and that is frustrating for + // users. let mux = Mux::get(); let window_id = None; let pane_id = None; + let cmd = None; let cwd = None; let workspace = mux.active_workspace(); @@ -182,7 +181,7 @@ impl GuiFrontEnd { .spawn_tab_or_window( window_id, SpawnTabDomain::DomainName("local".to_string()), - Some(cmd), + cmd, cwd, TerminalSize::default(), pane_id, @@ -192,6 +191,8 @@ impl GuiFrontEnd { { Ok((_tab, pane, _window_id)) => { log::trace!("Spawned {file_name} as pane_id {}", pane.pane_id()); + let mut writer = pane.writer(); + write!(writer, "{} ; exit\n", shlex::quote(&file_name)).ok(); } Err(err) => { log::error!("Failed to spawn {file_name}: {err:#?}");