Repository navigation
Fix fzf preview under non-POSIX login shells (e.g. fish) - #3
Conversation
|
Thanks for tracking this down. I am not an active fish user (and I did not think of the fish-as-login-shell scenario), so the report is appreciated. Direct {2..} interpolation is a good fix and I'll merge it once you've updated the PR. I think that it is principally preferable to keep the preview command free of shell-specific assignment syntax. E.g. debian/ubuntu still ships fzf 0.44 AFAIK so the Separately/alternatively, I'd still like to pin /bin/sh for the fzf call, since a future wrapper (nushell, for example) could hit the same problem (this also should resolve the environment leakage issue you mention). Proposed change: I tested it in fish with so that ze.sh then sees SHELL as fish on startup. so this approach also woul fix the issue (but your 'direct interpolation' variant still should be adopted in the first place). |
fzf runs --preview commands with $SHELL -c. ze.sh built the preview in
POSIX shell syntax (pathname={2..}; ...), so with fish as the login shell
the preview died before running:
fish: Unsupported use of '='. In fish, please use 'set pathname ...'
Two independent changes, per maintainer feedback:
* Interpolate the field placeholder directly ({2..}) instead of first
assigning it to a shell variable. fzf already single-quotes placeholder
expansions, so this is equivalent and keeps the preview free of any
shell-specific assignment syntax (works on any fzf, incl. Debian/Ubuntu
versions older than 0.48 that lack --with-shell).
* Pin SHELL=/bin/sh on both fzf calls, so the preview is spawned by a
POSIX shell regardless of the user's login shell. This also stops the
interactive shell's functions/aliases from leaking into the preview
(e.g. a fish 'ls' function wrapping eza, which rejects -C).
9ffda72 to
f6a7c5b
Compare
jghub
left a comment
There was a problem hiding this comment.
'preview' still needs to be declared to keep it local to the respective function.
Co-authored-by: jghub <jghub@users.noreply.github.com>
Co-authored-by: jghub <jghub@users.noreply.github.com>
Problem
With a non-POSIX login shell (e.g.
fish), the fzf preview pane fails immediately:Cause
_ze_findand_ze_digbuild the fzf--previewcommand in POSIX shell syntax (pathname={2..}; ...). fzf executes preview commands with$SHELL -c(fzf docs: "the default value is$SHELL -cif$SHELLis set, otherwisesh -c"). When$SHELLisfish, fish cannot parse a bareVAR=valueassignment, so the preview dies before the listing runs. The preview is spawned by fzf itself, so running ze.sh's logic under bash (as the fish wrapper does) does not help.Fix
Reworked per @jghub's feedback — two independent changes:
Interpolate the placeholder directly (
{2..}) instead of first assigning it to a shell variable. fzf already single-quotes placeholder expansions (this is the same quoting the oldpathname={2..}relied on), so the result is equivalent, but the preview command no longer contains any shell-specific assignment syntax. This keeps it working on any shell and on fzf versions older than 0.48 (Debian bookworm ships 0.38, Ubuntu 24.04 ships 0.44.1), where--with-shelldoes not exist.Pin
SHELL=/bin/shon both fzf calls, so the preview is always spawned by a POSIX shell regardless of the user's login shell. This also prevents the interactive shell's functions/aliases from leaking into the preview — e.g. a fishlsfunction wrappingeza, which rejects-Cand would otherwise break the preview even after the parse error is gone. It also future-proofs other wrappers (nushell, …).(and the analogous edits in
_ze_dig). The--with-shellapproach from the first revision is dropped, since pinningSHELLcovers it without the fzf >= 0.48 requirement.Verification
bash -n/zsh -n/ksh -n: OK/bin/shand lists the directory correctly ({2..}quoting intact).fish -c 'ze -f iris'andfish -c 'ze -d': noUnsupported use of '='and noeza-Cerrors._ZE_NO_FZF) unaffected.