From 118d5fb877381d207ec7e97262df584b3f4eb606 Mon Sep 17 00:00:00 2001 From: Rousseau Vincent Date: Tue, 15 Jul 2025 10:26:43 +0200 Subject: [PATCH] fix: populate layount metadata with the right cmd and cwd (#4287) Add cmd from sysinfo in terminal_ids_to_commands if no cmd are return by ps. So then, cmd and cwd are udpated in "session-layout.kdl" even if no cmd is runing in pane. --- zellij-server/src/os_input_output.rs | 14 ++++++++++---- zellij-server/src/pty.rs | 11 ++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/zellij-server/src/os_input_output.rs b/zellij-server/src/os_input_output.rs index 175ec289..a85fab6f 100644 --- a/zellij-server/src/os_input_output.rs +++ b/zellij-server/src/os_input_output.rs @@ -508,8 +508,8 @@ pub trait ServerOsApi: Send + Sync { /// Returns the current working directory for a given pid fn get_cwd(&self, pid: Pid) -> Option; /// Returns the current working directory for multiple pids - fn get_cwds(&self, _pids: Vec) -> HashMap { - HashMap::new() + fn get_cwds(&self, _pids: Vec) -> (HashMap, HashMap>) { + (HashMap::new(), HashMap::new()) } /// Get a list of all running commands by their parent process id fn get_all_cmds_by_ppid(&self, _post_hook: &Option) -> HashMap> { @@ -755,9 +755,10 @@ impl ServerOsApi for ServerOsInputOutput { None } - fn get_cwds(&self, pids: Vec) -> HashMap { + fn get_cwds(&self, pids: Vec) -> (HashMap, HashMap>) { let mut system_info = System::new(); let mut cwds = HashMap::new(); + let mut cmds = HashMap::new(); for pid in pids { // Update by minimizing information. @@ -767,15 +768,20 @@ impl ServerOsApi for ServerOsInputOutput { if is_found { if let Some(process) = system_info.process(pid.into()) { let cwd = process.cwd(); + let cmd = process.cmd(); let cwd_is_empty = cwd.iter().next().is_none(); if !cwd_is_empty { cwds.insert(pid, process.cwd().to_path_buf()); } + let cmd_is_empty = cmd.iter().next().is_none(); + if !cmd_is_empty { + cmds.insert(pid, process.cmd().to_vec()); + } } } } - cwds + (cwds, cmds) } fn get_all_cmds_by_ppid(&self, post_hook: &Option) -> HashMap> { // the key is the stringified ppid diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs index 2658188b..26fe7203 100644 --- a/zellij-server/src/pty.rs +++ b/zellij-server/src/pty.rs @@ -1425,7 +1425,7 @@ impl Pty { .filter_map(|id| self.id_to_child_pid.get(&id)) .map(|pid| Pid::from_raw(*pid)) .collect(); - let pids_to_cwds = self + let (pids_to_cwds, pids_to_cmds) = self .bus .os_input .as_ref() @@ -1443,10 +1443,15 @@ impl Pty { let cwd = process_id .as_ref() .and_then(|pid| pids_to_cwds.get(&Pid::from_raw(**pid))); - let cmd = process_id + let cmd_sysinfo = process_id + .as_ref() + .and_then(|pid| pids_to_cmds.get(&Pid::from_raw(**pid))); + let cmd_ps = process_id .as_ref() .and_then(|pid| ppids_to_cmds.get(&format!("{}", pid))); - if let Some(cmd) = cmd { + if let Some(cmd) = cmd_ps { + terminal_ids_to_commands.insert(terminal_id, cmd.clone()); + } else if let Some(cmd) = cmd_sysinfo { terminal_ids_to_commands.insert(terminal_id, cmd.clone()); } if let Some(cwd) = cwd {