···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+33+complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete tcld
···1+#compdef $PROG
2+3+## based on https://github.com/urfave/cli/blob/v2.27.6/autocomplete/zsh_autocomplete
4+5+_cli_zsh_autocomplete() {
6+ local -a opts
7+ local cur
8+ cur=${words[-1]}
9+ if [[ "$cur" == "-"* ]]; then
10+ opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
11+ else
12+ opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-bash-completion)}")
13+ fi
14+15+ if [[ "${opts[1]}" != "" ]]; then
16+ _describe 'values' opts
17+ else
18+ _files
19+ fi
20+}
21+22+compdef _cli_zsh_autocomplete tcld