--- gentoo 2013-10-06 13:33:12.000000000 -0400 +++ gentoo 2013-11-07 23:25:49.472350399 -0500 @@ -716,25 +716,31 @@ have ebuild && { _ebuild() { - local cur opts + local cur opts cmds i noopts seenf COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" - opts="help setup clean fetch digest manifest unpack compile test preinst \ + cmds="help setup clean fetch digest manifest unpack compile test preinst \ install postinst qmerge merge unmerge prerm postrm config package rpm \ configure prepare" - if [[ $COMP_CWORD -eq 1 ]] ; then - COMPREPLY=($(compgen -f -X "!*.ebuild" -- ${cur}) \ - $(compgen -d -- ${cur}) \ - $(compgen -W '--debug --force --help --ignore-default-opts --skip-manifest' -- ${cur})) + opts="--debug --force --ignore-default-opts --skip-manifest --help" - elif [[ $COMP_CWORD -eq 2 && "${COMP_WORDS[1]}" = "--debug --force --ignore-default-opts --skip-manifest" ]] ; then - COMPREPLY=($(compgen -f -X "!*.ebuild" -- ${cur}) $(compgen -d -- ${cur})) + local i noopts seenf - elif [[ $COMP_CWORD -ge 2 ]] ; then - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + for (( i=1 ; $i < ${COMP_CWORD} ; i++ )) ; do + [[ ${noopts} || ${COMP_WORDS[$i]/#-*} ]] && seenf=1 + [[ ${COMP_WORDS[$i]} == "--" ]] && noopts=1 + done + + if [[ ${seenf} ]] ; then + COMPREPLY=($(compgen -W "${cmds}" -- ${cur})) + else + COMPREPLY=($(compgen -f -X "!*.ebuild" -- ${cur}) \ + $(compgen -d -- ${cur})) fi + + [[ ${noopts} ]] || COMPREPLY+=($(compgen -W "${opts}" -- ${cur})) return 0 } complete -o filenames -F _ebuild ebuild