diff --git a/config/src/config.rs b/config/src/config.rs index f40dafa68..c31d9cf87 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -1538,18 +1538,29 @@ impl Config { } }; - self.apply_cmd_defaults(&mut cmd, default_cwd); + self.apply_cmd_defaults(&mut cmd, None, default_cwd); Ok(cmd) } - pub fn apply_cmd_defaults(&self, cmd: &mut CommandBuilder, default_cwd: Option<&PathBuf>) { + pub fn apply_cmd_defaults( + &self, + cmd: &mut CommandBuilder, + default_prog: Option<&Vec>, + default_cwd: Option<&PathBuf>, + ) { // Apply `default_cwd` only if `cwd` is not already set, allows `--cwd` // option to take precedence if let (None, Some(cwd)) = (cmd.get_cwd(), default_cwd) { cmd.cwd(cwd); } + if let Some(default_prog) = default_prog { + if cmd.is_default_prog() { + cmd.replace_default_prog(default_prog); + } + } + // Augment WSLENV so that TERM related environment propagates // across the win32/wsl boundary let mut wsl_env = std::env::var("WSLENV").ok(); diff --git a/mux/src/domain.rs b/mux/src/domain.rs index a10fa216e..c0a59048c 100644 --- a/mux/src/domain.rs +++ b/mux/src/domain.rs @@ -453,23 +453,25 @@ impl LocalDomain { pane_id: PaneId, ) -> anyhow::Result { let config = configuration(); + + let wsl = self.resolve_wsl_domain(); + let default_prog = wsl + .as_ref() + .map(|wsl| wsl.default_prog.as_ref()) + .unwrap_or(config.default_prog.as_ref()); + let mut cmd = match command { Some(mut cmd) => { - config.apply_cmd_defaults(&mut cmd, config.default_cwd.as_ref()); + config.apply_cmd_defaults(&mut cmd, default_prog, config.default_cwd.as_ref()); cmd } - None => { - let wsl = self.resolve_wsl_domain(); - config.build_prog( - None, - wsl.as_ref() - .map(|wsl| wsl.default_prog.as_ref()) - .unwrap_or(config.default_prog.as_ref()), - wsl.as_ref() - .map(|wsl| wsl.default_cwd.as_ref()) - .unwrap_or(config.default_cwd.as_ref()), - )? - } + None => config.build_prog( + None, + default_prog, + wsl.as_ref() + .map(|wsl| wsl.default_cwd.as_ref()) + .unwrap_or(config.default_cwd.as_ref()), + )?, }; if let Some(dir) = command_dir { cmd.cwd(dir); diff --git a/mux/src/ssh.rs b/mux/src/ssh.rs index 157d887ec..80bf13e58 100644 --- a/mux/src/ssh.rs +++ b/mux/src/ssh.rs @@ -253,7 +253,7 @@ impl RemoteSshDomain { let config = config::configuration(); let cmd = match command { Some(mut cmd) => { - config.apply_cmd_defaults(&mut cmd, None); + config.apply_cmd_defaults(&mut cmd, self.dom.default_prog.as_ref(), None); cmd } None => config.build_prog(None, self.dom.default_prog.as_ref(), None)?, diff --git a/pty/src/cmdbuilder.rs b/pty/src/cmdbuilder.rs index 0a270eae3..675d88cdb 100644 --- a/pty/src/cmdbuilder.rs +++ b/pty/src/cmdbuilder.rs @@ -276,6 +276,22 @@ impl CommandBuilder { self.args.push(arg.as_ref().to_owned()); } + /// If a builder is_default_prog, then this function can be used to + /// set the actual prog that should be used. + /// This is intended to facilitate plumbing through the handling + /// of the underlying default prog when merging together supplemental + /// env and cwd information. + /// You will not typically use this method in your own code. + pub fn replace_default_prog(&mut self, args: impl IntoIterator>) { + if !self.is_default_prog() { + panic!("attempted to replace_default_prog on a non-default_prog builder"); + } + + for arg in args { + self.args.push(arg.as_ref().to_owned()); + } + } + /// Append a sequence of arguments to the current command line pub fn args(&mut self, args: I) where