From 815a24e2de9764022943d24fa81621c185cbab90 Mon Sep 17 00:00:00 2001 From: Tim Harder Date: Fri, 21 Nov 2014 09:02:24 -0500 Subject: move completions into src subdir --- src/_eselect | 197 ++++++++++++++++++++++++++ src/_gcc-config | 27 ++++ src/_genlop | 103 ++++++++++++++ src/_gentoo_packages | 309 +++++++++++++++++++++++++++++++++++++++++ src/_gentoolkit | 382 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/_layman | 51 +++++++ src/_openrc | 85 ++++++++++++ src/_portage | 364 ++++++++++++++++++++++++++++++++++++++++++++++++ src/_portage_utils | 270 ++++++++++++++++++++++++++++++++++++ 9 files changed, 1788 insertions(+) create mode 100644 src/_eselect create mode 100644 src/_gcc-config create mode 100644 src/_genlop create mode 100644 src/_gentoo_packages create mode 100644 src/_gentoolkit create mode 100644 src/_layman create mode 100644 src/_openrc create mode 100644 src/_portage create mode 100644 src/_portage_utils (limited to 'src') diff --git a/src/_eselect b/src/_eselect new file mode 100644 index 0000000..c012955 --- /dev/null +++ b/src/_eselect @@ -0,0 +1,197 @@ +#compdef eselect + +common_values=( + "help[Display help text]" + "usage[Display usage information]" + "version[Display version information]" +) + +_eselect_env () { + if (( $words[(I)(update)] )); then + _values "update options" \ + "makelinks[force updating of links]" \ + "noldconfig[Do not alter the ld.so cache or configuration]" && return 0 + fi + _values "env options" $common_values \ + 'update[Collect environment variables from all scripts in /etc/env.d/]' && return 0 +} + +_eselect_binutils () { + local binutilslist + if (( $words[(I)(set)] )); then + binutilslist=(${(f)"$(eselect --brief --color=no binutils list)"}) + _values "available binutils version" $binutilslist[@] && return 0 + fi + _values "binutils options" $common_values \ + "list[List all installed version of binutils]" \ + "show[Print the currently active binutils version]" \ + "set[Activate one of the installed binutils]" && return 0 +} + +_eselect_kernel () { + local kernellist + if (( $words[(I)(set)] )); then + kernellist=(${(f)"$(eselect --brief --color=no kernel list)"}) + _values "available kernel version" $kernellist[@] && return 0 + fi + _values "kernel options" $common_values \ + "list[List available kernel symlink targets]" \ + "show[Show the current kernel symlink]" \ + "set[Set a new kernel symlink target]" && return 0 +} + +_eselect_ctags () { + local ctagslist + if (( $words[(I)(set)] )); then + ctagslist=(${(f)"$(eselect --brief --color=no ctags list)"}) + _values "available ctags version" $ctagslist[@] && return 0 + fi + _values "ctags options" $common_values \ + "list[List available ctags symlink targets]" \ + "show[Show the current target of the ctags symlink]" \ + "update[Automatically update the ctags symlink]" \ + "set[Set a new ctags symlink target]" && return 0 +} + +_eselect_profile () { + local profilelist + if (( $words[(I)(set)] )); then + profilelist=(${${(f)"$(eselect --brief --color=no profile list)"}/:/\\:}) + _values -w "available profiles" $profilelist[@] \ + "--force[Forcibly set the symlink]" && return 0 + fi + _values "profile options" $common_values \ + "list[List available profile symlink targets]" \ + "show[Show the current make.profile symlink]" \ + "set[Set a new profile symlink target]" && return 0 +} + +_eselect_fontconfig () { + local fclistenabled fclistdisabled + if (( $words[(I)(enable)] )); then + fclistdisabled=(${${${${(M)${(f)"$(eselect --color=no fontconfig list)"}## *}#*\*}// \**/}//( \[*\] | \[*\] )/}) + _values -w ".conf to enable" $fclistdisabled[@] && return 0 + elif (( $words[(I)(disable)] )); then + fclistenabled=(${${${(M)${(M)${(f)"$(eselect --color=no fontconfig list)"}## *}#*\*}// \**/}//( \[*\] | \[*\] )/}) + _values -w ".conf to disable" $fclistenabled[@] && return 0 + fi + _values "fontconfig options" $common_values \ + "list[List available fontconfig .conf files]" \ + "disable[Disable specified fontconfig .conf file(s)]" \ + "enable[Enable specified fontconfig .conf file(s)]" && return 0 +} + +_eselect_opengl () { + local opengllist + if (( $words[(I)(set)] )); then + opengllist=(${(f)"$(eselect --brief --color=no opengl list)"}) + _values -w "opengl implementations and options" $opengllist[@] \ + "--use-old[If an implementation is already set, use that one instead]" \ + "--prefix[Set the source prefix]:path:_files -/" \ + "--dst-prefix[Set the destination prefix]:path:_files -/" \ + "--ignore-missing[Ignore missing files when setting a new implementation]" && return 0 + fi + _values "opengl options" $common_values \ + "list[List the available OpenGL implementations]" \ + "set[Select the OpenGL implementation]" \ + "show[Print the current OpenGL implementation]" && return 0 +} + +_eselect_vi () { + local vilist + if (( $words[(I)(set)] )); then + vilist=(${(f)"$(eselect --brief --color=no vi list)"}) + _values -w "vi implementation" $vilist[@] && return 0 + elif (( $words[(I)(update)] )); then + _values -w "option" "--if-unset[Do not override existing implementation]" && return 0 + fi + _values "vi options" $common_values \ + "list[List available vi implementations]" \ + "set[Set a new vi implementation provider]" \ + "show[Show the current vi implementation]" \ + "update[Automatically update the vi provider]" +} + +_eselect_news() { + + ## TODO: Normal numeric sorting. + ## I've spent many time on trying to rewrite this + ## function to normally sort (to DO NOT sort, actually) items, + ## but it growing bigger and bigger and going to be too complicated. + ## So, I (mva) either need to help to make it in the "right way". + ## Or, maybe, to completely rewrite this compdef. + + local -a newslist; + if ((CURRENT == 3)); then + _values 'news options' $stdopts[@] \ + 'list[List news items]' \ + 'count[Display number of news items]' \ + 'purge[Purge read news]' \ + 'read[Read news items]' \ + 'unread[Mark read news items as unread again]' && return 0 + elif ((CURRENT == 4)); then + if (( $words[(I)(count)] )); then + _values -w 'news' 'new[Count only new news items]' 'all[Count all news items]' && return 0 + fi + + newslist=(${${${${${${${(M)${(f)"$(eselect --color=no news list)"}## *}// \**/}/ \[/}/\] ##/\[}/%/]}/ \[/ (}/\] /) }) + + if (( $words[(I)(read)] )); then + newslist+=( "new[Read unread news items (default)]" "all[Read all news items]" "--mbox[Output in mbox format]" "--quiet[Suppress output, only change status]" "--raw[Output in raw format]" ) + fi; + + if (( $words[(I)(unread)] )); then + newslist+=( "all[Unread all news items]" ) + fi + + _values -w 'news' $newslist[@] && return 0 + fi +} + +_eselect () { + local globopts modnames modopts + + globopts=( + "--brief[Make output shorter]" + "--colour=no[Disable coloured output]" + "--color=no[Disable coloured output]" + ) + modnames=(${${${(M)${(f)"$(eselect --brief --color=no modules list)"}## *}// */}// /}) + + if ((CURRENT == 2)); then + _arguments -s \ + "$globopts[@]" \ + "*:portage:_values 'eselect modules' \$modnames[@]" && return 0 + elif ((CURRENT == 3)); then + if [[ $words[2] == --colour=no || $words[2] == --color=no ]]; then + _arguments -s \ + "*:portage:_values 'eselect modules' \$modnames[@]" && return 0 + elif (( $modnames[(I)$words[2]] )); then + if [[ "$words[2]" == (env|binutils|kernel|ctags|profile|fontconfig|opengl|vi|news) ]]; then + _eselect_$words[2] "$@" + else + modopts=(${${${(M)${(f)"$(eselect --brief --color=no $words[2] usage)"}## *}// */}// /}) + _arguments -s \ + "*:portage:_values 'eselect $words[2] options' \$modopts[@]" && return 0 + fi + fi + elif ((CURRENT >= 4)); then + if (( $words[(I)(--color=no|--colour=no)] )); then + if (( $modnames[(I)$words[3]] )); then + if [[ "$words[3]" == (env|binutils|kernel|ctags|profile|fontconfig|opengl|vi|news) ]]; then + _eselect_$words[3] "$@" + else + modopts=(${${${${(M)${(f)"$(eselect --brief --color=no $words[3] usage)"}## *}// */}// /}// *}) + _arguments -s \ + "*:portage:_values 'eselect $words[3] options' \$modopts[@]" && return 0 + fi + fi + else + if (( $modnames[(I)$words[2]] )); then + (( $+functions[_eselect_$words[2]] )) && _eselect_$words[2] "$@" + fi + fi + fi +} + +_eselect "$@" diff --git a/src/_gcc-config b/src/_gcc-config new file mode 100644 index 0000000..3b0fcf3 --- /dev/null +++ b/src/_gcc-config @@ -0,0 +1,27 @@ +#compdef gcc-config +#Author oberyno + +local arguments + +arguments=( + '(- :)'{--use-old,-O}'[use the old profile if one was selected]' + '(- :)'{--use-portage-chost,-P}'[only set profile if its CHOST matches /etc/{portage/}make.conf]:profiles:_gcc_profile' + '(- :)'{--get-current-profile,-c}'[print current used gcc profile]' + '(- :)'{--list-profiles,-l}'[print a list of available profiles]' + '(- :)'{--print-environ,-E}'[print environment of the given/current profile]:profiles:_gcc_profile' + '(- :)'{--get-bin-path,-B}'[print binary path of given/current profile]:profiles:_gcc_profile' + '(- :)'{--get-lib-path,-L}'[print library path of given/current profile]:profiles:_gcc_profile' + '(- :)'{--get-stdcxx-incdir,-X}'[print g++ include path of given/current profile]:profiles:_gcc_profile' + '(- :)'{--help,-h}'[show help]' + '(- :)'{--version,-v}'[show version info]' + '(- :):profiles:_gcc_profile' +) + +_gcc_profile(){ + local profile + profile=(${(f)"$(_call_program gcc-installed RC_NOCOLOR=yes gcc-config --list-profiles)"}) + profile=${${profile/\[([^]]*)\]/}/\*} + _tags profile && { compadd "$@" -k profile || compadd "$@" ${(kv)=profile} } +} + +_arguments $arguments diff --git a/src/_genlop b/src/_genlop new file mode 100644 index 0000000..322babb --- /dev/null +++ b/src/_genlop @@ -0,0 +1,103 @@ +#compdef genlop + +#genlop 0.30.8 +_genlop () { +local prev1="$words[CURRENT-1]" prev2="$words[CURRENT-2]" days months arg single state lstate +days=(monday tuesday wednesday thursday friday saturday sunday) +months=(january february march april may june july august september october november december) +arg=( --current -c --time -t --gmt -g --info -i --file -f --rsync -r --unmerge -u --date --search -s --list -l ) +single=( --current -c --pretend -p --help -h --version -v ) + + [[ ${prev2} == (1st|2nd|3rd|4th|5th) ]] && + compadd in\ $months && return 0 + [[ ${prev1} == ([2-9]|[1-9][0-9]*) && ${prev2} != \ + (january|february|march|april|may|june|july|august|september|october|november|december) ]] && + _values '' 'days ago' 'months ago' 'years ago' 'weeks ago' && return 0 + [[ ${prev1} == (1) && ${prev2} != \ + (january|february|march|april|may|june|july|august|september|october|november|december) ]] && + _values '' 'day ago' 'month ago' 'year ago' 'week ago' && return 0 + + case "$prev1" in + last) + _values '' month week + compadd $days && return 0 + ;; + 1st|2nd|3rd|4th|5th) + compadd $days && return 0 + ;; + january|february|march|april|may|june|july|august|september|october|november|december) + compadd {1..31} && return 0 + ;; + --date) + _message 'enter number for more options or use mm/dd/yyyy format' + _values '' \ + last yesterday 1st 2nd 3rd 4th 5th + _alternative \ + '*:*:_days' '*:*:_months' && return 0 + ;; + --file|-f) + _arguments '*:logfile:_files' && return 0 + ;; + *) + _arguments \ + "($single $arg *)"{--current,-c}"[display the current merge in action]" \ + "($single)*--date[specify date of event]:date:->date" \ + "($single)*-f[specify the logfile to use]:logfile:_files" \ + "($single --gmt -g)"{--gmt,-g}"[display time in GMT/UTC format (default is local time)]" \ + "($single $arg *)"{--help,-h}"[display help information]" \ + "($single --info -i --list -l)"{--info,-i}"[print brief summary about installed ebuild]" \ + "($single --search -s --info -i --list -l *)"{--list,-l}"[list merge history]" \ + "(--nocolor -n)"{--nocolor,-n}"[disable colored output]" \ + "($single $arg *)"{--pretend,-p}"[estimate build time of a piped emerge -p]" \ + "($single --search -s --info -i --time -t --unmerge -u --rsync -r *)"{--rsync,-r}"[display rsync history]" \ + "($single --rsync -r --search -s --list -l *)"{--search,-s}"[select ebuilds matching the provided regular expression]:pattern:" \ + "($single --time -t)"{--time,-t}"[display merge time]" \ + "($single --rsync -r --unmerge -u)"{--unmerge,-u}"[display when packages have been unmerged]" \ + "($single $arg *)"{--version,-v}"[display version information]" \ + "($single)*:package:_gentoo_packages available" + ;; + esac + + while [[ -n "$state" ]]; do + lstate=$state + state='' + case "$lstate" in + date) _message 'enter number for more options or use mm/dd/yyyy format' + _values '' \ + last yesterday 1st 2nd 3rd 4th 5th + _alternative \ + ':*:_days' ':*:_months' && return 0 + ;; + esac + done +} + +_days() { + local m="monday" t="tuesday" w="wednesday" T="thursday" f="friday" s="saturday" S="sunday" + local day=$(date +%u) + if [[ ${day} == 1 ]] then compadd $m + elif [[ ${day} == 2 ]] then compadd $m $t + elif [[ ${day} == 3 ]] then compadd $m $t $w + elif [[ ${day} == 4 ]] then compadd $m $t $w $T + elif [[ ${day} == 5 ]] then compadd $m $t $w $T $f + elif [[ ${day} == 6 ]] then compadd $m $t $w $T $f $s + elif [[ ${day} == 7 ]] then compadd $m $t $w $T $f $s $S + fi +} +_months() { + local j="january" f="february" m="march" a="april" M="may" ju="june" J="july" A="august" s="september" o="october" n="november" d="december" + local month=$(date +%m) + if [[ ${month} == 01 ]] then compadd $j + elif [[ ${month} == 02 ]] then compadd $j $f + elif [[ ${month} == 03 ]] then compadd $j $f $m + elif [[ ${month} == 04 ]] then compadd $j $f $m $a + elif [[ ${month} == 05 ]] then compadd $j $f $m $a $M + elif [[ ${month} == 06 ]] then compadd $j $f $m $a $M $ju + elif [[ ${month} == 07 ]] then compadd $j $f $m $a $M $ju $J + elif [[ ${month} == 08 ]] then compadd $j $f $m $a $M $ju $J $A + elif [[ ${month} == 09 ]] then compadd $j $f $m $a $M $ju $J $A $s + elif [[ ${month} == 10 ]] then compadd $j $f $m $a $M $ju $J $A $s $o + elif [[ ${month} == 11 ]] then compadd $j $f $m $a $M $ju $J $A $s $o $n + elif [[ ${month} == 12 ]] then compadd $j $f $m $a $M $ju $J $A $s $o $n $d + fi +} diff --git a/src/_gentoo_packages b/src/_gentoo_packages new file mode 100644 index 0000000..9a747b7 --- /dev/null +++ b/src/_gentoo_packages @@ -0,0 +1,309 @@ +#autoload + +setopt extendedglob bareglobqual +#Description: +# functions for gentoo packages +# inspired by _deb_packages +#Usage: _gentoo_packages installed|available|installed_versions|available_versions|binary|category|useflag + + +_portdir() { + local mainreponame mainrepopath overlayname overlaypath + + if [[ -e /usr/share/portage/config/repos.conf ]]; then + if [[ ${1} == -o ]]; then + for overlayname in $(_parsereposconf -l); do + overlaypath+=($(_parsereposconf ${overlayname} location)) + done + + source /etc/make.conf 2>/dev/null + source /etc/portage/make.conf 2>/dev/null + + overlaypath+=(${(@)PORTDIR_OVERLAY}) + + echo "${(@u)overlaypath}" + else + mainreponame=$(_parsereposconf DEFAULT main-repo) + mainrepopath=$(_parsereposconf ${mainreponame} location) + + echo "${mainrepopath}" + fi + else + source /usr/share/portage/config/make.globals 2>/dev/null + source /etc/make.conf 2>/dev/null + source /etc/portage/make.conf 2>/dev/null + + if [[ "-o" == ${1} ]]; then + echo "${(@u)PORTDIR_OVERLAY}" + else + echo "${PORTDIR}" + fi + fi +} + +_parsereposconf() { + local v f insection section arr; + + for f in /usr/share/portage/config/repos.conf \ + /etc/portage/repos.conf \ + /etc/portage/repos.conf/*.conf; do + + [[ -f ${f} ]] || continue + insection=0; + declare -A arr; + IFS='= '; + + while read -r name value; do + [[ -z ${name} || ${name} == '#'* ]] && continue + + if [[ (${name} == '['*']') && (-z ${value}) ]]; then + value=${name//(\]|\[)}; + name="section"; + fi; + arr[${name}]=${value}; + + if [[ ${insection} == 1 && ${name} == "section" ]]; then + break + elif [[ ${name} == "section" ]]; then + [[ ${value} == ${1} ]] && insection=1 + secname+=(${value}) + elif [[ ${insection} == 1 ]]; then + if [[ ${name} == ${2} ]]; then + v=${value}; + fi + fi + continue + done < ${f} + done + + if [[ "-l" == ${1} ]]; then + echo "${(@)secname}" + else + echo "${v}" + fi +} + +_parsesetsconf() { + [[ -d ${1} ]] || continue + + local v f places sections setsconf insection section arr; + + if [[ -d ${1}/sets ]]; then + setsconf=(${1}/sets/*.conf(N)); + [[ (($#setsconf > 0)) ]] && places=(${setsconf}) + elif [[ -f ${1}/sets.conf ]]; then + places=(${1}/sets.conf) + fi + + for f in ${(@)places}; do + if [[ -r ${f} ]]; then + insection=0; + declare -A arr; + IFS='= '; + while read -r name value; do + [[ -z ${name} || ${name} == '#'* ]] && continue + + if [[ (${name} == '['*']') && (-z ${value}) ]]; then + value=${name//(\]|\[)}; + name="section"; + fi; + arr[${name}]=${value}; + + if [[ ${insection} == 1 && ${name} == "section" ]]; then + [[ "sets" == ${2} ]] && [[ ! ${value} =~ "sets" ]] && sections+=(${value}) + insection=0; + elif [[ ${name} == "section" ]]; then + [[ ${value} =~ "${1:t} sets" ]] && insection=1 + [[ "sets" == ${2} ]] && [[ ! ${value} =~ "sets" ]] && sections+=(${value}) + elif [[ ${insection} == 1 ]]; then + [[ "sets" == ${2} ]] && continue + if [[ ${name} == "directory" ]]; then + v=${value}; + fi + fi + continue + done < ${f} + fi + done + + if [[ "sets" == ${2} ]]; then + [[ ((${#sections} > 0)) ]] && echo ${(@)sections} + else + [[ ((${#v} > 0)) ]] && echo ${v:t}; + fi +} + +_gentoo_packages_update_installed_sets() { + local sets; + sets=($( 0)) ]]; then + _wanted installed_sets expl 'installed set' compadd "$@" "${(o@)^sets}" + fi +} + +_gentoo_packages_update_available_sets() { + trees=($(_portdir -o) /etc/portage /usr/share/portage/config) + for PORTDIR in ${(@)trees}; do + if [[ -d ${PORTDIR} ]]; then + setsdir="$(_parsesetsconf ${PORTDIR})" + [[ ! -z "${setsdir}" ]] && setspath="${PORTDIR}/${setsdir}" || setspath="${PORTDIR}/sets" + if [[ -d "${setspath}" ]]; then + setsfiles=(${setspath}/*~*.conf(N)) + for set in ${setsfiles[@]}; do + sets+=(${set}(:t)) + done; + sets+=($(_parsesetsconf ${PORTDIR} sets)) + fi + fi + done + if [[ ((${#sets} > 0)) ]]; then + _wanted available_sets expl 'available set' compadd "$@" "@${(o@)^sets}" + fi +} + +# Completion function to show useflags. +_gentoo_packages_update_useflag(){ + local flags trees + + flags=() + trees=($(_portdir) $(_portdir -o)) + + for PORTDIR in ${trees[@]}; do + [[ -r ${PORTDIR}/profiles/use.desc ]] && + flags+=(${${(M)${(f)"$(<$PORTDIR/profiles/use.desc)"}:#* - *}%% - *}) + [[ -r ${PORTDIR}/profiles/use.local.desc ]] && + flags+=(${${${(M)${(f)"$(<$PORTDIR/profiles/use.local.desc)"}#* - *}%% - *}#*:}) + done + + compadd $flags +} + +_gentoo_packages_update_active_useflag(){ + local flags USE + var=USE + [[ -z ${(P)var} && -r /etc/portage/make.conf ]] && + local $var="`. /etc/portage/make.conf 2>/dev/null; echo ${(P)var}`" + [[ -z ${(P)var} && -r /etc/make.conf ]] && + local $var="`. /etc/make.conf 2>/dev/null; echo ${(P)var}`" + flags=(${${${=USE}%-*}%\\*}) + compadd $flags +} +_gentoo_packages_update_category(){ + local trees category + + trees=($(_portdir) $(_portdir -o)) + category=( $trees/*-*(/:t) ) + _wanted cat_packages expl 'category' compadd "$@" $category +} + +_gentoo_packages_update_installed(){ + local installed_dir installed_portage installed_list expl + installed_dir="/var/db/pkg" + installed_portage=($installed_dir/*-*/*) + + installed_pkgname=(${${installed_portage:t}%%-[0-9]*}) + _wanted packages expl 'package' compadd "$@" ${installed_pkgname} + + installed_list=( ${${installed_portage#$installed_dir/}%%-[0-9]*} ) + _wanted cat_packages expl 'category/package' _multi_parts "$@" / installed_list +} + +_gentoo_packages_update_installed_versions(){ + local installed_list installed_portage expl + + installed_portage=(/var/db/pkg/*-*/*) + _wanted packages expl 'package' compadd "$@" ${installed_portage:t} + + installed_list=(${installed_portage##*/pkg/}) + _wanted cat_packages expl 'category/package' _multi_parts "$@" / installed_list +} + +_gentoo_packages_update_available_pkgnames_only(){ + local trees packages + + trees=($(_portdir) $(_portdir -o)) + + packages=($trees/*-*/*(:t)) + _wanted packages expl 'package' compadd - "${(@)packages}" +} + +_gentoo_packages_update_available(){ + local trees category packages pkg expl + + trees=($(_portdir) $(_portdir -o)) + category=($trees/*-*(/:t)) + + packages=($trees/*-*/*(:t)) + _wanted packages expl 'package' compadd - "${(@)packages}" + + # Complete cat/pkg. _multi_parts is much to slow for such a large task, + # _sep_parts removes the dash from gnome-, and _path_files wants to + # complete cat/pkg/files (if "files" is ignored with -F, miscfiles, etc... + # don't get completed). + if [[ $PREFIX != */* ]] ; then + _wanted cat_packages expl 'category/package' compadd -S '/' $category + else + compset -P '*/' + pkg=($trees/$IPREFIX/*(:t)) + _wanted cat_packages expl 'category/package' compadd $pkg + fi +} + +_gentoo_packages_update_available_versions(){ + local var overlay_ebuilds portage_ebuilds expl trees category + + PORTDIR=$(_portdir) + PORTDIR_OVERLAY=$(_portdir -o); + + trees=($PORTDIR $=PORTDIR_OVERLAY) + category=($trees/*-*(/:t)) + typeset -U category + + if [[ $#PREFIX -ge 1 && -z $words[(r)(--inject|-i)] ]] ; then + overlay_ebuilds=($=PORTDIR_OVERLAY/*-*/${PREFIX%%-[0-9]#*}*/*.ebuild(:t:r) ) + portage_ebuilds=($PORTDIR/metadata/cache/*-*/${PREFIX%%-[0-9]#*}*(:t)) + _wanted packages expl 'package' compadd $portage_ebuilds $overlay_ebuilds + fi + pkg=( $trees/${PREFIX%%/*}/*/*.ebuild(:t:r) ) + _wanted cat_packages expl 'category/package' _sep_parts category / pkg +} + +#Function to show tbz2 files available +_gentoo_packages_update_binary() { + [[ -z $PKGDIR && -r /etc/portage/make.conf ]] && + local PKGDIR="`. /etc/portage/make.conf 2>/dev/null; echo $PKGDIR`" + [[ -z $PKGDIR && -r /etc/make.conf ]] && + local PKGDIR="`. /etc/make.conf 2>/dev/null; echo $PKGDIR`" + [[ -z $PKGDIR && -r /usr/share/portage/config/make.globals ]] && + local PKGDIR="`. /usr/share/portage/config/make.globals 2>/dev/null; echo $PKGDIR`" + + # this doesn't take care of ${PORTAGE_BINHOST}. If Gentoo official + # binary mirror will be available we should rewrite it accordingly. + _path_files -g \*.tbz2 -W "$PKGDIR/All" +} + +_gentoo_packages () { + local command="$argv[$#]" expl cachevar pkgset update_policy + zstyle -s ":completion:*:*:$service:*" cache-policy update_policy + if [[ -z "$update_policy" ]]; then + zstyle ":completion:*:*:$service:*" cache-policy _gentoo_cache_policy + fi + [[ "$command" == (installed(_versions|_sets|)|available(_versions|_sets|_pkgnames_only|)|binary|category|(active_|)useflag) ]] || { + _message "unknown command: $command" + return + } + [[ "$pkgset" == (installed(_versions|_sets|)|available(_versions|_sets|_pkgnames_only|)|binary|category|(active_|)useflag) ]] || { + pkgset="$command" + } + expl=("${(@)argv[1,-2]}") + _gentoo_packages_update_$pkgset +} + +_gentoo_cache_policy () { + # rebuild if cache is more than a week old + oldp=( "$1"(mw+1) ) + (( $#oldp )) && return 0 +} + + +_gentoo_packages "$@" diff --git a/src/_gentoolkit b/src/_gentoolkit new file mode 100644 index 0000000..ef3db9a --- /dev/null +++ b/src/_gentoolkit @@ -0,0 +1,382 @@ +#compdef equery euse eclean eclean-dist eclean-pkg epkginfo genpkgindex glsa-check revdep-rebuild + +# gentoolkit-0.2.4-rc3 +# +# euse (fully done) +# equery (fully done) +# eclean* (fully done) +# epkginfo (fully done) +# genpkgindex (fully done) +# glsa-check (fully done) +# revdep-rebuild (partial) +# eread *nothing todo* + + +# XXX: shouldn't this go to _gentoo_package? +_packages () { + if compset -P '(\\|)(>=|<=|<|>|=)' ; then + _gentoo_packages ${*/(#m)(installed|available)/${MATCH}_versions} + else + _gentoo_packages $* + fi +} + + +_euse () { + local state tmp start_args suboptions_args + start_args=( + {'(--help)-h','(-h)--help'}'[show help]' + {'(--version)-v','(-v)--version'}'[show version]' + {'(--info)-i','(-i)--info'}'[show descriptions for the given useflags]' + {'(--active)-a','(-a)--active'}'[show currently active useflags and their origin]' + {'(--enable)-E','(-E)--enable'}'[enable the given useflags]' + {'(--disable)-D','(-D)--disable'}'[disable the given useflags]' + {'(--prune)-P','(-P)--prune'}'[show version]' + ) + suboptions_args=( + {'(--global)-g','(-g)--global'}'[show only global use flags]' + {'(--local)-l','(-l)--local'}'[show only local use flags]' + ) + if (( CURRENT == 2 ));then + _arguments -s $start_args + elif (( CURRENT == 3 ));then + case "$words[2]" in + -i|--info|-a|--active) + _arguments -s $suboptions_args \ + '*:useflags:_gentoo_packages useflag' && ret=0 + ;; + -E|--enable) + _arguments \ + '*:useflags:_gentoo_packages useflag' && ret=0 + ;; + -D|--disable) + _arguments \ + '*:active useflags:_gentoo_packages active_useflag' && ret=0 + esac + else + _arguments \ + '*:useflag:_gentoo_packages useflag' && ret=0 + fi +} + + +_equery () { + # Based off of X/_xauth. + local state context line expl ret=1 + local tmp cmd start_args common_args + + start_args=( + {'(--nocolor)-C','(-C)--nocolor'}'[turns off colors]' + {'(--quiet)-q','(-q)--quiet'}'[minimal output]' + {'(--help)-h','(-h)--help'}'[show help]' + {'(--version)-V','(-V)--version'}'[show version]' + ) + + common_args=( + '(-i --installed -I --exclude-installed)'{-i,--installed}'[search installed packages]' + '(-I --exclude-installed -i --installed)'{-I,--exclude-installed}'[do not search installed packages]' + '(-p --portage)'{-p,--portage-tree}'[also search in portage tree]' + '(-o --overlay-tree)'{-o,--overlay-tree}'[also search in overlay tree]' + ) + + + _arguments -s $start_args \ + '*::command:->command' && ret=0 + + while [[ -n "$state" ]]; do + tmp="$state" + state= + case "$tmp" in + command) + if (( CURRENT == 1 )); then + state=subcommands + else + cmd="$words[1]" + curcontext="${curcontext%:*:*}:equery-${cmd}:" + case "$cmd" in + belongs|b) + _arguments \ + '(-c --category)'{-c,--category}'[only search in specified category]:category:_gentoo_packages category' \ + '(-e --earlyout)'{-e,--earlyout}'[stop when first match found]' \ + '(-f --full-regex)'{-f,--full-regex}'[supplied query is a full regex]:pattern:' \ + '*:file:_files' && ret=0 + ;; + check|k) + _arguments \ + ':portage:_packages installed' && ret=0 + ;; + depends|d) + _arguments \ + '(-a --all-packages)'{-a,--all-packages}'[search in all available packages (slow)]:all packages:->packages' \ + '(-d --direct -D --indirect)'{-d,--direct}'[search direct dependencies only (default)]' \ + '(-d --direct -D --indirect)'{-D,--indirect}'[search indirect dependencies (VERY slow)]' \ + '*:package:_packages installed' && ret=0 + ;; + depgraph|g) + _arguments \ + '(-U --no-useflags)'{-U,--no-useflags}'[do not show USE flags]' \ + '(-l --linear)'{-l,--linear}'[do not use fancy formatting]' \ + ':package:_packages installed' && ret=0 + ;; + files|f) + _arguments \ + '--timestamp[append timestamp]' \ + '--md5sum[append md5sum]' \ + '--type[prepend file type]' \ + '--filter=[filter output]:filter(s):_values -s , '' dir obj sym dev fifo path conf cmd doc man info' \ + ':installed pkgname:_packages installed' && ret=0 + ;; + meta|m) + _arguments \ + '(-d --description)'{-d,--description}'[show an extended package description]' \ + '(-H --herd)'{-H,--herd}'[show the herd(s) for the package]' \ + '(-k --keywords)'{-k,--keywords}'[show keywords for all matching package versions]' \ + '(-m --maintainer)'{-m,--maintainer}'[show the maintainer(s) for the package]' \ + '(-S --stablreq)'{-S,--stablreq}'[show STABLEREQ arches (ccs) for all matching package versions]' \ + '(-u --useflags)'{-u,--useflags}'[show per-package USE flag descriptions]' \ + '(-U --upstream)'{-U,--upstream}'[show packages upstream information]' \ + '(-x --xml)'{-x,--xml}'[show the plain metadata.xml file]' \ + ':package:_packages available' && ret=0 + ;; + hasuse|h) + _arguments \ + $common_args \ + ':useflag:_gentoo_packages useflag' && ret=0 + ;; + list|l) + _arguments \ + $common_args \ + ': :_guard "^--*" pattern' && ret=0 + ;; + size|s) + _arguments \ + '(-b --bytes)'{-b,--bytes}'[report size in bytes]' \ + ':package:_packages installed' && ret=0 + ;; + which|w) + _arguments \ + ':portage:_packages available' && ret=0 + ;; + uses|u) + _arguments \ + {--all,-a}'[include non-installed packages]' \ + ":portage:_packages installed" && ret=0 + ;; + changes|c) + _arguments \ + '(-l --latest)'{-l,--latest}'[only display latest ChangeLog entry]' \ + '(-f --full)'{-f,--full}'[display full ChangeLog entry]' \ + ':portage:_packages available' && ret=0 + ;; + *) + _message 'command not found' + ;; + esac + fi + ;; + subcommands) + tmp=( + {belongs,b}'[list all packages owning file(s)]' + {check,k}'[check MD5sums and timestamps of package]' + {changes,c}'[shows ChangeLog for specified package]' + {depends,d}'[list all packages depending on specified package]' + {depgraph,g}'[display a dependency tree for package]' + {files,f}'[list files owned by package]' + {hasuse,h}'[list all packages with specified useflag]' + {list,l}'[list all packages matching pattern]' + {size,s}'[print size of files contained in package]' + {uses,u}'[display USE flags for package]' + {which,w}'[print full path to ebuild for package]' + {has,a}'[list all packages matching ENVIRONMENT data stored in /var/db/pkg]' + {keywords,y}'[display keywords for specified PKG]' + {meta,m}'[display metadata about PKG]' + ) + _values 'equery command' $tmp && ret=0 + ;; + esac + done +} + + +_eclean_wrapper () { + local global_opts pkg_opts dist_opts + + global_opts=( + '(-C --nocolor)'{-C,--nocolor}'[turns off colors]' + '(-d,--destructive)'{-d,--destructive}'[only keep the minimum for a reinstallation]' + '(-e,--exclude-file)'{-e,--exclude-file}'[path to the exclusion file]:filename:_files' + '(-i,--interactive)'{-i,--interactive}'[ask confirmation before deletions]' + '(-n,--package-names)'{-n,--package-names}'[protect all versions (when --destructive)]' + '(-p,--pretend)'{-p,--pretend}'[only display what would be cleaned]' + '(-q,--quiet)'{-q,--quiet}'[minimal output]' + '(-t,--time-limit)'{-t,--time-limit}'[don’t delete files modified since