1
1
mirror of https://github.com/wez/wezterm.git synced 2024-08-16 17:50:28 +03:00

wezterm cli list-clients: add ssh_auth_sock to json, tidy up duration

Make longer durations a bit more intelligible.
Add the auth sock to the json format output from the command.
This commit is contained in:
Wez Furlong 2024-05-10 08:27:05 -07:00
parent e19def7c9a
commit ca27f921e2
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
3 changed files with 20 additions and 2 deletions

1
Cargo.lock generated
View File

@ -6431,6 +6431,7 @@ dependencies = [
"env-bootstrap",
"filedescriptor",
"hostname",
"humantime",
"image",
"libc",
"log",

View File

@ -17,6 +17,7 @@ config = { path = "../config" }
env-bootstrap = { path = "../env-bootstrap" }
filedescriptor = { version="0.8", path = "../filedescriptor" }
hostname = "0.4"
humantime = "2.1"
image = "0.25"
libc = "0.2"
log = "0.4"

View File

@ -67,7 +67,20 @@ impl ListClientsCommand {
fn duration_string(d: chrono::Duration) -> String {
if let Ok(d) = d.to_std() {
format!("{:?}", d)
// The default is full precision, which is a bit
// overwhelming (https://github.com/tailhook/humantime/issues/35).
// Let's auto-adjust this to be a bit more reasonable.
use std::time::Duration;
let seconds = d.as_secs();
let adjusted = if seconds >= 60 {
Duration::from_secs(seconds)
} else {
Duration::from_millis(d.as_millis() as u64)
};
let mut formatted = humantime::format_duration(adjusted).to_string();
formatted.retain(|c| c != ' ');
formatted
} else {
d.to_string()
}
@ -114,6 +127,7 @@ struct CliListClientsResultItem {
idle_time: std::time::Duration,
workspace: String,
focused_pane_id: Option<mux::pane::PaneId>,
ssh_auth_sock: Option<String>,
}
impl From<mux::client::ClientInfo> for CliListClientsResultItem {
@ -133,6 +147,7 @@ impl From<mux::client::ClientInfo> for CliListClientsResultItem {
username,
hostname,
pid,
ssh_auth_sock,
..
} = client_id.as_ref();
@ -148,7 +163,8 @@ impl From<mux::client::ClientInfo> for CliListClientsResultItem {
.unwrap_or(std::time::Duration::ZERO),
idle_time: idle_time.to_std().unwrap_or(std::time::Duration::ZERO),
workspace: active_workspace.as_deref().unwrap_or("").to_string(),
focused_pane_id: focused_pane_id,
focused_pane_id,
ssh_auth_sock: ssh_auth_sock.as_ref().map(|s| s.to_string()),
}
}
}