fzf single button data source toggling in bash environment variable but in a variable function execution declatation #3663
-
I've found this fzf snippet that allows fzf to toggle between directory and path's querry and I'm basically trying to make it work for pasting command but I assume all or some of the Basically I'm trying to make this work, got stuck at the source toggling functionality export MY_FZF_OPTS="
--header 'CTRL-T: Switch between Files/Directories'
--bind 'ctrl-d:change-prompt(Directories> )+reload(find * -type d)'
--bind 'ctrl-f:change-prompt(Files> )+reload(find * -type f)'
--bind 'ctrl-y:execute-silent(echo -n {1..} | xclip -se c)'
--bind 'ctrl-t:transform:[[ ! $FZF_PROMPT =~ Files ]] && echo [change-prompt(Files> )+reload(fd --type file --hidden 2>/dev/null)] ||
echo [change-prompt(Dirs > )+reload(fd --type directory --hidden 2>/dev/null)]
--preview '[[ $FZF_PROMPT =~ Files ]] && bat --color=always {} || tree -C {}'
"
myFzf1() {
READLINE_LINE_NEW="$(fd --type file --hidden 2>/dev/null | FZF_DEFAULT_OPTS="$MY_FZF_OPTS" $(__fzfcmd) )"
echo "$MY_FZF_OPTS" # For debugging
if
[[ -n $READLINE_LINE_NEW ]]
then
builtin bind '"\er": redraw-current-line'
builtin bind '"\e^": magic-space'
READLINE_LINE=${READLINE_LINE:+${READLINE_LINE:0:READLINE_POINT}}${READLINE_LINE_NEW}${READLINE_LINE:+${READLINE_LINE:READLINE_POINT}}
READLINE_POINT=$(( READLINE_POINT + ${#READLINE_LINE_NEW} ))
else
builtin bind '"\er":'
builtin bind '"\e^":'
fi
} Any idea how to make it work? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
In your case, you need to escape the # example with surrounding double quotes
export MY_FZF_OPTS="
--preview '[[ \$FZF_PROMPT =~ Files ]] && bat --color=always {} || tree -C {}'
"
# example with surrounding single quotes
export MY_FZF_OPTS='
--preview "[[ $FZF_PROMPT =~ Files ]] && bat --color=always {} || tree -C {}"
' Furthermore, your Further the parts following the 'echo' command also need to be quoted and need to be escaped3. You should also set a default prompt, because of your export MY_FZF_OPTS='
--ansi
--header "CTRL-T: Switch between Files/Directories"
--bind "ctrl-y:execute-silent(echo -n {} | xclip -se c)"
--bind "ctrl-t:transform:[[ ! $FZF_PROMPT =~ Files ]] &&
echo \"change-prompt(Files> )+reload(fd --type file --hidden)\" ||
echo \"change-prompt(Dirs > )+reload(fd --type directory --hidden)\""
--preview "[[ $FZF_PROMPT =~ Files ]] && bat --color=always {} || tree -C {}"
--prompt "Files >"
' Footnotes |
Beta Was this translation helpful? Give feedback.
set -x
12 is powerful for debugging as it prints commands and their arguments as they areexecuted, allowing you to chip away parts of your code until you find the bug yourself.
In your case, you need to escape the
$FZF_PROMPT
because the surrounding quotes are double quotes.Fur…