#/usr/bin/env bash __mdatp__suggestion() { local json_command=[ END=$((COMP_CWORD-1)) for i in $(seq 0 $END) do case $i in 0) #it is always mdatp - skip ;; 1) json_command+=\"${COMP_WORDS[i]}\" ;; *) json_command+=,\"${COMP_WORDS[i]}\" ;; esac done # Last element starts with "--", for optional parametters completion if [[ ${COMP_WORDS[COMP_CWORD]} = --* ]]; then json_command+=,\"--\" fi json_command+=] echo "$(mdatp helper --command $json_command --type bash 2>/dev/null)" } __mdatp__completion() { local cur prev cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} case "${prev}" in "--path") local suggestions=($(compgen -o filenames -A file -- ${cur})) COMPREPLY=("${suggestions[@]}") ;; *) n="$(__mdatp__suggestion)" if [ -n "${n}" ] then local suggestions=($(compgen -W "${n}" -- ${cur})) COMPREPLY=("${suggestions[@]}") fi ;; esac } complete -F __mdatp__completion mdatp