aboutsummaryrefslogtreecommitdiff
path: root/src/pane.rs
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-07-16 23:13:06 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-07-16 23:13:41 +0300
commit550e9f8cc085f428429f5cf2da0bb2dba897e8b8 (patch)
tree996e9cbbf905b89df8bd512fa9b0e68d07e25943 /src/pane.rs
parent8dcb75a5c08b4dd1f225ea531a27824a9f41ae4a (diff)
fix: follow foreground process group leader cwd
refs #1472
Diffstat (limited to 'src/pane.rs')
-rw-r--r--src/pane.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/pane.rs b/src/pane.rs
index 5bb6fe4e..3c817876 100644
--- a/src/pane.rs
+++ b/src/pane.rs
@@ -2713,6 +2713,22 @@ impl PaneRuntime {
(pid > 0).then_some(pid)
}
+ pub fn follow_cwd(&self) -> Option<std::path::PathBuf> {
+ #[cfg(unix)]
+ {
+ let leader_cwd = self
+ .io
+ .foreground_process_group_id()
+ .and_then(usable_process_cwd);
+ leader_cwd.or_else(|| self.cwd())
+ }
+
+ #[cfg(not(unix))]
+ {
+ self.cwd()
+ }
+ }
+
/// Get the current working directory of the process group controlling the pane PTY.
pub fn foreground_cwd(&self) -> Option<std::path::PathBuf> {
#[cfg(unix)]
@@ -2816,6 +2832,16 @@ impl PaneRuntime {
mod tests {
use super::*;
+ #[cfg(unix)]
+ #[tokio::test]
+ async fn follow_cwd_falls_back_to_reported_pane_cwd_without_foreground_group() {
+ let (runtime, _rx) = PaneRuntime::test_with_channel(80, 24);
+ let cwd = std::env::temp_dir();
+ *runtime.reported_cwd.lock().unwrap() = Some(cwd.clone());
+
+ assert_eq!(runtime.follow_cwd(), Some(cwd));
+ }
+
#[test]
fn shutdown_liveness_treats_reaped_direct_child_as_gone() {
assert!(!process_alive_for_shutdown(42, 42, true, |_| true));