diff --git a/config/src/lib.rs b/config/src/lib.rs index 7088bb3ed..038ff95fc 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -148,6 +148,12 @@ pub fn designate_this_as_the_main_thread() { }); } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ProgDomain { + Local, + Remote, +} + #[must_use = "Cancels the subscription when dropped"] pub struct ConfigSubscription(usize); @@ -1808,15 +1814,19 @@ impl Config { } } - pub fn build_prog(&self, prog: Option>) -> Result { - let mut cmd = match prog { - Some(args) => { + pub fn build_prog( + &self, + prog: Option>, + prog_domain: ProgDomain, + ) -> Result { + let mut cmd = match (prog, prog_domain) { + (Some(args), _) => { let mut args = args.iter(); let mut cmd = CommandBuilder::new(args.next().expect("executable name")); cmd.args(args); cmd } - None => { + (None, ProgDomain::Local) => { if let Some(prog) = self.default_prog.as_ref() { let mut args = prog.iter(); let mut cmd = CommandBuilder::new(args.next().expect("executable name")); @@ -1826,18 +1836,21 @@ impl Config { CommandBuilder::new_default_prog() } } + (None, ProgDomain::Remote) => CommandBuilder::new_default_prog(), }; - self.apply_cmd_defaults(&mut cmd); + self.apply_cmd_defaults(&mut cmd, prog_domain); Ok(cmd) } - pub fn apply_cmd_defaults(&self, cmd: &mut CommandBuilder) { + pub fn apply_cmd_defaults(&self, cmd: &mut CommandBuilder, prog_domain: ProgDomain) { // Apply `default_cwd` only if `cwd` is not already set, allows `--cwd` // option to take precedence - if let (None, Some(cwd)) = (cmd.get_cwd(), &self.default_cwd) { - cmd.cwd(cwd); + if prog_domain == ProgDomain::Local { + if let (None, Some(cwd)) = (cmd.get_cwd(), &self.default_cwd) { + cmd.cwd(cwd); + } } // Augment WSLENV so that TERM related environment propagates diff --git a/docs/changelog.md b/docs/changelog.md index 4cdc923bd..6adfd1437 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -58,6 +58,7 @@ As features stabilize some brief notes about them will accumulate here. * Closing a window will no longer recursively terminate contained multiplexer client panes; the window will instead be restored when you next connect to that multiplexer server. Killing/closing individual tabs/panes *will* kill the panes; this change only affects closing the window. [#848](https://github.com/wez/wezterm/issues/848) [#917](https://github.com/wez/wezterm/issues/917) [#1224](https://github.com/wez/wezterm/issues/1224) * Colors were too intense due to over gamma correction [#1025](https://github.com/wez/wezterm/issues/1025) * Mesa and EGL colors were too dim due to under gamma correction [#1373](https://github.com/wez/wezterm/issues/1373) +* `wezterm ssh` no longer tries to use `default_prog` or `default_cwd` when spawning additional panes on the remote host [#1456](https://github.com/wez/wezterm/issues/1456) ### 20211205-192649-672c1cc1 diff --git a/mux/src/domain.rs b/mux/src/domain.rs index e926d59a6..b1442d3a3 100644 --- a/mux/src/domain.rs +++ b/mux/src/domain.rs @@ -12,7 +12,7 @@ use crate::window::WindowId; use crate::Mux; use anyhow::{bail, Error}; use async_trait::async_trait; -use config::configuration; +use config::{configuration, ProgDomain}; use downcast_rs::{impl_downcast, Downcast}; use portable_pty::{native_pty_system, CommandBuilder, PtySize, PtySystem}; use std::rc::Rc; @@ -120,10 +120,10 @@ impl Domain for LocalDomain { let config = configuration(); let mut cmd = match command { Some(mut cmd) => { - config.apply_cmd_defaults(&mut cmd); + config.apply_cmd_defaults(&mut cmd, ProgDomain::Local); cmd } - None => config.build_prog(None)?, + None => config.build_prog(None, ProgDomain::Local)?, }; if let Some(dir) = command_dir { // I'm not normally a fan of existence checking, but not checking here @@ -200,10 +200,10 @@ impl Domain for LocalDomain { let config = configuration(); let mut cmd = match command { Some(mut cmd) => { - config.apply_cmd_defaults(&mut cmd); + config.apply_cmd_defaults(&mut cmd, ProgDomain::Local); cmd } - None => config.build_prog(None)?, + None => config.build_prog(None, ProgDomain::Local)?, }; if let Some(dir) = command_dir { // I'm not normally a fan of existence checking, but not checking here diff --git a/mux/src/ssh.rs b/mux/src/ssh.rs index 68d7a5ec3..3c372d9eb 100644 --- a/mux/src/ssh.rs +++ b/mux/src/ssh.rs @@ -7,6 +7,7 @@ use crate::window::WindowId; use crate::Mux; use anyhow::{anyhow, bail, Context, Error}; use async_trait::async_trait; +use config::ProgDomain; use filedescriptor::{poll, pollfd, socketpair, AsRawSocketDescriptor, FileDescriptor, POLLIN}; use portable_pty::cmdbuilder::CommandBuilder; use portable_pty::{ChildKiller, ExitStatus, MasterPty, PtySize}; @@ -609,10 +610,10 @@ impl Domain for RemoteSshDomain { let config = config::configuration(); let cmd = match command { Some(mut cmd) => { - config.apply_cmd_defaults(&mut cmd); + config.apply_cmd_defaults(&mut cmd, ProgDomain::Remote); cmd } - None => config.build_prog(None)?, + None => config.build_prog(None, ProgDomain::Remote)?, }; let pane_id = alloc_pane_id(); diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index ad208422d..387da3d72 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -4,7 +4,7 @@ use crate::frontend::front_end; use ::window::*; use anyhow::{anyhow, Context}; -use config::{ConfigHandle, SshBackend}; +use config::{ConfigHandle, ProgDomain, SshBackend}; use mux::activity::Activity; use mux::domain::{Domain, LocalDomain}; use mux::Mux; @@ -362,7 +362,10 @@ fn run_terminal_gui(opts: StartCommand) -> anyhow::Result<()> { let cmd = if need_builder { let config = config::configuration(); let prog = opts.prog.iter().map(|s| s.as_os_str()).collect::>(); - let mut builder = config.build_prog(if prog.is_empty() { None } else { Some(prog) })?; + let mut builder = config.build_prog( + if prog.is_empty() { None } else { Some(prog) }, + ProgDomain::Local, + )?; if let Some(cwd) = opts.cwd { builder.cwd(cwd); }