diff options
Diffstat (limited to 'crates/dinggerd/src/watcher.rs')
| -rw-r--r-- | crates/dinggerd/src/watcher.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/crates/dinggerd/src/watcher.rs b/crates/dinggerd/src/watcher.rs index 2455407..e87a7bf 100644 --- a/crates/dinggerd/src/watcher.rs +++ b/crates/dinggerd/src/watcher.rs @@ -305,6 +305,15 @@ impl Watcher { if pane.written_agent != agent { let _ = tmux::set_pane_option(&pane.pane_id, "@agent", agent); } + let name = crate::names::display_name(pane.agent, &pane.pane_title, &pane.cwd, host_name()) + .unwrap_or_default(); + if pane.written_name != name { + let _ = if name.is_empty() { + tmux::unset_pane_option(&pane.pane_id, "@agent_name") + } else { + tmux::set_pane_option(&pane.pane_id, "@agent_name", &name) + }; + } // Persist the authoritative hook state so a restart keeps it. let hook = hooks::last_state(&pane.pane_id) .map(state_label) @@ -410,6 +419,17 @@ fn observe(pane: &tmux::Pane) -> Option<Vec<AgentState>> { (!detection.skip_state_update).then(|| vec![detection.state]) } +/// The host name tmux uses as a pane's default title. +fn host_name() -> &'static str { + static HOST: std::sync::OnceLock<String> = std::sync::OnceLock::new(); + HOST.get_or_init(|| { + std::process::Command::new("hostname") + .output() + .map(|out| String::from_utf8_lossy(&out.stdout).trim().to_string()) + .unwrap_or_default() + }) +} + fn state_label(state: AgentState) -> &'static str { match state { AgentState::Idle => "idle", |
