How can I escape special characters in bash with FZF? #3725
-
TARGET=some_program
target:
$(TARGET) This will error here when searching.
open_files() {
echo "args $*"
# Handel args here.
}
export -f open_files
RG_PREFIX="rg --follow --sortr=path --column --line-number --no-heading --color=always --smart-case "
INITIAL_QUERY="${*:-}"
DIRS=(".")
selected=$(
FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY") ${DIRS[*]}" \
fzf --ansi \
--color "hl:-1:underline,hl+:-1:underline:reverse" \
--disabled --query "$INITIAL_QUERY" \
--bind "change:reload:sleep 0.1; $RG_PREFIX {q} ${DIRS[*]} || true" \
--bind "ctrl-f:unbind(change,ctrl-f)+change-prompt(2. fzf> )+enable-search+clear-query" \
--bind 'enter:become(bash -c "open_files {+}">/dev/tty)+abort' \
--prompt '1. ripgrep> ' \
--multi \
--delimiter : \
--preview 'bat --color=always {1} --highlight-line {2}' \
--preview-window 'up,65%,border-bottom,+{2}+3/3,~3' \
--height "100%"
) You will get an error in fish or bash: fish: Unknown command: TARGET
fish:
TARGET
^~~~~^
in command substitution
fish: Unknown command
bash -c "open_files './Makefile:28:4: $(TARGET) This will error here when searching.'">/dev/tty |
Beta Was this translation helpful? Give feedback.
Answered by
LangLangBart
Apr 13, 2024
Replies: 1 comment 1 reply
-
When pressing ⏎ Enter, 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 - FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY") ${DIRS[*]}" \
+ SHELL="$(which bash)" FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY") ${DIRS[*]}" \ Then, update this line: - --bind 'enter:become(bash -c "open_files {+}">/dev/tty)+abort' \
+ --bind 'enter:become:open_files {+}>/dev/tty' \ # args ./Makefile:4:4: $(TARGET) This will error here when searching. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
rickalex21
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When pressing ⏎ Enter,
fzf
executes using$SHELL -c
. See also fzf's man page.Your command would be executed as follows:
To modify the
SHELL
variable, prependSHELL=$(which bash)
to yourfzf
command in the script: