diff --git a/src-tauri/src/ssh/session.rs b/src-tauri/src/ssh/session.rs index 4852d29..c36be93 100644 --- a/src-tauri/src/ssh/session.rs +++ b/src-tauri/src/ssh/session.rs @@ -157,6 +157,23 @@ impl SshService { // Start remote monitoring if enabled (runs on a separate exec channel) crate::ssh::monitor::start_monitor(handle.clone(), app_handle.clone(), session_id.clone()); + // Inject OSC 7 CWD reporting hook into the user's shell. + // This enables SFTP CWD following on all platforms (Linux, macOS, FreeBSD). + // Sent via the PTY channel so it configures the interactive shell. + { + let osc7_hook = concat!( + // Detect shell and inject the appropriate hook silently + r#"if [ -n "$ZSH_VERSION" ]; then "#, + r#"precmd() { printf '\033]7;file://%s%s\033\\' "$HOST" "$PWD"; }; "#, + r#"elif [ -n "$BASH_VERSION" ]; then "#, + r#"PROMPT_COMMAND='printf "\033]7;file://%s%s\033\\\\" "$HOSTNAME" "$PWD"'; "#, + r#"fi"#, + "\n" + ); + let h = handle.lock().await; + let _ = h.data(channel_id, CryptoVec::from_slice(osc7_hook.as_bytes())).await; + } + // Output reader loop — owns the Channel exclusively. // Writes go through Handle::data() so no shared mutex is needed. let sid = session_id.clone(); diff --git a/src/components/sftp/FileTree.vue b/src/components/sftp/FileTree.vue index 0bb9523..3b711ba 100644 --- a/src/components/sftp/FileTree.vue +++ b/src/components/sftp/FileTree.vue @@ -208,7 +208,7 @@