Skip to content
Myr

completion.bash

This file

Path

shell/completion.bash

740 lines · 21.2 KiB · Shell

Last changed by

Remove deprecated FZF_TMUX vars from shell script headersJunegunn Choibefore adoption57695b0

History of this file

Take it

The walk stopped after 200 commits: lines older than 7a811f0 point at it.

Fix --no-sort jumpiness by merging results in index orderJunegunn Choibefore adoption7a811f0

lines 1–161why, one step back
1# ____ ____
2# / __/___ / __/3# / /_/_ / / /_4# / __/ / /_/ __/5# /_/ /___/_/ completion.bash6#7# - $FZF_COMPLETION_TRIGGER (default: '**')8# - $FZF_COMPLETION_OPTS (default: empty)9# - $FZF_COMPLETION_PATH_OPTS (default: empty)10# - $FZF_COMPLETION_DIR_OPTS (default: empty)1112if [[ $- =~ i ]]; then131415# To use custom commands instead of find, override _fzf_compgen_{path,dir}16#17# _fzf_compgen_path() {18# echo "$1"19# command find -L "$1" \20# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \21# -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'22# }23#24# _fzf_compgen_dir() {25# command find -L "$1" \26# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o -type d \27# -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'28# }2930###########################################################3132#----BEGIN shfmt33#----BEGIN INCLUDE common.sh34# NOTE: Do not directly edit this section, which is copied from "common.sh".35# To modify it, one can edit "common.sh" and run "./update.sh" to apply36# the changes. See code comments in "common.sh" for the implementation details.3738__fzf_defaults() {39 builtin printf '%s\n' "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"40 command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null41 builtin printf '%s\n' "${FZF_DEFAULT_OPTS-} $2"42}4344__fzf_exec_awk() {45 if [[ -z ${__fzf_awk-} ]]; then46 __fzf_awk=awk47 if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then48 __fzf_awk=/usr/xpg4/bin/awk49 elif command -v mawk > /dev/null 2>&1; then50 local n x y z d51 IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)52 [[ $n == mawk ]] &&53 (((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&54 ((d >= 20230302)) 2> /dev/null &&55 __fzf_awk=mawk56 fi57 fi58 LC_ALL=C exec "$__fzf_awk" "$@"59}60#----END INCLUDE6162__fzf_comprun() {63 if [[ "$(type -t _fzf_comprun 2>&1)" == function ]]; then64 _fzf_comprun "$@"65 elif [[ -n ${TMUX_PANE-} ]] && { [[ ${FZF_TMUX:-0} != 0 ]] || [[ -n ${FZF_TMUX_OPTS-} ]]; }; then66 shift67 fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- "$@"68 else69 shift70 fzf "$@"71 fi72}7374__fzf_orig_completion() {75 local l comp f cmd76 while read -r l; do77 if [[ $l =~ ^(.*\ -F)\ *([^ ]*).*\ ([^ ]*)$ ]]; then78 comp="${BASH_REMATCH[1]}"79 f="${BASH_REMATCH[2]}"80 cmd="${BASH_REMATCH[3]}"81 [[ $f == _fzf_* ]] && continue82 builtin printf -v "_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}" "%s" "${comp} %s ${cmd} #${f}"83 if [[ $l == *" -o nospace "* ]] && [[ ${__fzf_nospace_commands-} != *" $cmd "* ]]; then84 __fzf_nospace_commands="${__fzf_nospace_commands-} $cmd "85 fi86 fi87 done88}8990# @param $1 cmd - Command name for which the original completion is searched91# @var[out] REPLY - Original function name is returned92__fzf_orig_completion_get_orig_func() {93 local cmd orig_var orig94 cmd=$195 orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"96 orig="${!orig_var-}"97 REPLY="${orig##*#}"98 [[ $REPLY ]] && type "$REPLY" &> /dev/null99}100101# @param $1 cmd - Command name for which the original completion is searched102# @param $2 func - Fzf's completion function to replace the original function103# @var[out] REPLY - Completion setting is returned as a string to "eval"104__fzf_orig_completion_instantiate() {105 local cmd func orig_var orig106 cmd=$1107 func=$2108 orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"109 orig="${!orig_var-}"110 orig="${orig%#*}"111 [[ $orig == *' %s '* ]] || return 1112 builtin printf -v REPLY "$orig" "$func"113}114115_fzf_opts_completion() {116 local cur prev opts117 COMPREPLY=()118 cur="${COMP_WORDS[COMP_CWORD]}"119 prev="${COMP_WORDS[COMP_CWORD - 1]}"120 opts="121 +c --no-color122 +i --no-ignore-case123 +s --no-sort124 +x --no-extended125 --accept-nth126 --ansi127 --bash128 --bind129 --border130 --border-label131 --border-label-pos132 --color133 --cycle134 --disabled135 --ellipsis136 --expect137 --filepath-word138 --fish139 --footer140 --footer-border141 --footer-label142 --footer-label-pos143 --freeze-left144 --freeze-right145 --gap146 --gap-line147 --ghost148 --gutter149 --gutter-raw150 --header151 --header-border152 --header-first153 --header-label154 --header-label-pos155 --header-lines156 --header-lines-border157 --height158 --highlight-line159 --history160 --history-size161 --hscroll-off

Add --id-nth to bash option completionJunegunn Choibefore adoptioncf57950

line 162why, one step back
162 --id-nth

Fix --no-sort jumpiness by merging results in index orderJunegunn Choibefore adoption7a811f0

lines 163–740why, one step back
163 --info
164 --info-command165 --input-border166 --input-label167 --input-label-pos168 --jump-labels169 --keep-right170 --layout171 --listen172 --listen-unsafe173 --list-border174 --list-label175 --list-label-pos176 --literal177 --man178 --margin179 --marker180 --marker-multi-line181 --min-height182 --no-bold183 --no-hscroll184 --no-input185 --no-multi-line186 --no-scrollbar187 --no-separator188 --padding189 --pointer190 --preview191 --preview-border192 --preview-label193 --preview-label-pos194 --preview-window195 --print-query196 --print0197 --prompt198 --raw199 --read0200 --scheme201 --scroll-off202 --scrollbar203 --separator204 --smart-case205 --style206 --sync207 --tabstop208 --tac209 --tail210 --tiebreak211 --tmux212 --track213 --version214 --walker215 --walker-root216 --walker-skip217 --with-nth218 --with-shell219 --wrap220 --wrap-sign221 --preview-wrap-sign222 --zsh223 -0 --exit-0224 -1 --select-1225 -d --delimiter226 -e --exact227 -f --filter228 -h --help229 -i --ignore-case230 -m --multi231 -n --nth232 -q --query233 --"234235 case "${prev}" in236 --scheme)237 COMPREPLY=($(compgen -W "default path history" -- "$cur"))238 return 0239 ;;240 --tiebreak)241 COMPREPLY=($(compgen -W "length chunk pathname begin end index" -- "$cur"))242 return 0243 ;;244 --color)245 COMPREPLY=($(compgen -W "dark light base16 16 bw no" -- "$cur"))246 return 0247 ;;248 --layout)249 COMPREPLY=($(compgen -W "default reverse reverse-list" -- "$cur"))250 return 0251 ;;252 --info)253 COMPREPLY=($(compgen -W "default right hidden inline inline-right" -- "$cur"))254 return 0255 ;;256 --wrap)257 COMPREPLY=($(compgen -W "char word" -- "$cur"))258 return 0259 ;;260 --style)261 COMPREPLY=($(compgen -W "default minimal full" -- "$cur"))262 return 0263 ;;264 --preview-window)265 COMPREPLY=($(compgen -W "266 default267 hidden268 nohidden269 wrap270 wrap-word271 nowrap272 cycle273 nocycle274 up top275 down bottom276 left277 right278 rounded border border-rounded279 border-line280 sharp border-sharp281 border-bold282 border-block283 border-thinblock284 border-double285 noborder border-none286 border-horizontal287 border-vertical288 border-up border-top289 border-down border-bottom290 border-left291 border-right292 follow293 nofollow294 info295 noinfo" -- "$cur"))296 return 0297 ;;298 --border | --list-border | --header-border | --header-lines-border | --footer-border | --input-border | --preview-border)299 COMPREPLY=($(compgen -W "line rounded sharp bold block thinblock double horizontal vertical top bottom left right none" -- "$cur"))300 return 0301 ;;302 --border-label-pos | --preview-label-pos | --list-label-pos | --header-label-pos | --footer-label-pos | --input-label-pos)303 COMPREPLY=($(compgen -W "center bottom top" -- "$cur"))304 return 0305 ;;306 esac307308 if [[ $cur =~ ^-|\+ ]]; then309 COMPREPLY=($(compgen -W "${opts}" -- "$cur"))310 return 0311 fi312313 return 0314}315316_fzf_handle_dynamic_completion() {317 local cmd ret REPLY orig_cmd orig_complete318 cmd="$1"319 shift320 orig_cmd="$1"321 if __fzf_orig_completion_get_orig_func "$cmd"; then322 "$REPLY" "$@"323 elif [[ -n ${_fzf_completion_loader-} ]]; then324 orig_complete=$(complete -p "$orig_cmd" 2> /dev/null)325 $_fzf_completion_loader "$@"326 ret=$?327 # _completion_loader may not have updated completion for the command328 if [[ "$(complete -p "$orig_cmd" 2> /dev/null)" != "$orig_complete" ]]; then329 __fzf_orig_completion < <(complete -p "$orig_cmd" 2> /dev/null)330 __fzf_orig_completion_get_orig_func "$cmd" || ret=1331332 # Update orig_complete by _fzf_orig_completion entry333 [[ $orig_complete =~ ' -F '(_fzf_[^ ]+)' ' ]] &&334 __fzf_orig_completion_instantiate "$cmd" "${BASH_REMATCH[1]}" &&335 orig_complete=$REPLY336337 if [[ ${__fzf_nospace_commands-} == *" $orig_cmd "* ]]; then338 eval "${orig_complete/ -F / -o nospace -F }"339 else340 eval "$orig_complete"341 fi342 fi343 [[ $ret -eq 0 ]] && return 124344 return $ret345 fi346}347348__fzf_generic_path_completion() {349 local cur base dir leftover matches trigger cmd350 cmd="${COMP_WORDS[0]}"351 if [[ $cmd == \\* ]]; then352 cmd="${cmd:1}"353 fi354 COMPREPLY=()355 trigger=${FZF_COMPLETION_TRIGGER-'**'}356 [[ $COMP_CWORD -ge 0 ]] && cur="${COMP_WORDS[COMP_CWORD]}"357 if [[ $cur == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then358 base=${cur:0:${#cur}-${#trigger}}359 eval "base=$base" 2> /dev/null || return360361 dir=362 [[ $base == *"/"* ]] && dir="$base"363 while true; do364 if [[ -z $dir ]] || [[ -d $dir ]]; then365 leftover=${base/#"$dir"/}366 leftover=${leftover/#\//}367 [[ -z $dir ]] && dir='.'368 [[ $dir != "/" ]] && dir="${dir/%\//}"369 matches=$(370 export FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --scheme=path" "${FZF_COMPLETION_OPTS-} $2")371 unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE372 if [[ $1 =~ dir ]]; then373 eval "rest=(${FZF_COMPLETION_DIR_OPTS-})"374 else375 eval "rest=(${FZF_COMPLETION_PATH_OPTS-})"376 fi377 if declare -F "$1" > /dev/null; then378 eval "$1 $(builtin printf %q "$dir")" | __fzf_comprun "$4" -q "$leftover" "${rest[@]}"379 else380 if [[ $1 =~ dir ]]; then381 walker=dir,follow382 else383 walker=file,dir,follow,hidden384 fi385 __fzf_comprun "$4" -q "$leftover" --walker "$walker" --walker-root="$dir" "${rest[@]}"386 fi | while read -r item; do387 builtin printf "%q " "${item%$3}$3"388 done389 )390 matches=${matches% }391 [[ -z $3 ]] && [[ ${__fzf_nospace_commands-} == *" ${COMP_WORDS[0]} "* ]] && matches="$matches "392 if [[ -n $matches ]]; then393 COMPREPLY=("$matches")394 else395 COMPREPLY=("$cur")396 fi397 # To redraw line after fzf closes (builtin printf '\e[5n')398 bind '"\e[0n": redraw-current-line' 2> /dev/null399 builtin printf '\e[5n'400 return 0401 fi402 dir=$(command dirname "$dir")403 [[ $dir =~ /$ ]] || dir="$dir"/404 done405 else406 shift407 shift408 shift409 _fzf_handle_dynamic_completion "$cmd" "$@"410 fi411}412413_fzf_complete() {414 # Split arguments around --415 local args rest str_arg i sep416 args=("$@")417 sep=418 for i in "${!args[@]}"; do419 if [[ ${args[$i]} == -- ]]; then420 sep=$i421 break422 fi423 done424 if [[ -n $sep ]]; then425 str_arg=426 rest=("${args[@]:$((sep + 1)):${#args[@]}}")427 args=("${args[@]:0:sep}")428 else429 str_arg=$1430 args=()431 shift432 rest=("$@")433 fi434435 local cur selected trigger cmd post436 post="$(caller 0 | __fzf_exec_awk '{print $2}')_post"437 type -t "$post" > /dev/null 2>&1 || post='command cat'438439 trigger=${FZF_COMPLETION_TRIGGER-'**'}440 cmd="${COMP_WORDS[0]}"441 cur="${COMP_WORDS[COMP_CWORD]}"442 if [[ $cur == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then443 cur=${cur:0:${#cur}-${#trigger}}444445 selected=$(446 FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse" "${FZF_COMPLETION_OPTS-} $str_arg") \447 FZF_DEFAULT_OPTS_FILE='' \448 __fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | eval "$post" | command tr '\n' ' '449 )450 selected=${selected% } # Strip trailing space not to repeat "-o nospace"451 if [[ -n $selected ]]; then452 COMPREPLY=("$selected")453 else454 COMPREPLY=("$cur")455 fi456 bind '"\e[0n": redraw-current-line' 2> /dev/null457 builtin printf '\e[5n'458 return 0459 else460 _fzf_handle_dynamic_completion "$cmd" "${rest[@]}"461 fi462}463464_fzf_path_completion() {465 __fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"466}467468# Deprecated. No file only completion.469_fzf_file_completion() {470 _fzf_path_completion "$@"471}472473_fzf_dir_completion() {474 __fzf_generic_path_completion _fzf_compgen_dir "" "/" "$@"475}476477_fzf_complete_kill() {478 _fzf_proc_completion "$@"479}480481_fzf_proc_completion() {482 local transformer483 transformer='484 if [[ $FZF_KEY =~ ctrl|alt|shift ]] && [[ -n $FZF_NTH ]]; then485 nths=( ${FZF_NTH//,/ } )486 new_nths=()487 found=0488 for nth in ${nths[@]}; do489 if [[ $nth = $FZF_CLICK_HEADER_NTH ]]; then490 found=1491 else492 new_nths+=($nth)493 fi494 done495 [[ $found = 0 ]] && new_nths+=($FZF_CLICK_HEADER_NTH)496 new_nths=${new_nths[*]}497 new_nths=${new_nths// /,}498 echo "change-nth($new_nths)+change-prompt($new_nths> )"499 else500 if [[ $FZF_NTH = $FZF_CLICK_HEADER_NTH ]]; then501 echo "change-nth()+change-prompt(> )"502 else503 echo "change-nth($FZF_CLICK_HEADER_NTH)+change-prompt($FZF_CLICK_HEADER_WORD> )"504 fi505 fi506 '507 _fzf_complete -m --header-lines=1 --no-preview --wrap --color fg:dim,nth:regular \508 --bind "click-header:transform:$transformer" -- "$@" < <(509 command ps -eo user,pid,ppid,start,time,command 2> /dev/null ||510 command ps -eo user,pid,ppid,time,args 2> /dev/null || # For BusyBox511 command ps --everyone --full --windows # For cygwin512 )513}514515_fzf_proc_completion_post() {516 __fzf_exec_awk '{print $2}'517}518519# To use custom hostname lists, override __fzf_list_hosts.520# The function is expected to print hostnames, one per line as well as in the521# desired sorting and with any duplicates removed, to standard output.522#523# e.g.524# # Use bash-completions’s _known_hosts_real() for getting the list of hosts525# __fzf_list_hosts() {526# # Set the local attribute for any non-local variable that is set by _known_hosts_real()527# local COMPREPLY=()528# _known_hosts_real ''529# builtin printf '%s\n' "${COMPREPLY[@]}" | command sort -u --version-sort530# }531if ! declare -F __fzf_list_hosts > /dev/null; then532 __fzf_list_hosts() {533 command sort -u \534 <(535 # Note: To make the pathname expansion of "~/.ssh/config.d/*" work536 # properly, we need to adjust the related shell options. We need to537 # unset "set -f" and "GLOBIGNORE", which disable the pathname expansion538 # totally or partially. We need to unset "dotglob" and "nocaseglob" to539 # avoid matching unwanted files. We need to unset "failglob" to avoid540 # outputting the error messages to the terminal when no matching is541 # found. We need to set "nullglob" to avoid attempting to read the542 # literal filename '~/.ssh/config.d/*' when no matching is found.543 set +f544 GLOBIGNORE=545 shopt -u dotglob nocaseglob failglob546 shopt -s nullglob547548 __fzf_exec_awk '549 # Note: mawk <= 1.3.3-20090705 does not support the POSIX brackets of550 # the form [[:blank:]], and Ubuntu 18.04 LTS still uses this551 # 16-year-old mawk unfortunately. We need to use [ \t] instead.552 match(tolower($0), /^[ \t]*host(name)?[ \t]*[ \t=]/) {553 $0 = substr($0, RLENGTH + 1) # Remove "Host(name)?=?"554 sub(/#.*/, "")555 for (i = 1; i <= NF; i++)556 if ($i !~ /[*?%]/)557 print $i558 }559 ' ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null560 ) \561 <(562 __fzf_exec_awk -F ',' '563 match($0, /^[][a-zA-Z0-9.,:-]+/) {564 $0 = substr($0, 1, RLENGTH)565 gsub(/[][]|:[^,]*/, "")566 for (i = 1; i <= NF; i++)567 print $i568 }569 ' ~/.ssh/known_hosts 2> /dev/null570 ) \571 <(572 __fzf_exec_awk '573 {574 sub(/#.*/, "")575 for (i = 2; i <= NF; i++)576 if ($i != "0.0.0.0")577 print $i578 }579 ' /etc/hosts 2> /dev/null580 )581 }582fi583584_fzf_host_completion() {585 _fzf_complete +m -- "$@" < <(__fzf_list_hosts)586}587588# Values for $1 $2 $3 are described here589# https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html590# > the first argument ($1) is the name of the command whose arguments are being completed,591# > the second argument ($2) is the word being completed,592# > and the third argument ($3) is the word preceding the word being completed on the current command line.593_fzf_complete_ssh() {594 case $3 in595 -i | -F | -E)596 _fzf_path_completion "$@"597 ;;598 *)599 local user=600 [[ $2 =~ '@' ]] && user="${2%%@*}@"601 _fzf_complete +m -- "$@" < <(__fzf_list_hosts | __fzf_exec_awk -v user="$user" '{print user $0}')602 ;;603 esac604}605606_fzf_var_completion() {607 _fzf_complete -m -- "$@" < <(608 declare -xp | command sed -En 's|^declare [^ ]+ ([^=]+).*|\1|p'609 )610}611612_fzf_alias_completion() {613 _fzf_complete -m -- "$@" < <(614 alias | command sed -En 's|^alias ([^=]+).*|\1|p'615 )616}617618# fzf options619complete -o default -F _fzf_opts_completion fzf620# fzf-tmux is a thin fzf wrapper that has only a few more options than fzf621# itself. As a quick improvement we take fzf's completion. Adding the few extra622# fzf-tmux specific options (like `-w WIDTH`) are left as a future patch.623complete -o default -F _fzf_opts_completion fzf-tmux624625# Default path completion626__fzf_default_completion() {627 __fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"628629 # Dynamic completion loader has updated the completion for the command630 if [[ $? -eq 124 ]]; then631 # We trigger _fzf_setup_completion so that fuzzy completion for the command632 # still works. However, loader can update the completion for multiple633 # commands at once, and fuzzy completion will no longer work for those634 # other commands. e.g. pytest -> py.test, pytest-2, pytest-3, etc635 _fzf_setup_completion path "$1"636 return 124637 fi638}639640# Set fuzzy path completion as the default completion for all commands.641# We can't set up default completion,642# 1. if it's already set up by another script643# 2. or if the current version of bash doesn't support -D option644complete | command grep -q __fzf_default_completion ||645 complete | command grep -- '-D$' | command grep -qv _comp_complete_load ||646 complete -D -F __fzf_default_completion -o default -o bashdefault 2> /dev/null647648d_cmds="${FZF_COMPLETION_DIR_COMMANDS-cd pushd rmdir}"649650# NOTE: $FZF_COMPLETION_PATH_COMMANDS and $FZF_COMPLETION_VAR_COMMANDS are651# undocumented and subject to change in the future.652#653# NOTE: Although we have default completion, we still need to set up completion654# for each command in case they already have completion set up by another script.655a_cmds="${FZF_COMPLETION_PATH_COMMANDS-"656 awk bat cat code diff diff3657 emacs emacsclient ex file ftp g++ gcc gvim head hg hx java658 javac ld less more mvim nvim patch perl python ruby659 sed sftp sort source tail tee uniq vi view vim wc xdg-open660 basename bunzip2 bzip2 chmod chown curl cp dirname du661 find git grep gunzip gzip hg jar662 ln ls mv open rm rsync scp663 svn tar unzip zip"}"664v_cmds="${FZF_COMPLETION_VAR_COMMANDS-export unset printenv}"665666# Preserve existing completion667__fzf_orig_completion < <(complete -p $d_cmds $a_cmds $v_cmds unalias kill ssh 2> /dev/null)668669if type _comp_load > /dev/null 2>&1; then670 # _comp_load was added in bash-completion 2.12 to replace _completion_loader.671 # We use it without -D option so that it does not use _comp_complete_minimal as the fallback.672 _fzf_completion_loader=_comp_load673elif type __load_completion > /dev/null 2>&1; then674 # In bash-completion 2.11, _completion_loader internally calls __load_completion675 # and if it returns a non-zero status, it sets the default 'minimal' completion.676 _fzf_completion_loader=__load_completion677elif type _completion_loader > /dev/null 2>&1; then678 _fzf_completion_loader=_completion_loader679fi680681__fzf_defc() {682 local cmd func opts REPLY683 cmd="$1"684 func="$2"685 opts="$3"686 if __fzf_orig_completion_instantiate "$cmd" "$func"; then687 eval "$REPLY"688 else689 eval "complete -F \"$func\" $opts \"$cmd\""690 fi691}692693# Anything694for cmd in $a_cmds; do695 __fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault"696done697698# Directory699for cmd in $d_cmds; do700 __fzf_defc "$cmd" _fzf_dir_completion "-o bashdefault -o nospace -o dirnames"701done702703# Variables704for cmd in $v_cmds; do705 __fzf_defc "$cmd" _fzf_var_completion "-o default -o nospace -v"706done707708# Aliases709__fzf_defc unalias _fzf_alias_completion "-a"710711# Processes712__fzf_defc kill _fzf_proc_completion "-o default -o bashdefault"713714# ssh715__fzf_defc ssh _fzf_complete_ssh "-o default -o bashdefault"716717unset cmd d_cmds a_cmds v_cmds718719_fzf_setup_completion() {720 local kind fn cmd721 kind=$1722 fn=_fzf_${1}_completion723 if [[ $# -lt 2 ]] || ! type -t "$fn" > /dev/null; then724 echo "usage: ${FUNCNAME[0]} path|dir|var|alias|host|proc COMMANDS..."725 return 1726 fi727 shift728 __fzf_orig_completion < <(complete -p "$@" 2> /dev/null)729 for cmd in "$@"; do730 case "$kind" in731 dir) __fzf_defc "$cmd" "$fn" "-o nospace -o dirnames" ;;732 var) __fzf_defc "$cmd" "$fn" "-o default -o nospace -v" ;;733 alias) __fzf_defc "$cmd" "$fn" "-a" ;;734 *) __fzf_defc "$cmd" "$fn" "-o default -o bashdefault" ;;735 esac736 done737}738#----END shfmt739740fi