From b8ff61da5b64be27a061ace80a2840142d0ead41 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 25 Oct 2021 15:26:30 -0700 Subject: [PATCH] ssh: allow `wezterm ssh -v` to log verbose diagnostics to stderr Feels generally useful --- wezterm-gui-subcommands/src/lib.rs | 6 ++++++ wezterm-gui/src/main.rs | 3 +++ wezterm-ssh/src/sessioninner.rs | 20 ++++++++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/wezterm-gui-subcommands/src/lib.rs b/wezterm-gui-subcommands/src/lib.rs index f7748e4e3..c69537d73 100644 --- a/wezterm-gui-subcommands/src/lib.rs +++ b/wezterm-gui-subcommands/src/lib.rs @@ -76,6 +76,12 @@ pub struct SshCommand { number_of_values = 1)] pub config_override: Vec<(String, String)>, + /// Enable verbose ssh protocol tracing. + /// The trace information is printed to the stderr stream of + /// the process. + #[structopt(short = "v")] + pub verbose: bool, + /// Instead of executing your shell, run PROG. /// For example: `wezterm ssh user@host -- bash -l` will spawn bash /// as if it were a login shell. diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index 1bea10318..4af360620 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -115,6 +115,9 @@ async fn async_run_ssh(opts: SshCommand) -> anyhow::Result<()> { } .to_string(), ); + if opts.verbose { + ssh_config.insert("wezterm_ssh_verbose".to_string(), "true".to_string()); + } if let Some(username) = &opts.user_at_host_and_port.username { ssh_config.insert("user".to_string(), username.to_string()); diff --git a/wezterm-ssh/src/sessioninner.rs b/wezterm-ssh/src/sessioninner.rs index 88aaa8885..f3f0bdcbb 100644 --- a/wezterm-ssh/src/sessioninner.rs +++ b/wezterm-ssh/src/sessioninner.rs @@ -104,7 +104,15 @@ impl SessionInner { .context("notifying user of banner")?; let sess = libssh::Session::new()?; - // sess.set_option(libssh::SshOption::LogLevel(libssh::LogLevel::Packet))?; + if self + .config + .get("wezterm_ssh_verbose") + .map(|s| s.as_str()) + .unwrap_or("false") + == "true" + { + sess.set_option(libssh::SshOption::LogLevel(libssh::LogLevel::Packet))?; + } sess.set_option(libssh::SshOption::Hostname(hostname.clone()))?; sess.set_option(libssh::SshOption::User(Some(user)))?; sess.set_option(libssh::SshOption::Port(port))?; @@ -221,7 +229,15 @@ impl SessionInner { }; let mut sess = ssh2::Session::new()?; - // sess.trace(ssh2::TraceFlags::all()); + if self + .config + .get("wezterm_ssh_verbose") + .map(|s| s.as_str()) + .unwrap_or("false") + == "true" + { + sess.trace(ssh2::TraceFlags::all()); + } sess.set_blocking(true); sess.set_tcp_stream(tcp); sess.handshake()