fix(completer): wrap file preview in \sh -c\ for fish compatibility#3089
Open
EmojiPati wants to merge 1 commit intotailcallhq:mainfrom
Open
fix(completer): wrap file preview in \sh -c\ for fish compatibility#3089EmojiPati wants to merge 1 commit intotailcallhq:mainfrom
sh -c\ for fish compatibility#3089EmojiPati wants to merge 1 commit intotailcallhq:mainfrom
Conversation
fzf dispatches `--preview` commands through `$SHELL`, so when the user's login shell is fish the `@`-completion preview fails with "fish: Missing end to balance this if statement" — fish cannot parse the POSIX `if [ … ]; then … fi` body. Wrapping the script in `sh -c` makes the preview render under any non-POSIX login shell.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix the
@-completion file preview so it renders correctly when the user's login shell isfish(or any other non-POSIX shell).Context
fzfdispatches--previewcommands through$SHELL. The preview template emitted byInputCompleteris a POSIX shell snippet that usesif [ -d … ]; then … else … fito decide between a directory listing and abat/catrender. Underfish, evaluating that snippet fails with:Opening a
zshsession from a terminal does not fix this, becausefzfreads the$SHELLenvironment variable from the process it was spawned under, not the currently active shell. For users whose login shell isfish, the file preview pane stays broken even after switching shells.Changes
crates/forge_main/src/completer/input_completer.rs: wrap the preview script insh -c '…' _ {2}so the POSIX body is always evaluated byshregardless of$SHELL. The{2}placeholder (the path column of the fzf list) is forwarded positionally and read inside the script as"$1", preserving paths that contain whitespace or shell metacharacters.build_preview_cmdfunction and add two unit tests covering thebatandcatbranches.Key implementation details
"$1", so fzf's nativequoteEntryoutput (e.g.'path with space/file.rs') composes correctly without requiring any additional escaping from our side._as$0filler is the standard trick for invokingsh -c 'script' arg1where the first positional argument is the real input.Testing
cargo +nightly fmt --all -- --check cargo +nightly clippy --all-features --workspace --all-targets -- -D warnings cargo test -p forge_main --libManual verification on a
fishlogin shell:echo $SHELL→/usr/bin/fishforge, type@and start typing a filename.batoutput for files /ls -laoutput for directories, instead of thefish: Missing end to balance this if statementerror.