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

ssh: support %l and %L in config files

We also log a warning when an unsupported token is used.

refs: https://github.com/wez/wezterm/issues/3176
This commit is contained in:
Wez Furlong 2023-03-01 18:44:11 -07:00
parent 0ac1cbc47c
commit 2d05f8f1f2
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
4 changed files with 49 additions and 0 deletions

26
Cargo.lock generated
View File

@ -1734,6 +1734,16 @@ dependencies = [
"version_check",
]
[[package]]
name = "gethostname"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a329e22866dd78b35d2c639a4a23d7b950aeae300dfd79f4fb19f74055c2404"
dependencies = [
"libc",
"windows 0.43.0",
]
[[package]]
name = "getopts"
version = "0.2.21"
@ -6061,6 +6071,7 @@ dependencies = [
"env_logger",
"filedescriptor",
"filenamegen",
"gethostname",
"k9",
"libc",
"libssh-rs",
@ -6360,6 +6371,21 @@ dependencies = [
"windows_x86_64_msvc 0.33.0",
]
[[package]]
name = "windows"
version = "0.43.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04662ed0e3e5630dfa9b26e4cb823b817f1a9addda855d973a9458c236556244"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc 0.42.1",
"windows_i686_gnu 0.42.1",
"windows_i686_msvc 0.42.1",
"windows_x86_64_gnu 0.42.1",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc 0.42.1",
]
[[package]]
name = "windows"
version = "0.44.0"

View File

@ -71,6 +71,8 @@ As features stabilize some brief notes about them will accumulate here.
* `CTRL-SHIFT-P` now activates the new [command
palette](config/lua/keyassignment/ActivateCommandPalette.md)
[#1485](https://github.com/wez/wezterm/issues/1485)
* `wezterm sssh` now supports `%l` and `%L` tokens in config files.
[#3176](https://github.com/wez/wezterm/issues/3176)
#### Fixed
* X11: hanging or killing the IME could hang wezterm

View File

@ -24,6 +24,7 @@ camino = "1.0"
dirs-next = "2.0"
filedescriptor = { version="0.8", path = "../filedescriptor" }
filenamegen = "0.2"
gethostname = "0.4"
libc = "0.2"
log = "0.4"
portable-pty = { version="0.8", path = "../pty" }

View File

@ -477,6 +477,19 @@ impl Config {
}
}
fn resolve_local_host(&self, include_domain_name: bool) -> String {
let hostname = gethostname::gethostname().to_string_lossy().to_string();
if include_domain_name {
hostname
} else {
match hostname.split_once('.') {
Some((hostname, _domain)) => hostname.to_string(),
None => hostname,
}
}
}
fn resolve_local_user(&self) -> String {
for user in &["USER", "USERNAME"] {
if let Some(user) = self.resolve_env(user) {
@ -621,11 +634,16 @@ impl Config {
/// Perform token substitution
fn expand_tokens(&self, value: &mut String, tokens: &[&str], token_map: &ConfigMap) {
let orig_value = value.to_string();
for &t in tokens {
if let Some(v) = token_map.get(t) {
*value = value.replace(t, v);
} else if t == "%u" {
*value = value.replace(t, &self.resolve_local_user());
} else if t == "%l" {
*value = value.replace(t, &self.resolve_local_host(false));
} else if t == "%L" {
*value = value.replace(t, &self.resolve_local_host(true));
} else if t == "%d" {
if let Some(home) = self.resolve_home() {
let mut items = value
@ -641,6 +659,8 @@ impl Config {
}
*value = items.join(" ");
}
} else if value.contains(t) {
log::warn!("Unsupported token {t} when evaluating `{orig_value}`");
}
}