# This is a shell completion script auto-generated by https://github.com/urfave/cli for bash. # macOS still ships Bash 3, where bash-completion may not provide # _init_completion. This is a minimal compatible fallback. __%[1]s_init_completion() { COMPREPLY=() if declare -F _comp_initialize >/dev/null 2>&1; then _comp_initialize "$@" else _get_comp_words_by_ref "$@" cur prev words cword fi } __%[1]s_build_completion_request() { local -a words_before_cursor=("${COMP_WORDS[@]:0:${COMP_CWORD}}") local current_word="${COMP_WORDS[COMP_CWORD]}" if [[ "${current_word}" == "-"* ]]; then printf '%%s %%s --generate-shell-completion' "${words_before_cursor[*]}" "${current_word}" else printf '%%s --generate-shell-completion' "${words_before_cursor[*]}" fi } __%[1]s_bash_autocomplete() { local words=("${COMP_WORDS[@]}") if [[ "${words[0]}" != "source" ]]; then local cur opts local cword="${COMP_CWORD}" local request_comp COMPREPLY=() cur="${words[$cword]}" __%[1]s_init_completion -n "=:" || return request_comp="$(__%[1]s_build_completion_request)" opts=$(eval "${request_comp}" 2>/dev/null) # Completion output lines use "token:description" format. Walk them once, keeping only # the entries that match the word being completed. This must stay linear in the number # of lines (apps can emit thousands) and avoid forking per candidate. local -a matches=() descriptions=() local line token description local longest=0 while IFS=$'\n' read -r line; do token="${line%%%%:*}" if [[ -z "${token}" || "${token}" != "${cur}"* ]]; then continue fi description="" if [[ "${line}" == *:* ]]; then description="${line#*:}" fi matches+=("${token}") descriptions+=("${description}") (( ${#token} > longest )) && longest=${#token} done <<< "${opts}" # COMP_TYPE=63 means Bash is listing matches (usually on second TAB). if [[ "${COMP_TYPE:-}" == "63" && ${#matches[@]} -gt 0 ]]; then local i padded for i in "${!matches[@]}"; do if [[ -n "${descriptions[i]}" ]]; then printf -v padded '%%-*s' "${longest}" "${matches[i]}" COMPREPLY+=("${padded} -- ${descriptions[i]}") else COMPREPLY+=("${matches[i]}") fi done else COMPREPLY=("${matches[@]}") fi return 0 fi } complete -o bashdefault -o default -F __%[1]s_bash_autocomplete %[1]s