Feat: support _approximate to correctly show correction options #554
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR resolves long-standing issues where
_approximate(fuzzy matching) and_correctwould bypassfzf-taband fall back to the standard Zsh menu completion.Fixes #56
Fixes #470
The Problem
Support for
_approximatehas been broken due to three specific conflicts betweenfzf-taband Zsh's internal implementation of the completer:_approximatechecksif (( ! $+functions[compadd] )). Sincefzf-tabdefinescompaddglobally,_approximatedetects this and skips defining its local wrapper. This prevents the fuzzy globbing logic (e.g.,(#a1)) from ever initializing._approximateexplicitly callsbuiltin compadd, bypassing thefzf-tabcapture function (-ftb-compadd)._approximategenerates corrections (e.g.,Docn->Documents,Downloads), Zsh calculates a common unambiguous prefix (Do).fzf-tabdetects this unambiguous prefix and auto-accepts it, exiting before displaying the selection list, even though_approximatesetscompstate[list]="list force".The Solution
This PR implements a robust fix involving dynamic patching and a logic update in the completion handler:
Dynamic Source Patching:
In
enable-fzf-tab, we dynamically load_approximateand create a patched version wherebuiltin compaddis replaced with-ftb-compadd. This ensures we capture the matches without maintaining a hard-coded copy of the_approximatesource code.Temporary Hook Unregistration:
We wrap the execution of
_approximate. inside this wrapper, we rununfunction compaddbefore calling the patched logic. This satisfies_approximate's internal check, forcing it to define its local fuzzy-matching wrapper (which now calls our capture function). The global hook is restored immediately in analwaysblock.Respect
compstate[list] force:Updated
-ftb-completeto check ifcompstate[list]contains"force". If it does,fzf-tabwill now display the list even if there is an unambiguous prefix, allowing the user to select between the original input and corrections.Verification configuration
Tested with the following configuration:
Scenario:
Type
cd Docnand press TAB.Before: Zsh standard menu appears below the prompt.
After:
fzf-tabopens, showingDocumentsandDownloads(and the originalDocn) correctly.