_ego() { local i cur prev opts cmd COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" cmd="" opts="" for i in ${COMP_WORDS[@]} do case "${cmd},${i}" in ",$1") cmd="ego" ;; *) ;; esac done case "${cmd}" in ego) opts="-u -v -h -V --user --sudo --machinectl --machinectl-bare --verbose --help --version [command]..." if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 fi case "${prev}" in --user) COMPREPLY=($(compgen -f "${cur}")) return 0 ;; -u) COMPREPLY=($(compgen -f "${cur}")) return 0 ;; *) COMPREPLY=() ;; esac COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; esac } complete -F _ego -o bashdefault -o default ego