Skip to content

Conversation

@alberti42
Copy link
Contributor

Fix associative subscript completion broken by local keys shadowing

This PR fixes a long‑standing completion bug in fzf-tab where associative array subscripts could complete to unrelated tokens like PREFIX, even when those are not real keys.

Root cause

Inside -ftb-compadd, we declared a local array named keys to capture metadata fields (PREFIX, SUFFIX, IPREFIX, ISUFFIX, etc.) for fzf-tab’s internal completion capture.

However, Zsh’s associative subscript completion uses compadd -a keys and expects a keys array from the completer context (containing the actual associative keys). Because -ftb-compadd runs in the same dynamic scope, our local keys shadowed that array. As a result, completion candidates were taken from our internal metadata list, not the real associative keys.

Symptom

Example (no _approximate needed):

typeset -A ZINIT
ZINIT[PLUGIN_DIR]=/tmp/plugin
ZINIT[PLUGINS_DIR]=/tmp/plugins

# Pressing TAB here could insert PREFIX (not a real key):
echo $ZINIT[P<TAB>

Instead of completing to PLUGIN..., it could insert PREFIX because that was one of the internal metadata field names.

Fix

Rename the internal array from keys to _ftb_compcap_keys in -ftb-compadd to avoid the name collision. This restores correct associative key completion without changing any completion logic or behavior for other paths.

Compatibility

All existing tests continue to pass.

… the completer’s `keys` array when using compadd -a keys
alberti42 added a commit to alberti42/fzf-tab-fork that referenced this pull request Jan 17, 2026
alberti42 added a commit to alberti42/fzf-tab-fork that referenced this pull request Jan 17, 2026
alberti42 added a commit to alberti42/fzf-tab-fork that referenced this pull request Jan 18, 2026
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.

1 participant