feat: the SFTP browser opens in the shell's current directory (OSC 7)

When the remote shell reports its working directory (OSC 7: fish, or
the bash/zsh hook in the manual), opening the SFTP browser from that
terminal goes there, including when it was already open elsewhere.
Without it the browser still falls back to the exec'd 'pwd' (the login
directory) and then the SFTP home. The File menu entry now goes through
the same request as the toolbar and palette.
This commit is contained in:
Andy Dixon
2026-10-12 18:40:11 +01:00
parent 58cb531e32
commit 1fcb5fa575
3 changed files with 21 additions and 4 deletions
+13 -2
View File
@@ -109,6 +109,8 @@ pub struct Sftp {
/// Profile id (or host:port for quick connects) → bookmarked paths. Loaded on first use.
bookmarks: Option<BTreeMap<String, Vec<String>>>,
inbox: Arc<Mutex<Vec<Done>>>,
/// Where a browser opened from a terminal should start: the directory its shell reported.
start_at: HashMap<String, String>,
}
// --- path helpers ---------------------------------------------------------------------------
@@ -215,11 +217,16 @@ fn state_line(ui: &mut Ui, loading: bool, error: Option<&str>) -> bool {
}
impl Sftp {
pub fn toggle(&mut self, session: &str) {
/// Opens (or closes) the browser for `session`; `at` is the shell's reported directory, which
/// the browser goes to when it opens.
pub fn toggle(&mut self, session: &str, at: Option<String>) {
if self.open_for.as_deref() == Some(session) {
self.close(session);
} else {
self.open_for = Some(session.into());
if let Some(dir) = at.filter(|d| d.starts_with('/')) {
self.start_at.insert(session.into(), dir);
}
}
}
@@ -488,7 +495,11 @@ impl Sftp {
let Some(session) = self.open_for.clone() else {
return;
};
if !self.panels.contains_key(&session) {
if let Some(dir) = self.start_at.remove(&session) {
if self.panels.get(&session).is_none_or(|p| p.cwd != dir) {
self.navigate(s, &session, Some(dir));
}
} else if !self.panels.contains_key(&session) {
self.navigate(s, &session, None);
}
let t = Tokens::get(ui.ctx());