Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at python-updates 33 lines 1.1 kB view raw
1#! /bin/bash 2# based on https://github.com/urfave/cli/blob/v2.27.6/autocomplete/bash_autocomplete 3 4# Macs have bash3 for which the bash-completion package doesn't include 5# _init_completion. This is a minimal version of that function. 6_cli_init_completion() { 7 COMPREPLY=() 8 _get_comp_words_by_ref "$@" cur prev words cword 9} 10 11_cli_bash_autocomplete() { 12 if [[ "${COMP_WORDS[0]}" != "source" ]]; then 13 local cur opts base words 14 COMPREPLY=() 15 cur="${COMP_WORDS[COMP_CWORD]}" 16 if declare -F _init_completion >/dev/null 2>&1; then 17 _init_completion -n "=:" || return 18 else 19 _cli_init_completion -n "=:" || return 20 fi 21 words=("${words[@]:0:$cword}") 22 if [[ "$cur" == "-"* ]]; then 23 requestComp="${words[*]} ${cur} --generate-bash-completion" 24 else 25 requestComp="${words[*]} --generate-bash-completion" 26 fi 27 opts=$(eval "${requestComp}" 2>/dev/null) 28 COMPREPLY=($(compgen -W "${opts}" -- ${cur})) 29 return 0 30 fi 31} 32 33complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete tcld