Skip to content

fix: quote -x message arg so compadd does not insert the message as a match - #592

Open
HaleTom wants to merge 2 commits into
Aloxaf:masterfrom
HaleTom:fix/compadd-x-message-arg
Open

HaleTom wants to merge 2 commits into
Aloxaf:masterfrom
HaleTom:fix/compadd-x-message-arg

Conversation

@HaleTom

@HaleTom HaleTom commented Aug 25, 2026

Copy link
Copy Markdown

Problem

In -ftb-compadd, the -x message path mishandles how zparseopts stores its result:

if is-at-least 5.9 && (( $#_mesg != 0 )); then
  builtin compadd -x $_mesg
fi

zparseopts x:=_mesg appends both the option name and its value to the array, so $_mesg is ('-x' '<msg>'). The unquoted expansion after the literal -x therefore passes two -x tokens to compadd: compadd binds the literal second -x as the message argument, and <msg> is left over as a match word.

Reproduced with a minimal completer on zsh 5.9 (x86_64-linux):

# _t completion
_t() {
  local -a _opts __ expl _mesg
  set -- -x 'hello world msg'
  zparseopts -a _opts x:=_mesg X+:=expl q e Q n U C
  builtin compadd -x $_mesg
}

Pressing Tab on t <TAB> inserts hello\ world\ msg onto the command line instead of displaying the message. So any zero-match group that carries an -x message silently completes garbage text instead of showing the message.

Fix

Index into the array and quote it:

builtin compadd -x "$_mesg[2]"

After the fix, the same minimal case displays hello world msg as a message and inserts nothing.

HaleTom and others added 2 commits August 18, 2026 17:38
With use-fzf-default-opts yes, FZF_DEFAULT_OPTS is propagated into the
popup env (upstream Aloxaf#509). If it contains --tmux or --popup, fzf opens a
second (nested) popup inside the outer tmux popup -E, which flashes and
closes, inserting the query text instead of showing matches.

Strip --tmux/--popup (bare and =value forms) from the env value passed to
fzf inside the popup. Keep --height/--layout and all other opts.

Add 15 ztst cases covering bare/=value/mixed/separate-arg/empty inputs.
… match

zparseopts x:=_mesg stores ('-x' '<msg>') into the array; expanding it
unquoted after a literal -x passes two -x tokens. compadd binds the
literal '-x' as the message argument and inserts '<msg>' as a match
word, so zero-match groups with a message silently complete garbage.
Quoted index [2] gives compadd exactly one -x plus the message.
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