fix: keep the newest reported histfiles; bind the menu's run to cmd-enter

- shell-histfiles is append-only and panes starting together append the
  same path; reading the first 32 lines let stale or duplicate entries
  hide every path reported later. Keep the newest 32 distinct ones.
- secondary-enter is ctrl-enter off macOS, where the Ctrl+R menu only
  accepts on that chord. Bind cmd-enter, matching the menu's own key
  handler on every platform.
This commit is contained in:
l0ng-ai
2026-10-23 20:14:05 +08:00
parent c3440006c1
commit c9282c73f0
2 changed files with 27 additions and 5 deletions
+24 -4
View File
@@ -344,13 +344,20 @@ fn reported_history_files() -> Vec<PathBuf> {
fn parse_reported_history_files(text: &str) -> Vec<PathBuf> {
// The file is written from inside panes, so it is only a hint: a relative
// path would resolve against this process's directory, and a list that
// grew without bound is not one worth reading in full.
text.lines()
// grew without bound is not one worth reading in full. It is only ever
// appended to, and panes starting together each append the same path, so
// the newest distinct paths are the ones kept.
let mut seen = HashSet::new();
let mut files: Vec<PathBuf> = text
.lines()
.rev()
.map(str::trim)
.filter(|line| looks_absolute(line))
.filter(|line| looks_absolute(line) && seen.insert(*line))
.take(32)
.map(PathBuf::from)
.collect()
.collect();
files.reverse();
files
}
fn read_shell_history_files(mut files: Vec<PathBuf>) -> Vec<Raw> {
@@ -734,6 +741,19 @@ mod tests {
);
}
#[test]
fn reported_history_files_keep_the_newest_distinct_paths() {
let mut text = String::new();
for i in 0..40 {
text.push_str(&format!("/old/{i}\n/dup\n"));
}
text.push_str("/new\n");
let files = parse_reported_history_files(&text);
assert_eq!(files.len(), 32);
assert_eq!(files.last(), Some(&PathBuf::from("/new")));
assert_eq!(files.iter().filter(|p| *p == Path::new("/dup")).count(), 1);
}
#[test]
fn plain_bash_lines() {
assert_eq!(
+3 -1
View File
@@ -56,8 +56,10 @@ fn fixed_bindings() -> Vec<KeyBinding> {
// The Ctrl+R menu runs its selection on Cmd+Enter, which on macOS is
// also `ToggleFullscreen`. Scoped to the open menu, it is deeper in
// the dispatch path than the window binding and wins only there.
// `cmd`, not `secondary`: the menu's own key handler runs on the
// platform key everywhere, and Ctrl+Enter off macOS only accepts.
KeyBinding::new(
"secondary-enter",
"cmd-enter",
RunReverseSearchSelection,
Some("Terminal && reverse_search"),
),