__fzf_select() {
setopt localoptions pipefail no_aliases 2> /dev/null
local -a tokens
tokens=(${(z)LBUFFER})
local last_word=${tokens[-1]}
local selection
export FZF_CTRL_F_COMMAND=$(
if [[ "$(realpath .)" == "${HOME}" ]] && [[ -n "$last_word" && -e "$last_word" ]]; then
search_path="'$last_word'"
printf '%s' "fd . $search_path --color=always -HiL -d1 -E .histfile -E .git -E .gitignore"
elif [[ "$(realpath .)" == "${HOME}" ]]; then
printf '%s' "fd . --color=always -HiL -d1 -E .histfile -E .git -E .gitignore"
elif [[ -n "$last_word" && -e "$last_word" ]]; then
search_path="'$last_word'"
printf '%s' "fd . $search_path --color=always -HiL -d2 -E .histfile -E .git -E .gitignore"
else
printf '%s' "fd . --color=always -HiL -d2 -E .histfile -E .git -E .gitignore"
fi
)
if [[ -z "$last_word" ]] || [[ ${LBUFFER[-1]} == " " ]]; then
selection=$(eval ${FZF_CTRL_F_COMMAND} | fzf --preview='fzf_preview_wrapper {}')
else
selection=$(eval ${FZF_CTRL_F_COMMAND} | fzf --preview='fzf_preview_wrapper {}' --query "$last_word" | sed "s|$last_word||g")
fi
local ret=$?
return $ret
}
fzf-file-widget() {
__fzf_select
local ret=$?
zle reset-prompt
return $ret
}
if [[ "${FZF_CTRL_F_COMMAND-x}" != "" ]]; then
zle -N fzf-file-widget
bindkey -M vicmd '^F' fzf-file-widget
bindkey -M viins '^F' fzf-file-widget
fi
__fzlf() {
export FZF_CTRL_F_COMMAND=$(
if [[ "$(realpath .)" == "${HOME}" ]]; then
printf '%s' "fd . --color=always -HiL -d1 -E .histfile -E .git -E .gitignore"
else
printf '%s' "fd . --color=always -HiL -d2 -E .histfile -E .git -E .gitignore"
fi
)
FZF_DEFAULT_COMMAND="${FZF_CTRL_F_COMMAND}"
eval ${FZF_DEFAULT_COMMAND} |
fzf -m -d '/' --preview='fzf_preview_wrapper {}'
}
alias -g fzlf=__fzlf
alias -g fff="\
\$(\
fzlf\
)\
"