Skip to content

Commit

Permalink
[bash-completion] _fzf_setup_completion to retain previous options
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Aug 9, 2019
1 parent 5095899 commit 5c7dcaf
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions shell/completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ if type _completion_loader > /dev/null 2>&1; then
_fzf_completion_loader=1
fi
_fzf_defc() {
__fzf_defc() {
local cmd func opts orig_var orig def
cmd="$1"
func="$2"
Expand All @@ -309,16 +309,14 @@ _fzf_defc() {
# Anything
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
# Directory
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
unset _fzf_defc
# Kill completion
complete -F _fzf_complete_kill -o nospace -o default -o bashdefault kill
Expand All @@ -334,16 +332,20 @@ 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
local kind fn cmd
kind=$1
fn=_fzf_${1}_completion
if [[ $# -lt 2 ]] || ! type -t "$fn" > /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"
case "$kind" in
dir) __fzf_defc "$cmd" "$fn" "-o nospace -o dirnames" ;;
*) __fzf_defc "$cmd" "$fn" "-o default -o bashdefault" ;;
esac
done
}
Expand Down

0 comments on commit 5c7dcaf

Please sign in to comment.