From b3987bec12acc35ff915a2f47079f1d81ddced12 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 9 Jan 2022 20:09:53 -0700 Subject: [PATCH] ssh: allow setting default_prog for SshDomain when multiplexing=None ``` return { ssh_domains = { { name = "woot", remote_address = "192.168.1.8", multiplexing = "None", default_prog = {"fish"}, } }, default_domain = "woot", } ``` refs: https://github.com/wez/wezterm/issues/1456 --- config/src/ssh.rs | 2 ++ docs/config/lua/SshDomain.md | 8 +++++ mux/src/ssh.rs | 61 ++++++++++++++++-------------------- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/config/src/ssh.rs b/config/src/ssh.rs index c53c638ab..a3d41f9d5 100644 --- a/config/src/ssh.rs +++ b/config/src/ssh.rs @@ -67,6 +67,8 @@ pub struct SshDomain { /// ssh_config option values #[serde(default)] pub ssh_option: HashMap, + + pub default_prog: Option>, } impl_lua_conversion!(SshDomain); diff --git a/docs/config/lua/SshDomain.md b/docs/config/lua/SshDomain.md index 173bb6b05..0469299dd 100644 --- a/docs/config/lua/SshDomain.md +++ b/docs/config/lua/SshDomain.md @@ -74,9 +74,17 @@ return { name = "my.server", remote_address = "192.168.1.1", multiplexing = "None", + + -- When multiplexing == "None", default_prog can be used + -- to specify the default program to run in new tabs/panes. + -- Due to the way that ssh works, you cannot specify default_cwd, + -- but you could instead change your default_prog to put you + -- in a specific directory. + default_prog = {"fish"}, } }, default_domain = "my.server", } ``` + diff --git a/mux/src/ssh.rs b/mux/src/ssh.rs index 45c9dd546..39706fc08 100644 --- a/mux/src/ssh.rs +++ b/mux/src/ssh.rs @@ -196,6 +196,31 @@ impl RemoteSshDomain { pub fn ssh_config(&self) -> anyhow::Result { ssh_domain_to_ssh_config(&self.dom) } + + fn build_command( + &self, + pane_id: PaneId, + command: Option, + ) -> anyhow::Result<(Option, HashMap)> { + let config = config::configuration(); + let cmd = match command { + Some(mut cmd) => { + config.apply_cmd_defaults(&mut cmd, None); + cmd + } + None => config.build_prog(None, self.dom.default_prog.as_ref(), None)?, + }; + let mut env: HashMap = cmd + .iter_extra_env_as_str() + .map(|(k, v)| (k.to_string(), v.to_string())) + .collect(); + env.insert("WEZTERM_PANE".to_string(), pane_id.to_string()); + if cmd.is_default_prog() { + Ok((None, env)) + } else { + Ok((Some(cmd.as_unix_command_line()?), env)) + } + } } /// Carry out the authentication process and create the initial pty. @@ -485,21 +510,7 @@ impl Domain for RemoteSshDomain { ) -> Result, Error> { let pane_id = alloc_pane_id(); - let cmd = match command { - Some(c) => c, - None => CommandBuilder::new_default_prog(), - }; - - let command_line = if cmd.is_default_prog() { - None - } else { - Some(cmd.as_unix_command_line()?) - }; - let mut env: HashMap = cmd - .iter_extra_env_as_str() - .map(|(k, v)| (k.to_string(), v.to_string())) - .collect(); - env.insert("WEZTERM_PANE".to_string(), pane_id.to_string()); + let (command_line, env) = self.build_command(pane_id, command)?; let pty: Box; let child: Box; @@ -650,26 +661,8 @@ impl Domain for RemoteSshDomain { None => anyhow::bail!("invalid pane index {}", pane_index), }; - let config = config::configuration(); - let cmd = match command { - Some(mut cmd) => { - config.apply_cmd_defaults(&mut cmd, None); - cmd - } - None => config.build_prog(None, None, None)?, - }; let pane_id = alloc_pane_id(); - - let command_line = if cmd.is_default_prog() { - None - } else { - Some(cmd.as_unix_command_line()?) - }; - let mut env: HashMap = cmd - .iter_extra_env_as_str() - .map(|(k, v)| (k.to_string(), v.to_string())) - .collect(); - env.insert("WEZTERM_PANE".to_string(), pane_id.to_string()); + let (command_line, env) = self.build_command(pane_id, command)?; let session = self .session