if [[ -z "$FZF_DEFAULT_COMMAND" ]]; then if (( $+commands[fd] )); then export FZF_DEFAULT_COMMAND='fd --type f --hidden --exclude .git' elif (( $+commands[rg] )); then export FZF_DEFAULT_COMMAND='rg --files --hidden --glob "!.git/*"' elif (( $+commands[ag] )); then export FZF_DEFAULT_COMMAND='ag -l --hidden -g "" --ignore .git' fi fi # alt-f to search files with fzf function fzf-file-widget() { local selected_file local command_to_run="$FZF_DEFAULT_COMMAND | fzf" selected_file=$(eval $command_to_run) LBUFFER+="$selected_file" } # alt-f to trigger file search zle -N fzf-file-widget bindkey '\ef' fzf-file-widget # alt-d to search directories with fzf function fzf-directory-widget() { local selected_dir local command_to_run if (( $+commands[fd] )); then command_to_run="fd --type d --hidden --no-ignore --exclude .git | fzf" else command_to_run='find . -type d | fzf' fi selected_dir=$(eval $command_to_run) LBUFFER+="$selected_dir" } # alt-d to trigger directory search zle -N fzf-directory-widget bindkey '\ed' fzf-directory-widget # alt-h to search command history with fzf function fzf-history-widget() { local selected_command selected_command=$(fc -frl 1 | fzf | awk '{$1=$2=$3=""; gsub(/^ +/, ""); print}') LBUFFER+="$selected_command" } # alt-h to trigger history search zle -N fzf-history-widget bindkey '\eh' fzf-history-widget