github.com/clusterize-io/tusk@v0.6.3-0.20211001020217-cfe8a8cd0d4a/appcli/completion/tusk-completion.bash (about) 1 #!/bin/bash 2 3 _tusk_bash_autocomplete() { 4 local cur words opts meta 5 COMPREPLY=() 6 cur="${COMP_WORDS[COMP_CWORD]}" 7 words="$( "${COMP_WORDS[@]:0:$COMP_CWORD}" --generate-bash-completion \ 8 | sed 's/\\:/_=_/g' | cut -f1 -d":" | sed 's/_=_/:/g' )" 9 10 # Split words into completion type and options 11 meta="$( echo "${words}" | head -n1 )" 12 opts="$( echo "${words}" | tail -n +2 )" 13 14 case "${meta}" in 15 file) 16 COMPREPLY=( $(compgen -f -- "${cur}") ) 17 ;; 18 *) 19 declare -a values args flags 20 values=( ${opts} ) 21 for option in "${values[@]}"; do 22 if [[ "${option}" = --* ]]; then 23 flags+=("${option}") 24 else 25 args+=("${option}") 26 fi 27 done 28 29 if [[ "${cur}" = --* ]]; then 30 COMPREPLY=( $(compgen -W "${flags[*]}" -- "${cur}") ) 31 else 32 COMPREPLY=( $(compgen -W "${args[*]}" -- "${cur}") ) 33 fi 34 ;; 35 esac 36 37 return 0 38 } 39 40 complete -o filenames -o bashdefault -F _tusk_bash_autocomplete tusk