--- gentoo-bashcomp-1.0_beta4/src/gentoo 2005-01-12 06:26:08.380227552 -0500 +++ gentoo-bashcomp/src/gentoo 2005-01-12 06:25:05.153839424 -0500 @@ -12,7 +12,7 @@ # _portdir() { - sed -n -e '/^PORTDIR=/ { s/^[^=]\+=\("[^"]\+\|\S\+\).*/\1/p ; q }' \ + sed -n -e '/^PORTDIR=/ { s/^[^=]\+="\?\([^"]\+\|\S\+\).*/\1/p ; q }' \ /etc/make.conf /etc/make.globals } @@ -272,7 +272,7 @@ cur=${COMP_WORDS[COMP_CWORD]} if [ $COMP_CWORD -eq 1 ]; then #COMPREPLY=($(compgen -o filenames -X "!*.ebuild" $cur)) - COMPREPLY=($(compgen -o filenames)) + COMPREPLY=($(compgen -o filenames -A file -W "--debug" -- ${cur})) elif [ $COMP_CWORD -eq 2 ]; then COMPREPLY=($(compgen -W 'clean compile config \ depend digest \ @@ -292,10 +292,27 @@ } # -# simple completion for Gentoo style init +# Gentoo init.d completion # -complete -W "start stop restart pause zap ineed needsme iuse usesme broken" \ - $(for i in /etc/init.d/*; do echo ${i##*/}; done) + +_gentoo_style_init() +{ + local script="${COMP_WORDS[0]}" + local cur="${COMP_WORDS[$COMP_CWORD]}" + + if [[ ( -f "${script}" || -h "${script}" ) && -r "${script}" ]] \ + && [[ "${script}" != *.sh ]] \ + && [[ "$(head -n 1 "${script}")" = "#!/sbin/runscript" ]]; then + [[ $COMP_CWORD -gt 1 ]] && return 1 + COMPREPLY=($(opts="start stop status restart pause zap ineed needsme iuse usesme broken"; eval "$(grep '^opts=' "${script}")"; echo "${opts}")) + [[ "$COMPREPLY" ]] || COMPREPLY=(start stop restart zap) + COMPREPLY=($(compgen -W "${COMPREPLY[*]}" -- "${cur}")) + else + COMPREPLY=($(compgen -o default -- "${cur}")) + fi + return 0 +} +complete -F _gentoo_style_init /etc/init.d/* # # rc completion command @@ -730,7 +747,7 @@ for i in "${COMP_WORDS[@]}"; do if [ $j -lt $COMP_CWORD ]; then j=$((j + 1)) - case $i in @(belongs|ch@(anges|eck)|dep@(ends|graph)|files|glsa|list|s@(ize|tats)|uses|which)) + case $i in @(belongs|ch@(anges|eck)|dep@(ends|graph)|files|glsa|list|s@(ize|tats)|uses|which|hasuse)) mode=$i ;; esac @@ -745,11 +762,11 @@ COMPREPLY=($(compgen -W "-q --quiet -C --nocolor -h --help -V --version" -- $cur)) ;; *) - COMPREPLY=($(compgen -W "belongs changes check depends depgraph files glsa list size stats uses which" -- $cur)) + COMPREPLY=($(compgen -W "belongs changes check depends depgraph files glsa hasuse list size stats uses which" -- $cur)) ;; esac ;; - changes|depends|glsa|stats) + changes|glsa|stats) # These commands have not been implemented in 'equery' yet ... echo -n "# Not implemented! " ;; @@ -829,9 +846,32 @@ COMPREPLY=($(compgen -W "-U --no-useflags -l --linear" -- $cur)) ;; *) - # Complete on all package names. - _pkgname -A $cur + # Complete on installed package names. + _pkgname -I $cur + ;; + esac + fi + ;; + depends) + # 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 "-a --all-packages -d --direct -D --indirect" -- $cur)) ;; + *) + case $prev in + -a|--all-packages) + # Complete on all package names. + _pkgname -A $cur + ;; + *) + # Complete on installed package names. + _pkgname -I $cur + ;; + + esac esac fi ;; @@ -858,12 +898,33 @@ esac fi ;; + hasuse) + # 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" -- $cur)) + ;; + *) + local glob loc + glob=$(sed -n -e 's/^\([^ ]\+\) - .*$/\1/p' ${portdir}/profiles/use.desc) + loc=$(sed -n -e 's/^[^ ]\+:\([^ ]*\) - .*$/\1/p' ${portdir}/profiles/use.local.desc) + COMPREPLY=($(compgen -W "$glob $loc" -- $cur)) + ;; + esac + fi + ;; esac return 0 } complete -F _equery -o filenames equery } +# +# ekeyword completion +# + have ekeyword && { _ekeyword() {