# bash completion for dprofile # shellcheck shell=bash _dprofile() { local cur=${COMP_WORDS[COMP_CWORD]} cmd=${COMP_WORDS[1]:-} dir=/usr/share/das/profiles local profiles profiles=$(find "$dir" -maxdepth 1 -name '*.conf' -printf '%f\n' 2>/dev/null | sed 's/\.conf$//') if ((COMP_CWORD == 1)); then mapfile -t COMPREPLY < <(compgen -W "list show install apps app help" -- "$cur") return fi case $cmd in show | apps | check) ((COMP_CWORD == 2)) && mapfile -t COMPREPLY < <(compgen -W "$profiles" -- "$cur") ;; install) if [[ ${COMP_WORDS[COMP_CWORD - 1]} == --apps ]]; then mapfile -t COMPREPLY < <(compgen -W "all none" -- "$cur") else mapfile -t COMPREPLY < <(compgen -W "$profiles --yes --apps" -- "$cur") fi ;; app) if ((COMP_CWORD == 2)); then mapfile -t COMPREPLY < <(compgen -W "add rm" -- "$cur") else # the last part of the IDs in the profiles: AndroidStudio, GoLand mapfile -t COMPREPLY < <(compgen -W "$(sed -n 's/^[a-z]*\.[A-Za-z0-9.-]*\.\([A-Za-z0-9-]*\) .*/\1/p' "$dir"/*.conf 2>/dev/null)" -- "$cur") fi ;; esac } complete -F _dprofile dprofile