feat(gpui): remember terminal startup directories

This commit is contained in:
GeekMr committed 2026-09-21 21:38:12 +08:00
1 parent 3050374343
commit 1338cce766
2 files changed
+45 -4

No files matched your search

+3 -3
View File
@@ -1,7 +1,7 @@
//! Shared directory intelligence derived from successful cwd transitions.
//! Shared directory intelligence derived from successful local terminal locations.
//!
//! Unlike command-text heuristics, this service records only directories the
//! shell actually entered (reported through OSC cwd/title integration). The
//! Unlike command-text heuristics, this service records only directories a local
//! terminal successfully starts in or later reports through cwd integration. The
//! resulting frecency score is reused by ghost text, path completion and UI
//! directory pickers; no shell-specific command or alias is introduced.
@@ -2,6 +2,16 @@
use super::*;
fn startup_history_directory(
options: &nebula_terminal::tty::Options,
env: &crate::display::SuggestEnv,
) -> Option<std::path::PathBuf> {
env.is_this_machine()
.then(|| options.working_directory.clone().or_else(|| std::env::current_dir().ok()))
.flatten()
.and_then(|path| std::path::absolute(path).ok())
}
impl TerminalView {
/// `spawn_grid`:PTY 出生网格(宿主已把窗口定形到该几何)。首帧布局
/// 与之相同则零下发;见 `set_layout` 的启动稳定闸。
@@ -116,7 +126,14 @@ impl TerminalView {
},
);
let options = session::local_options(effective, pane_id, cwd);
let history_cwd = startup_history_directory(&options, &suggest_env);
let exec_context = crate::runtime_exec::PaneExecContext::from_pty_options(&options);
let spawned = session::spawn(initial, term_config, options);
if spawned.is_ok()
&& let Some(cwd) = history_cwd.as_deref().and_then(|path| path.to_str())
{
crate::directory_history::global().record(cwd);
}
(
None,
String::from("shell"),
@@ -124,7 +141,7 @@ impl TerminalView {
suggest_env,
Some(exec_context),
session_launch,
session::spawn(initial, term_config, options),
spawned,
)
},
TerminalLaunch::Ssh { destination, cwd } => (
@@ -332,3 +349,27 @@ impl TerminalView {
view
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn startup_history_uses_only_local_initial_directories() {
let directory = tempfile::tempdir().unwrap();
let mut options = nebula_terminal::tty::Options::default();
options.working_directory = Some(directory.path().to_path_buf());
assert_eq!(
startup_history_directory(&options, &crate::display::SuggestEnv::Local).as_deref(),
Some(directory.path())
);
assert_eq!(
startup_history_directory(
&options,
&crate::display::SuggestEnv::Wsl { distro: "Debian".into() }
),
None
);
}
}