aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pane.rs26
-rw-r--r--src/terminal/runtime.rs4
-rw-r--r--src/workspace/tab.rs11
3 files changed, 39 insertions, 2 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));
diff --git a/src/terminal/runtime.rs b/src/terminal/runtime.rs
index 1d19ad4a..0241f984 100644
--- a/src/terminal/runtime.rs
+++ b/src/terminal/runtime.rs
@@ -453,6 +453,10 @@ impl TerminalRuntime {
self.0.cwd()
}
+ pub fn follow_cwd(&self) -> Option<std::path::PathBuf> {
+ self.0.follow_cwd()
+ }
+
pub fn foreground_cwd(&self) -> Option<std::path::PathBuf> {
self.0.foreground_cwd()
}
diff --git a/src/workspace/tab.rs b/src/workspace/tab.rs
index 15ca7e45..4c86a6e8 100644
--- a/src/workspace/tab.rs
+++ b/src/workspace/tab.rs
@@ -578,7 +578,14 @@ impl Tab {
terminals: &HashMap<TerminalId, TerminalState>,
terminal_runtimes: &TerminalRuntimeRegistry,
) -> Option<PathBuf> {
- self.foreground_cwd_for_pane(pane_id, terminal_runtimes)
- .or_else(|| self.cwd_for_pane(pane_id, terminals, terminal_runtimes))
+ let terminal_id = self.terminal_id(pane_id)?;
+ terminal_runtimes
+ .get(terminal_id)
+ .and_then(|runtime| runtime.follow_cwd())
+ .or_else(|| {
+ terminals
+ .get(terminal_id)
+ .map(|terminal| terminal.cwd.clone())
+ })
}
}