Skip to content

fix: strip carapace double-backslash quoting in compadd capture - #584

Open
nirvana6 wants to merge 1 commit into
Aloxaf:masterfrom
nirvana6:master
Open

fix: strip carapace double-backslash quoting in compadd capture#584
nirvana6 wants to merge 1 commit into
Aloxaf:masterfrom
nirvana6:master

Conversation

@nirvana6

@nirvana6 nirvana6 commented Jul 3, 2026

Copy link
Copy Markdown

Problem

Carapace passes pre-quoted words to compadd with -Q, using double backslash escaping (path\\ file instead of path\ file). When fzf-tab's -ftb-compadd captures these words and re-inserts them with -Q, the double backslash is placed literally on the command line. Zsh parses \\ as a literal backslash followed by a word boundary, breaking paths with spaces into separate tokens.

Observed bug: completing a filename with spaces (e.g., 中文 文件.txt) via carapace-accelerated fzf-tab results in 中文\\ 文件.txt on the command line, which zsh treats as two separate words (中文\ + 文件.txt) instead of one.

Root Cause

In -ftb-compadd, the word from compadd arguments is stored as-is. When the original completer (carapace) uses -Q with double-backslash escaping, the stored word contains \\. On re-insertion via _fzf-tab-apply (which preserves -Q), the double backslash is treated as literal characters.

Fix

In -ftb-compadd, after capturing word=$__hits[i], strip one level of backslash quoting when -Q was present in the original compadd call:

(( ${_opts[(I)-Q]} )) && word=${word//\\\\/\\}

This converts \\\ (two literal backslashes to one), matching the format zsh expects for pre-quoted compadd -Q words.

Safety

  • Only activates when -Q is in the original args — native zsh completions (_files, _path_files) do not use -Q and are unaffected
  • Only affects carapace's double-backslash convention — correctly-quoted words (single \) contain no \\ sequence to match
  • File names with literal backslashes: if a path genuinely contains \ characters, carapace would escape them as \\\\ (4 backslashes). Stripping \\\ converts 4→2, preserving the correct escape level

Fixes #503

When carapace provides completions, it passes pre-quoted words to compadd
with -Q using double backslash escaping (e.g., "path\\ file" instead of
"path\ file"). fzf-tab's -ftb-compadd captures these words as-is, and
when re-inserted with -Q, the double backslash is treated literally by
zsh, causing paths with spaces to break into separate tokens.

Fix: when the original compadd call used -Q, strip one level of backslash
quoting from the captured word (\\ -> \), which is the format zsh expects
for pre-quoted compadd -Q words.

This fix only activates when -Q is present in the original args, so
native zsh completions (which do not use -Q) are unaffected.

Fixes: Aloxaf#503
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.

[Q] [carapace + fzf-tab] adds an extra backslash to file completion.

1 participant