# Gentoo emerge completion. # have emerge && _emerge() { local cur prev grepcmd sedcmd systemactions setsma setbig portagedir usepkg # This is where the packages are found unless '--usepkg' is specified. portagedir=/usr/portage COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--pretend \ --autoclean \ --usepkg \ --buildpkg' | grep ^$cur ) ) else if [ "$prev" == "--usepkg" ]; then if [ -e "${PKGDIR}" ]; then portagedir=${PKGDIR} else portagedir="/usr/portage/packages" fi usepkg="TRUE" COMPREPLY=( $( compgen -f $cur ) ) fi cd ${portagedir} grepcmd="grep -E ^$cur.*" sedcmd="sed -e /CVS/d \ -e /BUGS-TODO/d \ -e /ChangeLog.*/d \ -e /header.txt/d \ -e /skel.build/d \ -e /distfiles/d \ -e /eclass/d \ -e /files/d \ -e /incoming/d \ -e /packages/d \ -e /profiles/d \ -e /All/d \ -e /scripts/d" if [ "${usepkg}" ]; then setsma="`compgen -G "*/" | $sedcmd`" setbig="`compgen -G "*/*" | $sedcmd`" else systemactions=$'\n'"system"$'\n'"upgrade" setsma="`compgen -S '/' -G "*" | $sedcmd`"$systemactions setbig="`compgen -G "*/*" | $sedcmd`"$systemactions fi if [ $cur ]; then if [ `echo $cur | grep '/'` ]; then COMPREPLY=( $( echo "$setbig" | $grepcmd ) ) else if [ `echo "$setsma" | $grepcmd | grep '/' | wc -l` = 1 ]; then COMPREPLY=( $( echo "$setbig" | $grepcmd ) ) else COMPREPLY=( $( echo "$setsma" | $grepcmd ) ) fi fi else COMPREPLY=( $( echo "$setsma" ) ) fi fi return 0 } [ "$have" ] && complete -F _emerge emerge