_akeyless() { local cur prev opts COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" opts="--help" [ $COMP_CWORD -gt 2 ] && return 0 if [ "${prev}" == "akeyless" ]; then [ "${cur}" == "" ] || akeyless ${cur} 2>&1 | grep -Eqi "not found" if [ $? -eq 0 ]; then COMPREPLY=($(compgen -W "$(akeyless ${opts} | sed '1,17d' | awk '{print $1}')" -- "${COMP_WORDS[$COMP_CWORD]}")) fi else COMPREPLY=($(compgen -W "$(akeyless ${prev} ${opts} | sed '1,4d' | sed 's/.*\-\-/\-\-/g' | sed 's/\[.*//g' | awk '{print $1}' | grep '^\-')" -- "${COMP_WORDS[$COMP_CWORD]}")) fi return 0 } complete -F _akeyless akeyless