Skip to content

Commit

Permalink
wezterm cli list-clients: add ssh_auth_sock to json, tidy up duration
Browse files Browse the repository at this point in the history
Make longer durations a bit more intelligible.
Add the auth sock to the json format output from the command.
  • Loading branch information
wez committed May 10, 2024
1 parent e19def7 commit ca27f92
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wezterm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 18 additions & 2 deletions wezterm/src/cli/list_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand All @@ -133,6 +147,7 @@ impl From<mux::client::ClientInfo> for CliListClientsResultItem {
username,
hostname,
pid,
ssh_auth_sock,
..
} = client_id.as_ref();

Expand All @@ -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()),
}
}
}

0 comments on commit ca27f92

Please sign in to comment.