1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-27 12:23:46 +03:00

ssh: use env when assume_shell=Posix

This allows us to send over COLORTERM and TERM_PROGRAM_XXX environment
that the SSH server would have denied via AcceptEnv rules.
This commit is contained in:
Wez Furlong 2022-01-26 10:44:27 -07:00
parent 0ce029fdba
commit 25b4b3ff87
4 changed files with 41 additions and 9 deletions

1
Cargo.lock generated
View File

@ -2323,6 +2323,7 @@ dependencies = [
"ratelim", "ratelim",
"regex", "regex",
"serde", "serde",
"shell-words",
"smol", "smol",
"terminfo", "terminfo",
"termwiz", "termwiz",

View File

@ -76,9 +76,9 @@ panes and tabs. The following values are recognized for `assume_shell`:
* `"Unknown"` - this is the default. We can't make any assumptions about the * `"Unknown"` - this is the default. We can't make any assumptions about the
remote shell. remote shell.
* `"Posix"` - the remote host uses a Bourne Shell compatible shell that allows * `"Posix"` - the remote host uses a POSIX/Bourne Shell compatible environment
the syntax `cd DIR ; exec CMD` and `cd DIR ; exec $SHELL`. that allows the syntax `env -c DIR ENV1=VAL1 ENV2=VAL2 CMD` and
`env -c DIR ENV1=VAL1 ENV2=VAL2 $SHELL`.
```lua ```lua
return { return {
@ -96,7 +96,7 @@ return {
default_prog = {"fish"}, default_prog = {"fish"},
-- assume that we can use syntax like: -- assume that we can use syntax like:
-- "cd /some/where ; exec $SHELL" -- "env -C /some/where $SHELL"
-- using whatever the default command shell is on this -- using whatever the default command shell is on this
-- remote host, so that shell integration will respect -- remote host, so that shell integration will respect
-- the current directory on the remote host. -- the current directory on the remote host.

View File

@ -32,6 +32,7 @@ rangeset = { path = "../rangeset" }
ratelim= { path = "../ratelim" } ratelim= { path = "../ratelim" }
regex = "1" regex = "1"
serde = {version="1.0", features = ["rc", "derive"]} serde = {version="1.0", features = ["rc", "derive"]}
shell-words = "1.0"
smol = "1.2" smol = "1.2"
terminfo = "0.7" terminfo = "0.7"
termwiz = { path = "../termwiz" } termwiz = { path = "../termwiz" }

View File

@ -213,13 +213,43 @@ impl RemoteSshDomain {
.iter_extra_env_as_str() .iter_extra_env_as_str()
.map(|(k, v)| (k.to_string(), v.to_string())) .map(|(k, v)| (k.to_string(), v.to_string()))
.collect(); .collect();
env.insert("WEZTERM_PANE".to_string(), pane_id.to_string());
// FIXME: this isn't useful without a way to talk to the remote mux.
// One option is to forward the mux via unix domain, another is to
// embed the mux protocol in an escape sequence and just use the
// existing terminal connection
env.insert("WEZTERM_REMOTE_PANE".to_string(), pane_id.to_string());
fn build_env_command(
dir: Option<String>,
cmd: &CommandBuilder,
env: &HashMap<String, String>,
) -> anyhow::Result<String> {
let mut env_cmd = vec!["env".to_string()];
if let Some(dir) = dir {
env_cmd.push("-C".to_string());
env_cmd.push(dir.clone());
} else if let Some(dir) = cmd.get_cwd() {
let dir = dir.to_str().context("converting cwd to string")?;
env_cmd.push("-C".to_string());
env_cmd.push(dir.to_string());
}
for (k, v) in env {
env_cmd.push(format!("{}={}", k, v));
}
let cmd = if cmd.is_default_prog() {
"$SHELL".to_string()
} else {
cmd.as_unix_command_line()?
};
Ok(shell_words::join(env_cmd) + " " + &cmd)
}
let command_line = match (cmd.is_default_prog(), self.dom.assume_shell, command_dir) { let command_line = match (cmd.is_default_prog(), self.dom.assume_shell, command_dir) {
(true, Shell::Posix, Some(dir)) => Some(format!("cd {} ; exec $SHELL", dir)), (_, Shell::Posix, dir) => Some(build_env_command(dir, &cmd, &env)?),
(false, Shell::Posix, Some(dir)) => {
Some(format!("cd {} ; exec {}", dir, cmd.as_unix_command_line()?))
}
(true, _, _) => None, (true, _, _) => None,
(false, _, _) => Some(cmd.as_unix_command_line()?), (false, _, _) => Some(cmd.as_unix_command_line()?),
}; };