[bash-completion] _fzf_setup_completion to retain previous options

This commit is contained in:
Junegunn Choi 2019-08-09 11:11:29 +09:00
parent 5095899245
commit 5c7dcaffe8
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -292,7 +292,7 @@ if type _completion_loader > /dev/null 2>&1; then
_fzf_completion_loader=1 _fzf_completion_loader=1
fi fi
_fzf_defc() { __fzf_defc() {
local cmd func opts orig_var orig def local cmd func opts orig_var orig def
cmd="$1" cmd="$1"
func="$2" func="$2"
@ -309,16 +309,14 @@ _fzf_defc() {
# Anything # Anything
for cmd in $a_cmds; do for cmd in $a_cmds; do
_fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault" __fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault"
done done
# Directory # Directory
for cmd in $d_cmds; do for cmd in $d_cmds; do
_fzf_defc "$cmd" _fzf_dir_completion "-o nospace -o dirnames" __fzf_defc "$cmd" _fzf_dir_completion "-o nospace -o dirnames"
done done
unset _fzf_defc
# Kill completion # Kill completion
complete -F _fzf_complete_kill -o nospace -o default -o bashdefault kill complete -F _fzf_complete_kill -o nospace -o default -o bashdefault kill
@ -334,16 +332,20 @@ complete -F _fzf_complete_unalias -o default -o bashdefault unalias
unset cmd d_cmds a_cmds x_cmds unset cmd d_cmds a_cmds x_cmds
_fzf_setup_completion() { _fzf_setup_completion() {
local fn cmd local kind fn cmd
if [[ $# -lt 2 ]] || ! type -t _fzf_${1}_completion > /dev/null; then kind=$1
fn=_fzf_${1}_completion
if [[ $# -lt 2 ]] || ! type -t "$fn" > /dev/null; then
echo "usage: ${FUNCNAME[0]} path|dir COMMANDS..." echo "usage: ${FUNCNAME[0]} path|dir COMMANDS..."
return 1 return 1
fi fi
fn=_fzf_${1}_completion
shift shift
for cmd in "$@"; do for cmd in "$@"; do
eval "$(complete -p "$cmd" 2> /dev/null | grep -v "$fn" | __fzf_orig_completion_filter)" eval "$(complete -p "$cmd" 2> /dev/null | grep -v "$fn" | __fzf_orig_completion_filter)"
complete -F "$fn" -o default -o bashdefault "$cmd" case "$kind" in
dir) __fzf_defc "$cmd" "$fn" "-o nospace -o dirnames" ;;
*) __fzf_defc "$cmd" "$fn" "-o default -o bashdefault" ;;
esac
done done
} }