Skip to content
Myr

completion.bash

This file

Path

shell/completion.bash

741 lines · 21.2 KiB · Shell

Last changed by

Fix FZF_COMPLETION_{DIR,PATH}_OPTS ignored with custom compgen functions (#4679)Kyle Tsebefore adoption1a50a3c

History of this file

Take it

1#     ____      ____2#    / __/___  / __/3#   / /_/_  / / /_4#  / __/ / /_/ __/5# /_/   /___/_/ completion.bash6#7# - $FZF_TMUX                 (default: 0)8# - $FZF_TMUX_OPTS            (default: empty)9# - $FZF_COMPLETION_TRIGGER   (default: '**')10# - $FZF_COMPLETION_OPTS      (default: empty)11# - $FZF_COMPLETION_PATH_OPTS (default: empty)12# - $FZF_COMPLETION_DIR_OPTS  (default: empty)1314if [[ $- =~ i ]]; then151617# To use custom commands instead of find, override _fzf_compgen_{path,dir}18#19#   _fzf_compgen_path() {20#     echo "$1"21#     command find -L "$1" \22#       -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \23#       -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'24#   }25#26#   _fzf_compgen_dir() {27#     command find -L "$1" \28#       -name .git -prune -o -name .hg -prune -o -name .svn -prune -o -type d \29#       -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'30#   }3132###########################################################3334#----BEGIN shfmt35#----BEGIN INCLUDE common.sh36# NOTE: Do not directly edit this section, which is copied from "common.sh".37# To modify it, one can edit "common.sh" and run "./update.sh" to apply38# the changes. See code comments in "common.sh" for the implementation details.3940__fzf_defaults() {41  printf '%s\n' "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"42  command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null43  printf '%s\n' "${FZF_DEFAULT_OPTS-} $2"44}4546__fzf_exec_awk() {47  if [[ -z ${__fzf_awk-} ]]; then48    __fzf_awk=awk49    if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then50      __fzf_awk=/usr/xpg4/bin/awk51    elif command -v mawk > /dev/null 2>&1; then52      local n x y z d53      IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)54      [[ $n == mawk ]] &&55        (((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&56        ((d >= 20230302)) 2> /dev/null &&57        __fzf_awk=mawk58    fi59  fi60  LC_ALL=C exec "$__fzf_awk" "$@"61}62#----END INCLUDE6364__fzf_comprun() {65  if [[ "$(type -t _fzf_comprun 2>&1)" == function ]]; then66    _fzf_comprun "$@"67  elif [[ -n ${TMUX_PANE-} ]] && { [[ ${FZF_TMUX:-0} != 0 ]] || [[ -n ${FZF_TMUX_OPTS-} ]]; }; then68    shift69    fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- "$@"70  else71    shift72    fzf "$@"73  fi74}7576__fzf_orig_completion() {77  local l comp f cmd78  while read -r l; do79    if [[ $l =~ ^(.*\ -F)\ *([^ ]*).*\ ([^ ]*)$ ]]; then80      comp="${BASH_REMATCH[1]}"81      f="${BASH_REMATCH[2]}"82      cmd="${BASH_REMATCH[3]}"83      [[ $f == _fzf_* ]] && continue84      printf -v "_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}" "%s" "${comp} %s ${cmd} #${f}"85      if [[ $l == *" -o nospace "* ]] && [[ ${__fzf_nospace_commands-} != *" $cmd "* ]]; then86        __fzf_nospace_commands="${__fzf_nospace_commands-} $cmd "87      fi88    fi89  done90}9192# @param $1 cmd - Command name for which the original completion is searched93# @var[out] REPLY - Original function name is returned94__fzf_orig_completion_get_orig_func() {95  local cmd orig_var orig96  cmd=$197  orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"98  orig="${!orig_var-}"99  REPLY="${orig##*#}"100  [[ $REPLY ]] && type "$REPLY" &> /dev/null101}102103# @param $1 cmd - Command name for which the original completion is searched104# @param $2 func - Fzf's completion function to replace the original function105# @var[out] REPLY - Completion setting is returned as a string to "eval"106__fzf_orig_completion_instantiate() {107  local cmd func orig_var orig108  cmd=$1109  func=$2110  orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"111  orig="${!orig_var-}"112  orig="${orig%#*}"113  [[ $orig == *' %s '* ]] || return 1114  printf -v REPLY "$orig" "$func"115}116117_fzf_opts_completion() {118  local cur prev opts119  COMPREPLY=()120  cur="${COMP_WORDS[COMP_CWORD]}"121  prev="${COMP_WORDS[COMP_CWORD - 1]}"122  opts="123    +c --no-color124    +i --no-ignore-case125    +s --no-sort126    +x --no-extended127    --accept-nth128    --ansi129    --bash130    --bind131    --border132    --border-label133    --border-label-pos134    --color135    --cycle136    --disabled137    --ellipsis138    --expect139    --filepath-word140    --fish141    --footer142    --footer-border143    --footer-label144    --footer-label-pos145    --freeze-left146    --freeze-right147    --gap148    --gap-line149    --ghost150    --gutter151    --gutter-raw152    --header153    --header-border154    --header-first155    --header-label156    --header-label-pos157    --header-lines158    --header-lines-border159    --height160    --highlight-line161    --history162    --history-size163    --hscroll-off164    --info165    --info-command166    --input-border167    --input-label168    --input-label-pos169    --jump-labels170    --keep-right171    --layout172    --listen173    --listen-unsafe174    --list-border175    --list-label176    --list-label-pos177    --literal178    --man179    --margin180    --marker181    --marker-multi-line182    --min-height183    --no-bold184    --no-hscroll185    --no-input186    --no-multi-line187    --no-scrollbar188    --no-separator189    --padding190    --pointer191    --preview192    --preview-border193    --preview-label194    --preview-label-pos195    --preview-window196    --print-query197    --print0198    --prompt199    --raw200    --read0201    --scheme202    --scroll-off203    --scrollbar204    --separator205    --smart-case206    --style207    --sync208    --tabstop209    --tac210    --tail211    --tiebreak212    --tmux213    --track214    --version215    --walker216    --walker-root217    --walker-skip218    --with-nth219    --with-shell220    --wrap221    --wrap-sign222    --preview-wrap-sign223    --zsh224    -0 --exit-0225    -1 --select-1226    -d --delimiter227    -e --exact228    -f --filter229    -h --help230    -i --ignore-case231    -m --multi232    -n --nth233    -q --query234    --"235236  case "${prev}" in237    --scheme)238      COMPREPLY=($(compgen -W "default path history" -- "$cur"))239      return 0240      ;;241    --tiebreak)242      COMPREPLY=($(compgen -W "length chunk pathname begin end index" -- "$cur"))243      return 0244      ;;245    --color)246      COMPREPLY=($(compgen -W "dark light base16 16 bw no" -- "$cur"))247      return 0248      ;;249    --layout)250      COMPREPLY=($(compgen -W "default reverse reverse-list" -- "$cur"))251      return 0252      ;;253    --info)254      COMPREPLY=($(compgen -W "default right hidden inline inline-right" -- "$cur"))255      return 0256      ;;257    --wrap)258      COMPREPLY=($(compgen -W "char word" -- "$cur"))259      return 0260      ;;261    --style)262      COMPREPLY=($(compgen -W "default minimal full" -- "$cur"))263      return 0264      ;;265    --preview-window)266      COMPREPLY=($(compgen -W "267      default268      hidden269      nohidden270      wrap271      wrap-word272      nowrap273      cycle274      nocycle275      up top276      down bottom277      left278      right279      rounded border border-rounded280      border-line281      sharp border-sharp282      border-bold283      border-block284      border-thinblock285      border-double286      noborder border-none287      border-horizontal288      border-vertical289      border-up border-top290      border-down border-bottom291      border-left292      border-right293      follow294      nofollow295      info296      noinfo" -- "$cur"))297      return 0298      ;;299    --border | --list-border | --header-border | --header-lines-border | --footer-border | --input-border | --preview-border)300      COMPREPLY=($(compgen -W "line rounded sharp bold block thinblock double horizontal vertical top bottom left right none" -- "$cur"))301      return 0302      ;;303    --border-label-pos | --preview-label-pos | --list-label-pos | --header-label-pos | --footer-label-pos | --input-label-pos)304      COMPREPLY=($(compgen -W "center bottom top" -- "$cur"))305      return 0306      ;;307  esac308309  if [[ $cur =~ ^-|\+ ]]; then310    COMPREPLY=($(compgen -W "${opts}" -- "$cur"))311    return 0312  fi313314  return 0315}316317_fzf_handle_dynamic_completion() {318  local cmd ret REPLY orig_cmd orig_complete319  cmd="$1"320  shift321  orig_cmd="$1"322  if __fzf_orig_completion_get_orig_func "$cmd"; then323    "$REPLY" "$@"324  elif [[ -n ${_fzf_completion_loader-} ]]; then325    orig_complete=$(complete -p "$orig_cmd" 2> /dev/null)326    $_fzf_completion_loader "$@"327    ret=$?328    # _completion_loader may not have updated completion for the command329    if [[ "$(complete -p "$orig_cmd" 2> /dev/null)" != "$orig_complete" ]]; then330      __fzf_orig_completion < <(complete -p "$orig_cmd" 2> /dev/null)331      __fzf_orig_completion_get_orig_func "$cmd" || ret=1332333      # Update orig_complete by _fzf_orig_completion entry334      [[ $orig_complete =~ ' -F '(_fzf_[^ ]+)' ' ]] &&335        __fzf_orig_completion_instantiate "$cmd" "${BASH_REMATCH[1]}" &&336        orig_complete=$REPLY337338      if [[ ${__fzf_nospace_commands-} == *" $orig_cmd "* ]]; then339        eval "${orig_complete/ -F / -o nospace -F }"340      else341        eval "$orig_complete"342      fi343    fi344    [[ $ret -eq 0 ]] && return 124345    return $ret346  fi347}348349__fzf_generic_path_completion() {350  local cur base dir leftover matches trigger cmd351  cmd="${COMP_WORDS[0]}"352  if [[ $cmd == \\* ]]; then353    cmd="${cmd:1}"354  fi355  COMPREPLY=()356  trigger=${FZF_COMPLETION_TRIGGER-'**'}357  [[ $COMP_CWORD -ge 0 ]] && cur="${COMP_WORDS[COMP_CWORD]}"358  if [[ $cur == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then359    base=${cur:0:${#cur}-${#trigger}}360    eval "base=$base" 2> /dev/null || return361362    dir=363    [[ $base == *"/"* ]] && dir="$base"364    while true; do365      if [[ -z $dir ]] || [[ -d $dir ]]; then366        leftover=${base/#"$dir"/}367        leftover=${leftover/#\//}368        [[ -z $dir ]] && dir='.'369        [[ $dir != "/" ]] && dir="${dir/%\//}"370        matches=$(371          export FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --scheme=path" "${FZF_COMPLETION_OPTS-} $2")372          unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE373          if [[ $1 =~ dir ]]; then374            eval "rest=(${FZF_COMPLETION_DIR_OPTS-})"375          else376            eval "rest=(${FZF_COMPLETION_PATH_OPTS-})"377          fi378          if declare -F "$1" > /dev/null; then379            eval "$1 $(printf %q "$dir")" | __fzf_comprun "$4" -q "$leftover" "${rest[@]}"380          else381            if [[ $1 =~ dir ]]; then382              walker=dir,follow383            else384              walker=file,dir,follow,hidden385            fi386            __fzf_comprun "$4" -q "$leftover" --walker "$walker" --walker-root="$dir" "${rest[@]}"387          fi | while read -r item; do388            printf "%q " "${item%$3}$3"389          done390        )391        matches=${matches% }392        [[ -z $3 ]] && [[ ${__fzf_nospace_commands-} == *" ${COMP_WORDS[0]} "* ]] && matches="$matches "393        if [[ -n $matches ]]; then394          COMPREPLY=("$matches")395        else396          COMPREPLY=("$cur")397        fi398        # To redraw line after fzf closes (printf '\e[5n')399        bind '"\e[0n": redraw-current-line' 2> /dev/null400        printf '\e[5n'401        return 0402      fi403      dir=$(command dirname "$dir")404      [[ $dir =~ /$ ]] || dir="$dir"/405    done406  else407    shift408    shift409    shift410    _fzf_handle_dynamic_completion "$cmd" "$@"411  fi412}413414_fzf_complete() {415  # Split arguments around --416  local args rest str_arg i sep417  args=("$@")418  sep=419  for i in "${!args[@]}"; do420    if [[ ${args[$i]} == -- ]]; then421      sep=$i422      break423    fi424  done425  if [[ -n $sep ]]; then426    str_arg=427    rest=("${args[@]:$((sep + 1)):${#args[@]}}")428    args=("${args[@]:0:sep}")429  else430    str_arg=$1431    args=()432    shift433    rest=("$@")434  fi435436  local cur selected trigger cmd post437  post="$(caller 0 | __fzf_exec_awk '{print $2}')_post"438  type -t "$post" > /dev/null 2>&1 || post='command cat'439440  trigger=${FZF_COMPLETION_TRIGGER-'**'}441  cmd="${COMP_WORDS[0]}"442  cur="${COMP_WORDS[COMP_CWORD]}"443  if [[ $cur == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then444    cur=${cur:0:${#cur}-${#trigger}}445446    selected=$(447      FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse" "${FZF_COMPLETION_OPTS-} $str_arg") \448      FZF_DEFAULT_OPTS_FILE='' \449        __fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | eval "$post" | command tr '\n' ' '450    )451    selected=${selected% } # Strip trailing space not to repeat "-o nospace"452    if [[ -n $selected ]]; then453      COMPREPLY=("$selected")454    else455      COMPREPLY=("$cur")456    fi457    bind '"\e[0n": redraw-current-line' 2> /dev/null458    printf '\e[5n'459    return 0460  else461    _fzf_handle_dynamic_completion "$cmd" "${rest[@]}"462  fi463}464465_fzf_path_completion() {466  __fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"467}468469# Deprecated. No file only completion.470_fzf_file_completion() {471  _fzf_path_completion "$@"472}473474_fzf_dir_completion() {475  __fzf_generic_path_completion _fzf_compgen_dir "" "/" "$@"476}477478_fzf_complete_kill() {479  _fzf_proc_completion "$@"480}481482_fzf_proc_completion() {483  local transformer484  transformer='485    if [[ $FZF_KEY =~ ctrl|alt|shift ]] && [[ -n $FZF_NTH ]]; then486      nths=( ${FZF_NTH//,/ } )487      new_nths=()488      found=0489      for nth in ${nths[@]}; do490        if [[ $nth = $FZF_CLICK_HEADER_NTH ]]; then491          found=1492        else493          new_nths+=($nth)494        fi495      done496      [[ $found = 0 ]] && new_nths+=($FZF_CLICK_HEADER_NTH)497      new_nths=${new_nths[*]}498      new_nths=${new_nths// /,}499      echo "change-nth($new_nths)+change-prompt($new_nths> )"500    else501      if [[ $FZF_NTH = $FZF_CLICK_HEADER_NTH ]]; then502        echo "change-nth()+change-prompt(> )"503      else504        echo "change-nth($FZF_CLICK_HEADER_NTH)+change-prompt($FZF_CLICK_HEADER_WORD> )"505      fi506    fi507  '508  _fzf_complete -m --header-lines=1 --no-preview --wrap --color fg:dim,nth:regular \509    --bind "click-header:transform:$transformer" -- "$@" < <(510      command ps -eo user,pid,ppid,start,time,command 2> /dev/null ||511        command ps -eo user,pid,ppid,time,args 2> /dev/null || # For BusyBox512        command ps --everyone --full --windows                 # For cygwin513    )514}515516_fzf_proc_completion_post() {517  __fzf_exec_awk '{print $2}'518}519520# To use custom hostname lists, override __fzf_list_hosts.521# The function is expected to print hostnames, one per line as well as in the522# desired sorting and with any duplicates removed, to standard output.523#524# e.g.525#   # Use bash-completions’s _known_hosts_real() for getting the list of hosts526#   __fzf_list_hosts() {527#     # Set the local attribute for any non-local variable that is set by _known_hosts_real()528#     local COMPREPLY=()529#     _known_hosts_real ''530#     printf '%s\n' "${COMPREPLY[@]}" | command sort -u --version-sort531#   }532if ! declare -F __fzf_list_hosts > /dev/null; then533  __fzf_list_hosts() {534    command sort -u \535      <(536        # Note: To make the pathname expansion of "~/.ssh/config.d/*" work537        # properly, we need to adjust the related shell options.  We need to538        # unset "set -f" and "GLOBIGNORE", which disable the pathname expansion539        # totally or partially.  We need to unset "dotglob" and "nocaseglob" to540        # avoid matching unwanted files.  We need to unset "failglob" to avoid541        # outputting the error messages to the terminal when no matching is542        # found.  We need to set "nullglob" to avoid attempting to read the543        # literal filename '~/.ssh/config.d/*' when no matching is found.544        set +f545        GLOBIGNORE=546        shopt -u dotglob nocaseglob failglob547        shopt -s nullglob548549        __fzf_exec_awk '550          # Note: mawk <= 1.3.3-20090705 does not support the POSIX brackets of551          # the form [[:blank:]], and Ubuntu 18.04 LTS still uses this552          # 16-year-old mawk unfortunately.  We need to use [ \t] instead.553          match(tolower($0), /^[ \t]*host(name)?[ \t]*[ \t=]/) {554            $0 = substr($0, RLENGTH + 1) # Remove "Host(name)?=?"555            sub(/#.*/, "")556            for (i = 1; i <= NF; i++)557              if ($i !~ /[*?%]/)558                print $i559          }560        ' ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null561      ) \562      <(563        __fzf_exec_awk -F ',' '564          match($0, /^[][a-zA-Z0-9.,:-]+/) {565            $0 = substr($0, 1, RLENGTH)566            gsub(/[][]|:[^,]*/, "")567            for (i = 1; i <= NF; i++)568              print $i569          }570        ' ~/.ssh/known_hosts 2> /dev/null571      ) \572      <(573        __fzf_exec_awk '574          {575            sub(/#.*/, "")576            for (i = 2; i <= NF; i++)577              if ($i != "0.0.0.0")578                print $i579          }580        ' /etc/hosts 2> /dev/null581      )582  }583fi584585_fzf_host_completion() {586  _fzf_complete +m -- "$@" < <(__fzf_list_hosts)587}588589# Values for $1 $2 $3 are described here590# https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html591# > the first argument ($1) is the name of the command whose arguments are being completed,592# > the second argument ($2) is the word being completed,593# > and the third argument ($3) is the word preceding the word being completed on the current command line.594_fzf_complete_ssh() {595  case $3 in596    -i | -F | -E)597      _fzf_path_completion "$@"598      ;;599    *)600      local user=601      [[ $2 =~ '@' ]] && user="${2%%@*}@"602      _fzf_complete +m -- "$@" < <(__fzf_list_hosts | __fzf_exec_awk -v user="$user" '{print user $0}')603      ;;604  esac605}606607_fzf_var_completion() {608  _fzf_complete -m -- "$@" < <(609    declare -xp | command sed -En 's|^declare [^ ]+ ([^=]+).*|\1|p'610  )611}612613_fzf_alias_completion() {614  _fzf_complete -m -- "$@" < <(615    alias | command sed -En 's|^alias ([^=]+).*|\1|p'616  )617}618619# fzf options620complete -o default -F _fzf_opts_completion fzf621# fzf-tmux is a thin fzf wrapper that has only a few more options than fzf622# itself. As a quick improvement we take fzf's completion. Adding the few extra623# fzf-tmux specific options (like `-w WIDTH`) are left as a future patch.624complete -o default -F _fzf_opts_completion fzf-tmux625626# Default path completion627__fzf_default_completion() {628  __fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"629630  # Dynamic completion loader has updated the completion for the command631  if [[ $? -eq 124 ]]; then632    # We trigger _fzf_setup_completion so that fuzzy completion for the command633    # still works. However, loader can update the completion for multiple634    # commands at once, and fuzzy completion will no longer work for those635    # other commands. e.g. pytest -> py.test, pytest-2, pytest-3, etc636    _fzf_setup_completion path "$1"637    return 124638  fi639}640641# Set fuzzy path completion as the default completion for all commands.642# We can't set up default completion,643# 1. if it's already set up by another script644# 2. or if the current version of bash doesn't support -D option645complete | command grep -q __fzf_default_completion ||646  complete | command grep -- '-D$' | command grep -qv _comp_complete_load ||647  complete -D -F __fzf_default_completion -o default -o bashdefault 2> /dev/null648649d_cmds="${FZF_COMPLETION_DIR_COMMANDS-cd pushd rmdir}"650651# NOTE: $FZF_COMPLETION_PATH_COMMANDS and $FZF_COMPLETION_VAR_COMMANDS are652# undocumented and subject to change in the future.653#654# NOTE: Although we have default completion, we still need to set up completion655# for each command in case they already have completion set up by another script.656a_cmds="${FZF_COMPLETION_PATH_COMMANDS-"657  awk bat cat code diff diff3658  emacs emacsclient ex file ftp g++ gcc gvim head hg hx java659  javac ld less more mvim nvim patch perl python ruby660  sed sftp sort source tail tee uniq vi view vim wc xdg-open661  basename bunzip2 bzip2 chmod chown curl cp dirname du662  find git grep gunzip gzip hg jar663  ln ls mv open rm rsync scp664  svn tar unzip zip"}"665v_cmds="${FZF_COMPLETION_VAR_COMMANDS-export unset printenv}"666667# Preserve existing completion668__fzf_orig_completion < <(complete -p $d_cmds $a_cmds $v_cmds unalias kill ssh 2> /dev/null)669670if type _comp_load > /dev/null 2>&1; then671  # _comp_load was added in bash-completion 2.12 to replace _completion_loader.672  # We use it without -D option so that it does not use _comp_complete_minimal as the fallback.673  _fzf_completion_loader=_comp_load674elif type __load_completion > /dev/null 2>&1; then675  # In bash-completion 2.11, _completion_loader internally calls __load_completion676  # and if it returns a non-zero status, it sets the default 'minimal' completion.677  _fzf_completion_loader=__load_completion678elif type _completion_loader > /dev/null 2>&1; then679  _fzf_completion_loader=_completion_loader680fi681682__fzf_defc() {683  local cmd func opts REPLY684  cmd="$1"685  func="$2"686  opts="$3"687  if __fzf_orig_completion_instantiate "$cmd" "$func"; then688    eval "$REPLY"689  else690    eval "complete -F \"$func\" $opts \"$cmd\""691  fi692}693694# Anything695for cmd in $a_cmds; do696  __fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault"697done698699# Directory700for cmd in $d_cmds; do701  __fzf_defc "$cmd" _fzf_dir_completion "-o bashdefault -o nospace -o dirnames"702done703704# Variables705for cmd in $v_cmds; do706  __fzf_defc "$cmd" _fzf_var_completion "-o default -o nospace -v"707done708709# Aliases710__fzf_defc unalias _fzf_alias_completion "-a"711712# Processes713__fzf_defc kill _fzf_proc_completion "-o default -o bashdefault"714715# ssh716__fzf_defc ssh _fzf_complete_ssh "-o default -o bashdefault"717718unset cmd d_cmds a_cmds v_cmds719720_fzf_setup_completion() {721  local kind fn cmd722  kind=$1723  fn=_fzf_${1}_completion724  if [[ $# -lt 2 ]] || ! type -t "$fn" > /dev/null; then725    echo "usage: ${FUNCNAME[0]} path|dir|var|alias|host|proc COMMANDS..."726    return 1727  fi728  shift729  __fzf_orig_completion < <(complete -p "$@" 2> /dev/null)730  for cmd in "$@"; do731    case "$kind" in732      dir) __fzf_defc "$cmd" "$fn" "-o nospace -o dirnames" ;;733      var) __fzf_defc "$cmd" "$fn" "-o default -o nospace -v" ;;734      alias) __fzf_defc "$cmd" "$fn" "-a" ;;735      *) __fzf_defc "$cmd" "$fn" "-o default -o bashdefault" ;;736    esac737  done738}739#----END shfmt740741fi