Skip to content

How can I escape special characters in bash with FZF? #3725

Closed Answered by LangLangBart
rickalex21 asked this question in Q&A
Discussion options

You must be logged in to vote

When pressing ⏎ Enter, fzf executes using $SHELL -c. See also fzf's man page.

man fzf | less --pattern 'fzf runs the command with'
echo $SHELL
# /usr/local/bin/fish

Your command would be executed as follows:

/usr/local/bin/fish -c 'bash -c "open_files ./Makefile:4:4:$(TARGET) This will error here when searching.">/dev/tty'
# fish: Unknown command: TARGET
# fish:
# TARGET
# ^~~~~^
# in command substitution
# fish: Unknown command
# bash -c "open_files ./Makefile:4:4:$(TARGET) This will error here when searching.">/dev/tty

To modify the SHELL variable, prepend SHELL=$(which bash) to your fzf command in the script:

- FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY") ${DIRS[*]}" \
+

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rickalex21
Comment options

Answer selected by rickalex21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants