junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
61.96k stars 2.34k forks source link

Broken zsh shell integration on 0.51+ #3841

Closed ecanessa closed 3 weeks ago

ecanessa commented 1 month ago

Checklist

Output of fzf --version

0.53.0 (c4a9ccd)

OS

Shell

Problem / Steps to reproduce

Shell integration appears to be broken on early 5.x.x releases of zsh, starting from from fzf version 0.51.0.

I am using a locked system where zsh version cannot be changed:

% zsh --version
zsh 5.0.2 (x86_64-redhat-linux-gnu)
% ./fzf --version
0.53.0 (c4a9ccd)
% source <(./fzf --zsh)
% vi **<TAB>
vi **__fzf_generic_path_completion:export:23: not an identifier: 40%

The last fzf version which supports this version of zsh is 0.50.0 (f97d275).

LangLangBart commented 3 weeks ago

The last fzf version which supports this version of zsh is 0.50.0 (f97d275)

I believe the issue has been introduced through commit f864f8b5f7ab62e81fbf9eb2ac2333c7e52bb4e4.

I can confirm the problem occurs with any version up to 5.1, and the change was implemented in a commit^1, which introduced improved assignment handling in zsh for builtin commands such as export.

zsh-5.0.2 ❌

❯ ~/.local/zsh-test/bin/zsh-5.0.2 -fxvc 'export TEST=$(echo "--height 40% --reverse --scheme=path")'
+zsh:1> echo '--height 40% --reverse --scheme=path'
+zsh:1> export 'TEST=--height' 40% --reverse '--scheme=path'
zsh:export:1: not an identifier: 40%

zsh-5.1 ✅

❯ ~/.local/zsh-test/bin/zsh-5.1 -fxvc 'export TEST=$(echo "--height 40% --reverse --scheme=path")'
export TEST=$(echo "--height 40% --reverse --scheme=path")
+zsh:1> echo '--height 40% --reverse --scheme=path'
+zsh:1> export TEST='--height 40% --reverse --scheme=path'

Does splitting declaration and assignment solve the issue for you?

--- a/shell/completion.zsh
+++ b/shell/completion.zsh
@@ -158,5 +158,6 @@ __fzf_generic_path_completion() {
       [ "$dir" != "/" ] && dir="${dir/%\//}"
       matches=$(
-        export FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --scheme=path" "${FZF_COMPLETION_OPTS-}")
+        export FZF_DEFAULT_OPTS
+        FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --scheme=path" "${FZF_COMPLETION_OPTS-}")
         unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE
         if declare -f "$compgen" > /dev/null; then