--- _portage-20040204 2004-07-30 07:56:33.156950304 -0700 +++ _portage 2004-07-30 08:09:56.153876216 -0700 @@ -115,8 +115,16 @@ elif (( CURRENT > 2 ));then case "$words[2]" in unmerge|-C) - _arguments -s \ - '*:installed pkgname with versions:_portage_unmerge' "$common_args[@]" && return 0 + if compset -P '(\\|)[><][=]'; then + _arguments -s \ + '*:installed pkgname with versions:_portage_unmerge_vers' "$common_args[@]" && return 0 + elif compset -P '(\\|)[<=>]'; then + _arguments -s \ + '*:installed pkgname with versions:_portage_unmerge_vers' "$common_args[@]" && return 0 + else + _arguments -s \ + '*:installed pkgname:_portage_unmerge' "$common_args[@]" && return 0 + fi ;; clean|-c) _arguments -s \ @@ -126,7 +134,12 @@ _arguments -s \ '*:use package only:_portage_tbz2list' "$common_args[@]" && return 0 ;; - depclean|help|-h|info|regen|sync|rsync|--searchdesc|-S|search|-s|inject|-j|prune|-P) + depclean|help|-h|info|regen|sync|rsync|--searchdesc|-S|search|-s|prune|-P) + ;; + --resume|--skipfirst) + _arguments -s \ + '--skipfirst[Removes the first package in the resume list]' \ + "$common_args[@]" && return 0 ;; *) _arguments -s \ @@ -141,24 +154,51 @@ state='' case "$lstate" in actions) + if compset -P '(\\|)[><][=]'; then _alternative \ - ':emerge actions:_actions' \ - '*:portage:_portage_pkglist' + '*:portage:_ebuild_cache' + + elif compset -P '(\\|)[<=>]'; then + _alternative \ + '*:portage:_ebuild_cache' + + else + _alternative \ + ':emerge actions:_actions' \ + '*:portage:_portage_pkglist' + fi + ;; install_portage) + if compset -P '(\\|)[><][=]'; then _alternative \ - '*:portage:_portage_pkglist' + '*:portage:_ebuild_cache' + elif compset -P '(\\|)[<=>]'; then + _alternative \ + '*:portage:_ebuild_cache' + else + _alternative \ + '*:portage:_portage_pkglist' + fi ;; esac done } -#Function to show only installed packages "cat/name-ver" +#Function to show only installed packages -- pkgname (no category or version #) _portage_unmerge(){ installed_portage=(/var/db/pkg/*-*/*) - installed_dir=/var/db/pkg/ - installed_pkg=${installed_portage//$installed_dir/} - _tags -s installed_pkg && { compadd "$@" -k installed_pkg || compadd "$@" ${(kv)=installed_pkg} } + installed_pkgname=${(M)${${installed_portage##*/}%%-[0-9]*}} + _tags -s installed_pkgname && { compadd "$@" ${(kv)=installed_pkgname} } + _path_files -/ -W "/var/db/pkg/" +} + +#Function to show only installed packages -- cat/name-ver +_portage_unmerge_vers(){ + installed_portage=(/var/db/pkg/*-*/*) + installed_pkgname=${(M)${${installed_portage##*/}}} + _tags -s installed_pkgname && { compadd "$@" ${(kv)=installed_pkgname} } + _path_files -/ -W "/var/db/pkg/" } #Functions to show "cat/name", classes and dependencies @@ -188,9 +228,36 @@ #[[ -n "${portdir_overlay}" ]] && _path_files -/ -W "${portdir_overlay}" _path_files -g \*.ebuild } +#Function for matching all ebuilds pkg-ver (slow if asking for all packages) +_ebuild_cache(){ + if _cache_invalid portage_ebuilds || ! _retrieve_cache portage_ebuilds; then + + overlay_ebuilds=($portdir_overlay/*-*/*/*) + overlay_list=${${(M)${overlay_ebuilds##*/}#*ebuild}%%.ebuild} + metadata_ebuilds=($portdir/metadata/cache/*-*/*) + metadata_list=${(M)${${metadata_ebuilds##*/}}} + + _store_cache portage_ebuilds metadata_list overlay_list + fi + _tags -s metadata_list && {compadd "$@" ${(kv)=metadata_list} } + _tags -s overlay_list && {compadd "$@" ${(kv)=overlay_list} } +} + +local update_policy +zstyle -s ":completion:*:*:emerge:*" cache-policy update_policy +if [[ -z "$update_policy" ]]; then + zstyle ":completion:*:*:emerge:*" cache-policy _ebuilds_caching_policy +fi + +_ebuilds_caching_policy () { + # rebuild if cache is more than a week old + oldp=( "$1"(mw+1) ) + (( $#oldp )) && return 0 +} common_args=( - {'(-p)--pretend','(--pretend)-p'}'[simply display what would be done]' + {'(-p -a --ask)--pretend','(--pretend -a --ask)-p'}'[simply display what would be done]' + {'(-p -a --pretend)--ask','(--pretend -p --ask)-a'}'[ask what would be done]' {'(-d)--debug','(--debug)-d'}'[Tells emerge to run the emerge command in debug mode]' ) install_args=( @@ -212,16 +279,10 @@ {'(--usepkg --changelog -l)-k','(-k --changelog -l)--usepkg'}'[Tells emerge to use binary packages if available]' {'(--usepkgonly --changelog -l)-K','(-K --changelog -l)--usepkgonly'}'[Tells emerge to use binary packages only]' {'(--verbose)-v','(-v)--verbose'}'[Tell emerge to run in verbose mode]' - '(-p --pretend)--columns[Displays versions in aligned format]' + '(-p --pretend -a --ask)--columns[Displays versions in aligned format]' '--resume[Resumes the last merge operation]' - '--skipfirst[Removes the first package in the resume list]' ) -_options() { - _arguments -s \ - "$unmerge_args[@]" "$common_args[@]" "$install_args[@]" -} - _actions() { _values "emerge actions" \ 'sync[Initiates a portage tree update]' \