...

Text file src/github.com/urfave/cli/v2/autocomplete/bash_autocomplete

Documentation: github.com/urfave/cli/v2/autocomplete

     1#! /bin/bash
     2
     3: ${PROG:=$(basename ${BASH_SOURCE})}
     4
     5# Macs have bash3 for which the bash-completion package doesn't include
     6# _init_completion. This is a minimal version of that function.
     7_cli_init_completion() {
     8  COMPREPLY=()
     9  _get_comp_words_by_ref "$@" cur prev words cword
    10}
    11
    12_cli_bash_autocomplete() {
    13  if [[ "${COMP_WORDS[0]}" != "source" ]]; then
    14    local cur opts base words
    15    COMPREPLY=()
    16    cur="${COMP_WORDS[COMP_CWORD]}"
    17    if declare -F _init_completion >/dev/null 2>&1; then
    18      _init_completion -n "=:" || return
    19    else
    20      _cli_init_completion -n "=:" || return
    21    fi
    22    words=("${words[@]:0:$cword}")
    23    if [[ "$cur" == "-"* ]]; then
    24      requestComp="${words[*]} ${cur} --generate-bash-completion"
    25    else
    26      requestComp="${words[*]} --generate-bash-completion"
    27    fi
    28    opts=$(eval "${requestComp}" 2>/dev/null)
    29    COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
    30    return 0
    31  fi
    32}
    33
    34complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG
    35unset PROG

View as plain text