github.com/kristofferahl/go-centry@v1.5.0/bash_autocomplete (about)

     1  #! /bin/bash
     2  
     3  : ${PROG:=$(basename ${BASH_SOURCE})}
     4  
     5  _cli_bash_autocomplete() {
     6    if [[ "${COMP_WORDS[0]}" != "source" ]]; then
     7      local cur opts base
     8      COMPREPLY=()
     9      cur="${COMP_WORDS[COMP_CWORD]}"
    10      if [[ "$cur" == "-"* ]]; then
    11        opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )
    12      else
    13        opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
    14      fi
    15      COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
    16      return 0
    17    fi
    18  }
    19  
    20  complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG
    21  unset PROG