[bash-completion] Add _fzf_setup_completion to enable fuzzy completion

While we can attach `_fzf_path_completion` or `_fzf_dir_completion` to
any command using the standard bash complete command, the functionality
of the existing completion function is lost.

Use _fzf_setup_completion if you want to extend the existing function
with fuzzy completion instead of completely replacing it.

e.g. _fzf_setup_completion path kubectl
This commit is contained in:
Junegunn Choi 2019-08-08 15:35:52 +09:00
parent 4800e5d2ae
commit 5095899245
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -333,4 +333,18 @@ complete -F _fzf_complete_unalias -o default -o bashdefault unalias
unset cmd d_cmds a_cmds x_cmds
_fzf_setup_completion() {
local fn cmd
if [[ $# -lt 2 ]] || ! type -t _fzf_${1}_completion > /dev/null; then
echo "usage: ${FUNCNAME[0]} path|dir COMMANDS..."
return 1
fi
fn=_fzf_${1}_completion
shift
for cmd in "$@"; do
eval "$(complete -p "$cmd" 2> /dev/null | grep -v "$fn" | __fzf_orig_completion_filter)"
complete -F "$fn" -o default -o bashdefault "$cmd"
done
}
fi