diff options
Diffstat (limited to 'src/pane.rs')
| -rw-r--r-- | src/pane.rs | 26 |
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)); |
