Possible to use alias/function for the shells used by fzf? #3993
-
I have the following bash shell script (I would like to convert to a zsh shell function):
Here it relies on |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
yes. shell script - what is the zsh equivalent of bash's export -f - Unix & Linux Stack Exchange Most common is to store the function in a variable name. cmd='fd -t d --hidden --no-ignore --follow --ignore-file "$HOME/.config/fd/ignore" --ignore-file "$HOME/.config/fd/cd-fzf.fdignore" .'
selection=$(fzf --preview 'tree -C {}' \
--prompt 'Dirs > ' \
--bind "start:reload:$cmd '$HOME' /etc /media /data /data2" \
--bind "ctrl-r:transform:[[ ! \$FZF_PROMPT == 'Dirs > ' ]] &&
echo \"change-prompt(Dirs > )+reload($cmd '$HOME' /etc /media /data /data2)\" ||
echo \"change-prompt(Dirs (media excluded) > )+reload($cmd /etc '$HOME/dev')\"")
if [ -n "$selection" ]; then
cd "$selection" && n "$selection"
fi PRO
CONTRA
Another way is using # Define a function in your "${ZDOTDIR:-$HOME}/.zshenv"
random_word() {
perl -e 'srand; rand($.) < 1 && ($line = $_) while <>; print $line;' "${1:-/usr/share/dict/words}"
} # this works, it will find the function
fzf --bind "start:reload:random_word" --preview 'typeset -f'
# this won't work, the function will not be found; the '--with-shell' flag came with '0.51.0' (see CHANGELOG.md)
fzf --bind "start:reload:random_word" --preview 'typeset -f' --with-shell 'zsh --no-rcs -c' PRO
CONTRA
Footnotes |
Beta Was this translation helpful? Give feedback.
yes.
shell script - what is the zsh equivalent of bash's export -f - Unix & Linux Stack Exchange
Most common is to store the function in a variable name.