Skip to content

Conversation

@alberti42
Copy link
Contributor

This PR resolves long-standing issues where _approximate (fuzzy matching) and _correct would bypass fzf-tab and fall back to the standard Zsh menu completion.

Fixes #56
Fixes #470

The Problem

Support for _approximate has been broken due to three specific conflicts between fzf-tab and Zsh's internal implementation of the completer:

  1. Hook Conflict: _approximate checks if (( ! $+functions[compadd] )). Since fzf-tab defines compadd globally, _approximate detects this and skips defining its local wrapper. This prevents the fuzzy globbing logic (e.g., (#a1)) from ever initializing.
  2. Capture Bypass: Even if the wrapper runs, _approximate explicitly calls builtin compadd, bypassing the fzf-tab capture function (-ftb-compadd).
  3. Early Exit on Unambiguous Prefix: When _approximate generates corrections (e.g., Docn -> Documents, Downloads), Zsh calculates a common unambiguous prefix (Do). fzf-tab detects this unambiguous prefix and auto-accepts it, exiting before displaying the selection list, even though _approximate sets compstate[list]="list force".

The Solution

This PR implements a robust fix involving dynamic patching and a logic update in the completion handler:

  1. Dynamic Source Patching:
    In enable-fzf-tab, we dynamically load _approximate and create a patched version where builtin compadd is replaced with -ftb-compadd. This ensures we capture the matches without maintaining a hard-coded copy of the _approximate source code.

  2. Temporary Hook Unregistration:
    We wrap the execution of _approximate. inside this wrapper, we run unfunction compadd before 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 an always block.

  3. Respect compstate[list] force:
    Updated -ftb-complete to check if compstate[list] contains "force". If it does, fzf-tab will 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:

zstyle ':completion:*' completer _complete _match _approximate
zstyle ':completion:*:match:*' original only
zstyle ':completion:*:approximate:*' max-errors 1 numeric

Scenario:
Type cd Docn and press TAB.
Before: Zsh standard menu appears below the prompt.
After: fzf-tab opens, showing Documents and Downloads (and the original Docn) correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support _approximate completer [BUG] FZF tab completion does not activate on similar file names

1 participant