[Discussion] Optimising history matching pool architecture (Trade-offs in prefix filtering)
Hi everyone
Not sure if this is the right sub, but I already tried other subs like r/zsh , r/commandline and others, but no luck.
I am working on a personal project and while refining the functions/history matching logic to address early mutation typos like ccd instead of cd, the project faces a classic architectural trade-off between output cleanliness and edge-case coverage.
Currently, the single-character prefix filter provides reliable and clean output pool for 99% of user typos, including mutations inside trailing directory arguments:
local -a narrowed_entries=()
if [[ ${#last_typo} -ge 1 ]]; then
local prefix="${last_typo[0,1]}"
narrowed_entries=(${(M)hist_entries:#${prefix}*})
else
narrowed_entries=("${hist_entries[@]}")
fi
The Dilemma I am facing
This approach goes blind if a user makes a typo on the absolute first character of a command (for example typing vcd functions instead of cd functions).
To resolve this 1% edge case, experimenting with multi-character character sets or dual-prefix lookups (matching vc*) successfully injects the intended target cd back into the array pool.
However, it introduces a significant downside. It drastically widens the filter pool, pulling in hundreds of irrelevant historical commands (like vim, vlc), or anything that happen to share those initial letters. This pollutes the fzf layout and introduces messy, unrelated suggestions that degrade the user experience.
Personal Choice of Direction
I personally lean towards sacrificing the 1% first-character typo to guarantee a completely stable, clean, and highly relevant list of suggestions for the other 99% of daily interactions. A predictable interface that behaves reliably is more valuable than an over-engineered matching layout that makes messy guesses.
Opening this up to the community: Should I stick to the strict, clean single-character baseline, or is there a performant, dependency-agnostic way to handle first-character mutations without introducing buffer noise into the interactive menu?