Skip to content
Myr

[bash-completion] Retain original completion options (#288)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent b3010a4 · Browse files · 1 file+26 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+26 added−10 removed

  • other:+26 added−10 removed

1 file+26 added−10 removed

modified:shell/completion.bash+26 added-10 removed
9 unmodified lines
10# - $FZF_COMPLETION_TRIGGER (default: '**')11# - $FZF_COMPLETION_OPTS (default: empty)1213_fzf_orig_completion_filter() {14 sed 's/.*-F *\([^ ]*\).* \([^ ]*\)$/export _fzf_orig_completion_\2=\1;/' |15 sed 's/[^a-z0-9_= ;]/_/g'14 sed 's/^\(.*-F\) *\([^ ]*\).* \([^ ]*\)$/export _fzf_orig_completion_\3="\1 %s \3 #\2";/' |15 awk -F= '{gsub(/[^a-z0-9_= ;]/, "_", $1); print $1"="$2}'16}1718_fzf_opts_completion() {19 local cur prev opts
56 unmodified lines
76 return 077}7879_fzf_handle_dynamic_completion() {80 local cmd orig ret orig_cmd80 local cmd orig_var orig ret orig_cmd81 cmd="$1"82 shift83 orig_cmd="$1"8485 orig=$(eval "echo \$_fzf_orig_completion_$cmd")84 orig_var="_fzf_orig_completion_$cmd"85 orig="${!orig_var##*#}"86 if [ -n "$orig" ] && type "$orig" > /dev/null 2>&1; then87 $orig "$@"88 elif [ -n "$_fzf_completion_loader" ]; then89 _completion_loader "$@"
161 unmodified lines
251 svn tar unzip zip"252x_cmds="kill ssh telnet unset unalias export"253254# Preserve existing completion255if [ "$_fzf_completion_loaded" != '0.9.12' ]; then255if [ "$_fzf_completion_loaded" != '0.10.8' ]; then256 # Really wish I could use associative array but OSX comes with bash 3.2 :(257 eval $(complete | \grep '\-F' | \grep -v _fzf_ |258 \grep -E " ($(echo $d_cmds $f_cmds $a_cmds $x_cmds | sed 's/ /|/g' | sed 's/+/\\+/g'))$" | _fzf_orig_completion_filter)259 export _fzf_completion_loaded=0.9.12259 export _fzf_completion_loaded=0.10.8260fi261262if type _completion_loader > /dev/null 2>&1; then263 _fzf_completion_loader=1264fi265266_fzf_defc() {267 local cmd func opts orig_var orig268 cmd="$1"269 func="$2"270 opts="$3"271 orig_var="_fzf_orig_completion_$cmd"272 orig="${!orig_var}"273 if [ -n "$orig" ]; then274 eval "$(printf "$orig" "$func")"275 else276 complete -F "$func" $opts "$cmd"277 fi278}279280# Directory281for cmd in $d_cmds; do268 complete -F _fzf_dir_completion -o nospace -o plusdirs $cmd282 _fzf_defc "$cmd" _fzf_dir_completion "-o nospace -o plusdirs"283done284285# File286for cmd in $f_cmds; do273 complete -F _fzf_file_completion -o default -o bashdefault $cmd287 _fzf_defc "$cmd" _fzf_file_completion "-o default -o bashdefault"288done289290# Anything291for cmd in $a_cmds; do278 complete -F _fzf_path_completion -o default -o bashdefault $cmd292 _fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault"293done294295unset _fzf_defc296297# Kill completion298complete -F _fzf_complete_kill -o nospace -o default -o bashdefault kill299300# Host completion
9 unmodified lines