From 8a732d457cc28150861144e322e65c21097620c1 Mon Sep 17 00:00:00 2001 From: Andrew Coleman Date: Fri, 16 Sep 2022 11:50:22 -0400 Subject: [PATCH] add fzf configuration to exclude git-ignored files --- dot_config/bash/fzf.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 dot_config/bash/fzf.sh diff --git a/dot_config/bash/fzf.sh b/dot_config/bash/fzf.sh new file mode 100644 index 0000000..152a399 --- /dev/null +++ b/dot_config/bash/fzf.sh @@ -0,0 +1,34 @@ +# Use ~~ as the trigger sequence instead of the default ** +export FZF_COMPLETION_TRIGGER='~~' + +# Options to fzf command +export FZF_COMPLETION_OPTS='--border --info=inline' +export FZF_DEFAULT_COMMAND='fd --type f --strip-cwd-prefix' + +# Use fd (https://github.com/sharkdp/fd) instead of the default find +# command for listing path candidates. +# - The first argument to the function ($1) is the base path to start traversal +# - See the source code (completion.{bash,zsh}) for the details. +_fzf_compgen_path() { + fd --hidden --follow --exclude ".git" . "$1" +} + +# Use fd to generate the list for directory completion +_fzf_compgen_dir() { + fd --type d --hidden --follow --exclude ".git" . "$1" +} + +# (EXPERIMENTAL) Advanced customization of fzf options via _fzf_comprun function +# - The first argument to the function is the name of the command. +# - You should make sure to pass the rest of the arguments to fzf. +_fzf_comprun() { + local command=$1 + shift + + case "$command" in + cd) fzf "$@" --preview 'tree -C {} | head -200' ;; + export|unset) fzf "$@" --preview "eval 'echo \$'{}" ;; + ssh) fzf "$@" --preview 'dig {}' ;; + *) fzf "$@" ;; + esac +}