From 50958992455708f4a9ec82f745f7496fbca243c7 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 8 Aug 2019 15:35:52 +0900 Subject: [PATCH] [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 --- shell/completion.bash | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/shell/completion.bash b/shell/completion.bash index 2964829..1bedb43 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -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