# # This function completes package names. # The function has one mandatory parameter: # -A Search all available packages (except for those in the overlays) # -I Only search the installed packages # # Note: $cur is used and altered by this function. # _pkgname() { # Don't clobber the users $OLDPWD local oldpwd oldpwd=$OLDPWD # Ignore '=' at the beginning of the current completion [[ ${cur:1:1} == "=" ]] && cur=${cur:2} [[ ${cur:0:1} == "=" ]] && cur=${cur:1} case $1 in -I) cd /var/db/pkg/ # Complete either the category or the complete package name if [[ $cur == */* ]] then COMPREPLY=($(compgen -W "$(compgen -G "$cur*" )" -- $cur)) else COMPREPLY=($(compgen -W "$(compgen -G "$cur*" -S /)" -- $cur)) fi # We may just have finished completing the category. # Make sure there isn't anything more to complete now. if [ ${#COMPREPLY[@]} == 1 ] then COMPREPLY=($(compgen -W "$(compgen -G "$COMPREPLY*")" -- $cur)) fi cd $OLDPWD ;; -A) # Complete either the category or the complete package name if [[ $cur == */* ]] then # Once the category has been completed, it's safe to use /usr/portage/ # to continue completion. cd /usr/portage/ COMPREPLY=($(compgen -W "$(compgen -G "${cur}*")" -- "${cur}")) cd $OLDPWD # When we've completed most of the name, also display the version for # possible completion if [[ ${#COMPREPLY[@]} -le 1 || ${cur:${#cur}-1:1} == "-" ]] && [[ ${cur} != */ ]] then # The portage cache is appropriate to complete specific versions from cd /usr/portage/metadata/cache/ COMPREPLY=(${COMPREPLY[@]} $(compgen -W "$(compgen -G "${cur}*")" -- "${cur}")) cd $OLDPWD fi else # For completing categories, it's easiest to use the portage cache cd /usr/portage/metadata/cache/ COMPREPLY=($(compgen -W "$(compgen -G "$cur*" -S /)" -- $cur)) # Are we done completing the category? if [ ${#COMPREPLY[@]} == 1 ] then COMPREPLY=($(compgen -W "$(compgen -G "$COMPREPLY*")" -- $cur)) fi cd $OLDPWD fi ;; *) # Somebody screwed up! :-) ;; esac # 'equery' wants a '=' in front of specific package versions. # Add it if there is only one selected package and it isn't there already. [[ ${#COMPREPLY[@]} == 1 && ${COMP_WORDS[COMP_CWORD]:0:1} != "=" ]] && COMPREPLY=("="$COMPREPLY) OLDPWD=$oldpwd } # # Bash completion for the Gentoo 'equery' command # _equery() { local cur prev local mode local i j mode="GLOBAL" COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} # Find out what we're currently doing here. j=0 for i in "${COMP_WORDS[@]}" do if [ $j -lt $COMP_CWORD ] then j=$(( j + 1 )) case $i in files|stats|list|glsa|depends|belongs|uses|which|depgraph|changes|check|size) mode=$i ;; esac fi done case $mode in GLOBAL) # Complete commands and global options. case $cur in -*) COMPREPLY=($(compgen -W "-q --quiet -C --nocolor -h --help -V --version" -- $cur)) ;; *) COMPREPLY=($(compgen -W "files stats list glsa depends belongs uses which depgraph changes check size" -- $cur)) ;; esac ;; stats|glsa|depends|changes) # These commands have not been implemented in 'equery' yet ... echo -n "# Not implemented! " ;; files) # Only complete if the previous entry on the command line is not # a package name. if [[ ${prev} == ${mode} || ${prev:0:1} == "-" ]] then case $cur in -*) COMPREPLY=($(compgen -W "--timestamp --md5sum --type" -- $cur)) ;; *) # Only installed packages can have their files listed. _pkgname -I ;; esac fi ;; list) # Only complete if the previous entry on the command line is not # a package name. if [[ ${prev} == ${mode} || ${prev:0:1} == "-" ]] then case $cur in -*) COMPREPLY=($(compgen -W "-i --installed -I --exclude-installed -p --portage-tree -o --overlay-tree" -- $cur)) ;; *) # Complete on all package names. _pkgname -A ;; esac fi ;; belongs) # Only complete if the previous entry on the command line is not # a file name. if \ [[ \ ${prev} == ${mode} || \ ${prev:0:1} == "-" || \ ${COMP_WORDS[COMP_CWORD-2]} == "-c" || \ ${COMP_WORDS[COMP_CWORD-2]} == "--category" \ ]] && \ [[ \ ${prev} != "-c" && \ ${prev} != "--category" \ ]] then case $cur in -*) COMPREPLY=($(compgen -W "-c --category -e --earlyout" -- $cur)) ;; *) # Complete filenames. Function defined in /etc/bash_completion. _filedir ;; esac # Are we completing a category? elif [[ ${prev} == "-c" || ${prev} == "--category" ]] then local oldpwd oldpwd=$OLDPWD cd /usr/portage/metadata/cache/ COMPREPLY=($(compgen -W "$(compgen -G '*')" -- $cur)) cd $OLDPWD OLDPWD=$oldpwd fi ;; uses) # Only complete if the previous entry on the command line is not # a package name. if [[ ${prev} == ${mode} ]] then # Complete on all package names. _pkgname -A fi ;; which) # Only complete if the previous entry on the command line is not # a package name. if [[ ${prev} == ${mode} ]] then # Complete on all package names. _pkgname -A fi ;; depgraph) # Only complete if the previous entry on the command line is not # a package name. if [[ ${prev} == ${mode} || ${prev:0:1} == "-" ]] then case $cur in -*) COMPREPLY=($(compgen -W "-U --no-useflags -l --linear" -- $cur)) ;; *) # Complete on all package names. _pkgname -A ;; esac fi ;; check) # Only complete if the previous entry on the command line is not # a package name. if [[ ${prev} == ${mode} ]] then # Only installed packages can have their integrity verified. _pkgname -I fi ;; size) # Only complete if the previous entry on the command line is not # a package name. if [[ ${prev} == ${mode} || ${prev:0:1} == "-" ]] then case $cur in -*) COMPREPLY=($(compgen -W "-b --bytes" -- $cur)) ;; *) # Only installed packages can have their size calculated. _pkgname -I ;; esac fi ;; esac return 0 } complete -F _equery -o filenames equery