View | Details | Raw Unified
Collapse All | Expand All

(-) zsh-completion-20040730/_gcc-config (-2 / +2 lines)
 Lines 19-26    Link Here 
_gcc_profile(){
_gcc_profile(){
    local profile
    local profile
    profile=$(_call_program tag gcc-config --list-profiles)
    profile=(${(f)"$(_call_program gcc-installed gcc-config --list-profiles)"})
    profile=${profile/\[([^]]*)\]/}
    profile=${${profile/\[([^]]*)\]/}/\*}
    _tags profile && { compadd "$@" -k profile || compadd "$@" ${(kv)=profile} }
    _tags profile && { compadd "$@" -k profile || compadd "$@" ${(kv)=profile} }
}
}
(-) zsh-completion-20040730/_genlop (-36 / +1 lines)
 Lines 61-67    Link Here 
		"($single --time -t)"{--time,-t}"[display merge time]" \
		"($single --time -t)"{--time,-t}"[display merge time]" \
		"($single --rsync -r --unmerge -u)"{--unmerge,-u}"[display when packages have been unmerged]" \
		"($single --rsync -r --unmerge -u)"{--unmerge,-u}"[display when packages have been unmerged]" \
		"($single $arg *)"{--version,-v}"[display version information]" \
		"($single $arg *)"{--version,-v}"[display version information]" \
		"($single)*:package:_portage_pkglist"
		"($single)*:package:_gentoo_packages available"
	;;
	;;
    esac
    esac
	
	
 Lines 79-91    Link Here 
    done   
    done   
}
}
#Function to show all available portage names
_portage_pkglist(){
    portage_pkglist="$portage_pkglist"
    _tags -s portage_pkglist && { compadd "$@" ${(kv)=portage_pkglist} }
    _path_files -/ -F "*CVSROOT" -F "*eclass" -F "*distfiles" -F "*licences" -F "*files" -W "${portdir}"
}
_days() {
_days() {
	local m="monday" t="tuesday" w="wednesday" T="thursday" f="friday" s="saturday" S="sunday"	
	local m="monday" t="tuesday" w="wednesday" T="thursday" f="friday" s="saturday" S="sunday"	
	local day=$(date +%u)
	local day=$(date +%u)
 Lines 115-145    Link Here 
	elif [[ ${month} == 12 ]] then compadd $j $f $m $a $M $ju $J $A $s $o $n $d
	elif [[ ${month} == 12 ]] then compadd $j $f $m $a $M $ju $J $A $s $o $n $d
	fi
	fi
}
}
#Reading informations from make.conf
#
# Using portageq is the right way to get PORTDIR, but it is very slow :-(
#
#portdir="$(portageq portdir)"
#pkgdir="$(portageq pkgdir)"
#portdir_overlay="$(portageq portdir_overlay)"
[[ -n "${PORTDIR}" ]] && portdir="${PORTDIR}"
[[ -n "${PKGDIR}" ]] && pkgdir="${PKGDIR}"
if [[ -n "${PORTDIR_OVERLAY}" ]] ; then
    for overlay in ${=PORTDIR_OVERLAY} ; do
	portdir_overlay=(${overlay} ${portdir_overlay})
    done
fi
[[ -r /etc/make.globals ]] && source /etc/make.globals
[[ -r /etc/make.conf ]] && source /etc/make.conf
[[ -z "${portdir}" ]] && portdir="${PORTDIR}"
[[ -z "${pkgdir}" ]] && pkgdir="${PKGDIR}"
if [[ -z "${portdir_overlay}" ]] ; then
    for overlay in ${=PORTDIR_OVERLAY} ; do
	portdir_overlay=(${overlay} ${portdir_overlay})
    done
fi
portage_pkglist=(${portdir}/*-*/* ${=portdir_overlay}/*-*/*)
portage_pkglist=(${portage_pkglist##*/})
(-) zsh-completion-20040730/_gentoolkit (-60 / +11 lines)
 Lines 12-30    Link Here 
    _tags overlay && { compadd "$@" ${(kv)=overlay} }
    _tags overlay && { compadd "$@" ${(kv)=overlay} }
}
}
#show portage categories without / at end; app-cdr instead of app-cdr/ -- this can probably be done with _files, but I'm lazy
_category(){
 categories=($portdir/metadata/cache/*-*)
    category=${(M)${${categories##*/}}}
_tags -s category && { compadd "$@" ${(kv)=category} }
}
#Function to show only installed packages   -- pkgname (no category or version #)
_portage_installed(){
    installed_portage=(/var/db/pkg/*-*/*)
    installed_pkgname=${(M)${${installed_portage##*/}%%-[0-9]*}}
    _tags -s installed_pkgname && { compadd "$@" ${(kv)=installed_pkgname} }
}
#moved out of equery 
#moved out of equery 
_equery_val(){
_equery_val(){
    _values  "equery actions" \
    _values  "equery actions" \
 Lines 38-79    Link Here 
	'size[print size of files contained in package]' 
	'size[print size of files contained in package]' 
	}
	}
#Function to show all available portage names
_portage_pkglist(){
    portage_pkglist="$portage_pkglist"
    _tags -s portage_pkglist && { compadd "$@" ${(kv)=portage_pkglist} }
    _path_files -/ -F "*CVSROOT" -F "*eclass" -F "*distfiles" -F "*licences" -W "${portdir}"
}
#Reading informations from Portage
#
# Using portageq is the right way to get PORTDIR, but it is very slow :-(
#
#portdir="$(portageq portdir)"
#pkgdir="$(portageq pkgdir)"
#portdir_overlay="$(portageq portdir_overlay)"
[[ -n "${PORTDIR}" ]] && portdir="${PORTDIR}"
[[ -n "${PKGDIR}" ]] && pkgdir="${PKGDIR}"
if [[ -n "${PORTDIR_OVERLAY}" ]] ; then
    for overlay in ${=PORTDIR_OVERLAY} ; do
	portdir_overlay=(${overlay} ${portdir_overlay})
    done
fi
[[ -r /etc/make.globals ]] && source /etc/make.globals
[[ -r /etc/make.conf ]] && source /etc/make.conf
[[ -z "${portdir}" ]] && portdir="${PORTDIR}"
[[ -z "${pkgdir}" ]] && pkgdir="${PKGDIR}"
if [[ -z "${portdir_overlay}" ]] ; then
    for overlay in ${=PORTDIR_OVERLAY} ; do
	portdir_overlay=(${overlay} ${portdir_overlay})
    done
fi
portage_pkglist=(${portdir}/*-*/* ${portdir_overlay}/*-*/*)
portage_pkglist=(${portage_pkglist##*/})
case $service in
case $service in
  gensync) 
  gensync) 
 Lines 99-118    Link Here 
	"($excl $check $arg $find --slot -s 1)"{--slot,-s}"[only print duplicates of the same slot]" \
	"($excl $check $arg $find --slot -s 1)"{--slot,-s}"[only print duplicates of the same slot]" \
	"($check $excl --installed -I --uninstalled -U $dups -d)"{--uninstalled,-U}"[include only uninstalled packages]" \
	"($check $excl --installed -I --uninstalled -U $dups -d)"{--uninstalled,-U}"[include only uninstalled packages]" \
	"($excl --uninstalled -U --installed -I $dups -d)"{--installed,-I}"[include only installed packages]" \
	"($excl --uninstalled -U --installed -I $dups -d)"{--installed,-I}"[include only installed packages]" \
	"($excl --group -g $dups -d)"{--group,-g}"[find by group]:group:_category" \
	"($excl --group -g $dups -d)"{--group,-g}"[find by group]:group:_gentoo_packages category" \
	"($check $excl --list -l $dups -d)"{--list,-l}"[list package contents]" \
	"($check $excl --list -l $dups -d)"{--list,-l}"[list package contents]" \
	"($excl --info -i $dups -d 1)"{--info,-i}"[get package description and home page]:package:_portage_pkglist" \
	"($excl --info -i $dups -d 1)"{--info,-i}"[get package description and home page]:package:_gentoo_packages available" \
	"($excl $check $find $dups --uninstalled -U)"{--check-time,-ct}"[verify package file timestamps]" \
	"($excl $check $find $dups --uninstalled -U)"{--check-time,-ct}"[verify package file timestamps]" \
	"($excl $check $find $dups --uninstalled -U)"{--check-md5,-cm}"[verify package files md5]" \
	"($excl $check $find $dups --uninstalled -U)"{--check-md5,-cm}"[verify package files md5]" \
	"($excl $check $find $dups --uninstalled -U)"{--check,-c}"[verify mtimes and md5]" \
	"($excl $check $find $dups --uninstalled -U)"{--check,-c}"[verify mtimes and md5]" \
	"($excl $find --query-deps -q $dups -d 1)"{--query-deps,-q}"[display all installed packages depending on selected packages]:package:_portage_pkglist" \
	"($excl $find --query-deps -q $dups -d 1)"{--query-deps,-q}"[display all installed packages depending on selected packages]:package:_gentoo_packages available" \
	"()"{--no-color,-nc}"[dont use colors]" \
	"()"{--no-color,-nc}"[dont use colors]" \
	"*--verbose[be more verbose (2 levels)]" \
	"*--verbose[be more verbose (2 levels)]" \
	"*-v[be more verbose (2 levels)]" \
	"*-v[be more verbose (2 levels)]" \
	"($excl --non-masked -n --masked -m $dups)"{--masked,-m}"[include only masked packages]" \
	"($excl --non-masked -n --masked -m $dups)"{--masked,-m}"[include only masked packages]" \
	"($excl --non-masked -n --masked -m $dups)"{--non-masked,-n}"[include only non-masked packages]" \
	"($excl --non-masked -n --masked -m $dups)"{--non-masked,-n}"[include only non-masked packages]" \
	"(- :)"{--help,-h}"[show help]" \
	"(- :)"{--help,-h}"[show help]" \
	"(--info -i --query-deps -q --slot -s)1:package:_portage_installed"
	"(--info -i --query-deps -q --slot -s)1:package:_gentoo_packages installed_versions"
;;
;;
 
 
equery)
equery)
 Lines 130-136    Link Here 
		 '--timestamp[append timestamp]' \
		 '--timestamp[append timestamp]' \
		 '--md5sum[append md5sum]' \
		 '--md5sum[append md5sum]' \
		 '--type[prepend file type]' \
		 '--type[prepend file type]' \
		 '*:installed pkgname:_portage_installed' && return 0
		 '*:installed pkgname:_gentoo_packages installed_versions' && return 0
		;;
		;;
	    belongs|--earlyout)
	    belongs|--earlyout)
		  _arguments -s \
		  _arguments -s \
 Lines 140-146    Link Here 
		;;
		;;
	    --category|-c)  
	    --category|-c)  
	    	_arguments -s \
	    	_arguments -s \
			'*:category:_category' && return 0
			'*:category:_gentoo_packages category' && return 0
	    ;;
	    ;;
 	    list|--installed|-i|--exclude-installed|-I|-p|--portage-tree|-o|--overlay-tree)
 	    list|--installed|-i|--exclude-installed|-I|-p|--portage-tree|-o|--overlay-tree)
	    	_arguments -s \
	    	_arguments -s \
 Lines 148-176    Link Here 
		 '(-I --exclude-installed -i --installed)'{-I,--exclude-installed}'[do not 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]' \
		 '(-p --portage)'{-p,--portage-tree}'[also search in portage tree]' \
		 '(-o --overlay-tree)'{-o,--overlay-tree}'[also search in overlay tree]' \
		 '(-o --overlay-tree)'{-o,--overlay-tree}'[also search in overlay tree]' \
		 '*:package:_portage_installed' && return 0
		 '*:package:_gentoo_packages installed_versions' && return 0
		;;
		;;
	    uses|which)
	    uses|which)
	    	_arguments \
	    	_arguments \
		'*:package:_portage_pkglist' \
		'*:package:_gentoo_packages installed_versions' \
		     && return 0
		     && return 0
		;;
		;;
	    depgraph|-U|--no-useflags|-l|--linear)
	    depgraph|-U|--no-useflags|-l|--linear)
	    	_arguments -s \
	    	_arguments -s \
		'(-U --no-useflags)'{-U,--no-useflags}'[do not show USE flags]' \
		'(-U --no-useflags)'{-U,--no-useflags}'[do not show USE flags]' \
		'(-l --linear)'{-l,--linear}'[do not use fancy formatting]' \
		'(-l --linear)'{-l,--linear}'[do not use fancy formatting]' \
		 '*:package:_portage_installed' \
		 '*:package:_gentoo_packages installed_versions' \
		   && return 0
		   && return 0
		;;
		;;
	    size|-b|--bytes)
	    size|-b|--bytes)
	    	_arguments -s \
	    	_arguments -s \
		'(-b --bytes)'{-b,--bytes}'[report size in bytes]' \
		'(-b --bytes)'{-b,--bytes}'[report size in bytes]' \
		'*:package:_portage_installed' \
		'*:package:_gentoo_packages installed_versions' \
		    && return 0
		    && return 0
		;;
		;;
	    check)
	    check)
		_arguments -s \
		_arguments -s \
		'*:package:_portage_installed' \
		'*:package:_gentoo_packages installed_versions' \
		    && return 0
		    && return 0
	        ;;
	        ;;
	    --nocolor|-C|--quiet|-q)
	    --nocolor|-C|--quiet|-q)
(-) zsh-completion-20040730/_gentoo_packages (+134 lines)
Line 0    Link Here 
#autoload
#Author: baptux <bapt@ifrance.com>
#Author: oberyno <oberyno@gmail.com>
#Description:
# functions for gentoo packages
# inspired by _deb_packages
#Usage: _gentoo_packages installed|available|installed_versions|available_versions|binary|category
_gentoo_packages_update_category(){
    local var trees category
    for var in PORTDIR PORTDIR_OVERLAY ; do
	[[ -z ${(P)var} && -r /etc/make.conf ]] &&
	    local $var="`. /etc/make.conf 2>/dev/null; echo ${(P)var}`"
	[[ -z ${(P)var} && -r /etc/make.globals ]] &&
	    local $var="`. /etc/make.globals 2>/dev/null; echo ${(P)var}`"
    done
    trees=($PORTDIR $=PORTDIR_OVERLAY)
    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 'category/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(){
    local var trees category packages pkg expl
    for var in PORTDIR PORTDIR_OVERLAY ; do
	[[ -z ${(P)var} && -r /etc/make.conf ]] &&
	    local $var="`. /etc/make.conf 2>/dev/null; echo ${(P)var}`"
	[[ -z ${(P)var} && -r /etc/make.globals ]] &&
	    local $var="`. /etc/make.globals 2>/dev/null; echo ${(P)var}`"
    done
    trees=( $PORTDIR $=PORTDIR_OVERLAY)
    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-<tab>, 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
    for var in PORTDIR PORTDIR_OVERLAY ; do
	[[ -z ${(P)var} && -r /etc/make.conf ]] &&
	    local $var="`. /etc/make.conf 2>/dev/null; echo ${(P)var}`"
	[[ -z ${(P)var} && -r /etc/make.globals ]] &&
	    local $var="`. /etc/make.globals 2>/dev/null; echo ${(P)var}`"
    done
    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/make.conf ]] &&
	local PKGDIR="`. /etc/make.conf 2>/dev/null; echo $PKGDIR`"
    [[ -z $PKGDIR && -r /etc/make.globals ]] &&
	local PKGDIR="`. /etc/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|)|available(_versions|)|binary|category) ]] || {
		_message "unknown command: $command"
		return
	}
	[[ "$pkgset" ==  (installed(_versions|)|available(_versions|)|binary|category) ]] || {
		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 "$@"
(-) zsh-completion-20040730/_portage (-240 / +124 lines)
 Lines 5-14    Link Here 
# ZSH completion function for Portage
# ZSH completion function for Portage
# Author: baptux <bapt@ifrance.com>
# Author: baptux <bapt@ifrance.com>
# Author: Mamoru KOMACHI <usata@gentoo.org>
# Author: Mamoru KOMACHI <usata@gentoo.org>
# Author: oberyno <oberyno@gmail.com>
# Already done:
# Already done:
#
#
# emerge (fully done) 
# emerge (fully done)
# rc-update (fully done)
# rc-update (fully done)
# rc-status (fully done)
# rc-status (fully done)
# ebuild (fully done)
# ebuild (fully done)
 Lines 57-63    Link Here 
		'package[This command is a lot like the merge command, but create a .tbz2 package]' \
		'package[This command is a lot like the merge command, but create a .tbz2 package]' \
		'rpm[Builds a RedHat RPM package]'
		'rpm[Builds a RedHat RPM package]'
	fi
	fi
	
}
}
# Stuff for rc-status
# Stuff for rc-status
 Lines 77-82    Link Here 
# Stuff for rc-update
# Stuff for rc-update
_rc-update () {
_rc-update () {
local used_init
    used_init=(${=${(M)${(f)"$(rc-update show 2>/dev/null)"}:#*|*[a-z]*}% |*})
    if (( CURRENT == 2 ));then
    if (( CURRENT == 2 ));then
       _values "rc-update actions" \
       _values "rc-update actions" \
       'add[Add script to a runlevel]' \
       'add[Add script to a runlevel]' \
 Lines 87-95    Link Here 
       '-s[Show scripts lanched at a runlevel]'
       '-s[Show scripts lanched at a runlevel]'
    elif (( CURRENT == 3 ));then
    elif (( CURRENT == 3 ));then
	case "$words[2]" in
	case "$words[2]" in
		add|-a|del|-d)
		add|-a)
		    _arguments -s \
		 _values "scripts" /etc/init.d/*~*.sh(:t)
		        '*:scripts:_files -W /etc/init.d/'
		;;
		del|-d)
		_values "scripts" $used_init
		;;
		;;
		show|-s)
		show|-s)
		    _values "runlevels" $gentoo_runlevels
		    _values "runlevels" $gentoo_runlevels
 Lines 107-361    Link Here 
# Stuff for quickpkg
# Stuff for quickpkg
_quickpkg () {
_quickpkg () {
	if compset -P '(\\|)[><][=]'; then
	if compset -P '(\\|)(>=|<=|<|>|=)'; then
	_arguments -s \
	_arguments -s \
    	    '*:installed pkgname with versions:_portage_unmerge_vers' && return 0
    	    '*:installed package:_gentoo_packages installed_versions'
	  elif compset -P '(\\|)[<=>]'; then
		_arguments -s \
		    '*:installed pkgname with versions:_portage_unmerge_vers' && return 0
	  elif compset -P '(\\|)[/]'; then
	  elif compset -P '(\\|)[/]'; then
		_files -W / -/ && return 0
		_path_files -W / -/
	  else 
	  else
		_arguments -s \
    		_arguments \
		    '*:installed pkgname:_portage_quickpkg' && return 0
		    '*:installed package:_gentoo_packages installed'
	  fi
	  fi
}
}
 
# Stuff for emerge
# Stuff for emerge
_emerge () {
_emerge () {
    local state
    local nopkg_opts all noask_opts bopts install_args common_args profiles
    if (( CURRENT == 2 ));then
        _arguments -s \
            '*:*:->actions' \
            "$common_args[@]" "$install_args[@]" && return 0
    elif (( CURRENT > 2 ));then
        case "$words[2]" in
	    unmerge|-C)
	 	  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 \
		    '*:installed pkgname:_portage_clean' "$common_args[@]" && return 0
		;;
	    --usepkgonly|-K)
		_arguments -s \
		    '*:use package only:_portage_tbz2list' "$common_args[@]" && return 0
		;;
	    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 \
		    '*:*:->install_portage' \
		    "$common_args[@]" \
		    "$install_args[@]" && return 0
		;;
        esac
    fi
    while [[ -n "$state" ]]; do
        lstate=$state
        state=''
        case "$lstate" in
	    actions)
		if compset -P '(\\|)[><][=]'; then
		_alternative \
			'*: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:_ebuild_cache'
		elif compset -P '(\\|)[<=>]'; then
		_alternative \
			'*:portage:_ebuild_cache'
		else
		_alternative \
		     '*:portage:_portage_pkglist'
		fi
		;;
        esac
    done
}
#Function to show only installed packages   -- pkgname (no category or version #)
_portage_unmerge(){
    installed_portage=(/var/db/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 -- no _path_files 
  noask_opts=(-p -a --pretend --ask --regen --info --search -s --searchdesc \
_portage_quickpkg(){
  -S --version -V --help -h --metadata)
    installed_portage=(/var/db/pkg/*-*/*)
    installed_pkgname=${(M)${${installed_portage##*/}%%-[0-9]*}}
    _tags -s installed_pkgname && { compadd "$@" ${(kv)=installed_pkgname} }
}
#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
  nopkg_opts=(--resume --skipfirst -c --clean -h --help --depclean --info \
_portage_clean() {
  --metadata -P --prune --regen -s --search -S --searchdesc --sync -C \
    installed_portage=(/var/db/pkg/*-*/*)
  --unmerge -V --version -i --inject)
    installed_dir=/var/db/pkg/
    installed_pkg=${installed_portage//$installed_dir/}
  bopts=($nopkg_opts -b --buildpkg -B --buildpkgonly -G --getbinpkgonly -g \
    installed_pkgname=${(M)${${installed_portage##*/}%%-[0-9]*}}
  --getbinpkg -k --usepkg -K --usepkgonly --fetch-all-uri -f -F --fetchonly)
    _tags -s installed_pkg && { compadd "$@" -k installed_pkg || compadd "$@" ${(kv)=installed_pkg} }
    _tags -s installed_pkgname && { compadd "$@" -k installed_pkgname || compadd "$@" ${(kv)=installed_pkgname} }
  all=($bopts -l --changelog --columns --deep -D --emptytree -e --newuse \
}
  --noconfmem --nodeps -O --noreplace -n --oneshot -1 -o --onlydeps --tree -t \
  -u --update -U --upgradeonly)
#Function to show tbz2 files available
_portage_tbz2list() {
  common_args=(
    # this doesn't take care of ${PORTAGE_BINHOST}. If Gentoo official
    "($noask_opts --sync)"{-p,--pretend}"[Simply  display  what would be done]"
    # binary mirror will be available we should rewrite it accordingly.
    "($noask_opts)"{-a,--ask}"[Ask what would be done]"
    _path_files -g \*.tbz2 -W "${pkgdir}/All"
    '(-d --debug --help -h --version -V)'{-d,--debug}'[Tells emerge to run the emerge command in debug mode]'
}
    '(--quiet -q --verbose -v)'{-q,--quiet}'[General outcome is a reduced or condensed output]'
    '(--verbose -v --quiet -q)'{-v,--verbose}'[Tell emerge to run in verbose mode]'
    '--nospinner[Disables the spinner for the session]'
  )
  install_args=(
    "($bopts)"{-b,--buildpkg}"[Tells emerge to build binary packages]"
    "($bopts)"{-B,--buildpkgonly}"[Tells emerge to only build binary packages]"
    "($nopkg_opts --emptytree -e -l --changelog --usepkgonly -K)"{-l,--changelog}"[This will show the ChangeLog]"
    "($nopkg_opts -t --tree)--columns[Displays versions in aligned format]"
    "($nopkg_opts -D --deep)"{-D,--deep}"[Consider the entire dependency tree of packages]"
    "($nopkg_opts -e -l --changelog --emptytree)"{-e,--emptytree}"[Only consider glibc as installed packages]"
    "($all --nospinner --pretend -p)"{-i,--inject}"[Portage thinks that this package is installed]"
    "($nopkg_opts $bopts)"{-f,--fetchonly}"[Just perform fetches for all packages]"
    "($nopkg_opts $bopts)"{-F,--fetch-all-uri}"[As -f, but prints all mirrors when used with -p]"
    "($bopts)"{-g,--getbinpkg}"[Tells emerge to download binary package]"
    "($bopts)"{-G,--getbinpkgonly}"[As --getbinpkg, but does not use local info]"
    "($nopkg_opts)--noconfmem[Causes portage to disregard merge records]"
    "($nopkg_opts -O --nodeps)"{-O,--nodeps}"[Merges specified packages without merging dependencies]"
    "($nopkg_opts -n --noreplace)"{-n,--noreplace}"[Skip packages already installed]"
    "($nopkg_opts)"{-1,--oneshot}"[Do not add package to the world profile]"
    "($nopkg_opts --onlydeps -o)"{-o,--onlydeps}"[Only merge (or pretend to merge) the dependencies]"
    "($nopkg_opts --columns -t --tree)"{-t,--tree}"[Show dependency tree]"
    "($nopkg_opts --update -u)"{-u,--update}"[Updates packages to the most recent version available]"
    "($nopkg_opts --upgradeonly -U)"{-U,--upgradeonly}"[Do not update packages to a lower version]"
    "($bopts)"{-k,--usepkg}"[Tells emerge to use binary packages if available]"
    "($bopts --changelog -l)"{-K,--usepkgonly}"[Tells emerge to use binary packages only]"
    "($all)"{-c,--clean}"[Cleans the system by removing packages]"
    '(: -)'{-h,--help}'[Displays help]:subject:(sync config system)'
    "(: $all)--depclean[Clean all packages that have no reason for being installed]"
    "(: $all $noask_opts --nospinner --quiet -q)--info[This is a list of information to include in bug reports]"
    "(: -)--metadata[Generate metadata]"
    "($nopkg_opts --usepkgonly -K)--newuse[Include installed packages which have changed USE flags]"
    "($all)"{-P,--prune}"[Removes all but the latest versions of matching packages]"
    "(: $all $noask_opts --verbose -v)--regen[Causes portage to check and update the dependency cache]"
    "(: $all $noask_opts --verbose -v)"{-s,--search}"[Searches for matches]"
    "(: $all $noask_opts --verbose -v)"{-S,--searchdesc}"[Matches the seachdesc string against the description field]"
    "(: $all --pretend -p)--sync[Initiates a portage tree update]"
    "($all)"{-C,--unmerge}"[Removes all matching packages]"
    '(: -)'{-V,--version}'[Display version info]'
    "(: $all[3,-1])--resume[Resumes the last merge operation]"
    "(: $all[3,-1])--skipfirst[Removes the first package in the resume list]"
  )
  profiles=(
    'world[All packages in the world profile]'
    'system[All packages in the system profile]'
  )
  # Dispatch
  if (( $words[(I)(--(unmerge|clean|prune)|-[[:alpha:]]#(C|c|P)[[:alpha:]]#)] )) ; then
	if compset -P '(\\|)(>=|<=|<|>|=)'; then
	    _arguments -s \
		'*:installed package:_gentoo_packages installed_versions' && return 0
	else
	    _arguments -s \
		"$common_args[@]" "$install_args[@]" \
		"*:installed package:_gentoo_packages installed" && return 0
	fi
#Function to show all available portage names
  elif (( $words[(I)(world|system)] )) ; then
_portage_pkglist(){
    _arguments -s \
    portage_classlist="world system"
	"$common_args[@]" "$install_args[@]" \
    portage_pkglist="$portage_pkglist ${portage_classlist}"
	"($nopkg_opts[1,-2] --inject -i --oneshot -1):" && return 0
    _tags -s portage_pkglist && { compadd "$@" -k portage_pkglist || compadd "$@" ${(kv)=portage_pkglist} }
    _path_files -/ -W "${portdir}"
  elif (( $words[(I)(--usepkgonly|-[[:alnum:]]#K[[:alnum:]]#)] )) ; then
    # XXX: If I add ${portdir_overlay} category completion won't work properly
    _arguments -s \
    #[[ -n "${portdir_overlay}" ]] && _path_files -/ -W "${portdir_overlay}"
	"$common_args[@]" "$install_args[@]" \
    _path_files -g \*.ebuild
	'*:binary package:_gentoo_packages binary' && return 0
  elif [[ $words[-3] == (--help|-h) ]] ; then
      _message "No more arguments" && return 0
  else
	if compset -P '(\\|)(>=|<=|<|>|=)'; then
	    _arguments \
		"*:portage:_gentoo_packages available_versions" && return 0
	elif (( $words[(I)(--inject|-i)] )) ; then
	    _arguments -s \
		"$common_args[@]" "$install_args[@]" \
		"*:portage:_gentoo_packages available_versions" && return 0
	else
	    _arguments -s \
		"$common_args[@]" "$install_args[@]" \
		"($nopkg_opts)::portage: _values 'profile' \$profiles[@] " \
		"($nopkg_opts)*:portage:_gentoo_packages available" && return 0
	fi
  fi
}
}
#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=(
local gentoo_runlevels
    {'(-p -a --ask)--pretend','(--pretend -a --ask)-p'}'[simply  display  what would be done]'
gentoo_runlevels=(/etc/runlevels/*(:t))
    {'(-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=(
    {'(--upgradeonly -U --update -u --quiet -q --onlydeps -o --oneshot --nospinner --noreplace -n --nodeps -O --noconfmem -D --deep --changelog --buildpkg -B -b --buildpkgonly --emptytree -e -f --fetchonly)-l','(--upgradeonly -U --update -u --quiet -q --onlydeps -o --nospinner --noreplace -n --nodeps -O --noconfmem -D --deep --emptytree -e -f --fetchonly -l --buildpkg -b -B --buildpkgonly )--changelog'}'[This will show the ChangeLog]'
    {'(-b --buildpkgonly -B --changelog -l)--buildpkg','(--changelog -l --buildpkg --buildpkgonly -B)-b'}'[Tells emerge to build binary packages]'
    {'(-B -b --buildpkg --changelog -l)--buildpkgonly','(--changelog -l --buildpkgonly --buildpkg -b)-B'}'[Tells emerge to only build binary packages]'
    {'(-D --changelog -l)--deep','(-l --changelog --deep)-D'}'[Consider the entire dependency tree of packages]'
    {'(-e -l --changelog)--emptytree','(--emptytree -l --changelog)-e'}'[Only consider glibc as installed packages]'
    {'(-f -l --changelog)--fetchonly','(-l --changelog --fetchonly)-f'}'[Just perform fetches for all packages]'
    '(-l --changelog)--noconfmem[Causes portage to disregard merge records]'
    {'(--changelog -l -O)--nodeps','(--nodeps --changelog -l)-O'}'[Merges specified packages without merging dependencies]'
    {'(-l --changelog -n)--noreplace','(-l --changelog --noreplace)-n'}'[Skip packages already installed]'
    '(-l --changelog)--nospiner[Disables the spinner for the session]'
    '(-l --changelog)--oneshot[Do not add package to the world profile]'
    {'(--onlydeps --changelog -l)-o','(--changelog -o -l)--onlydeps'}'[Only merge (or pretend to merge) the dependencies]'
    {'(--quiet --changelog -l)-q','(-q --changelog -l)--quiet'}'[General outcome is a reduced or condensed output]'
    {'(-l --changelog -t)--tree','(-l --changelog --tree)-t'}'[Show dependency tree]'
    {'(--update --changelog -l)-u','(-u --changelog -l)--update'}'[Updates packages to the most recent version available]'
    {'(--upgradeonly --changelog -l)-U','(-U --changelog -l)--upgradeonly'}'[Do not update packages to a lower version]'
    {'(--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 -a --ask)--columns[Displays versions in aligned format]'
    '--resume[Resumes the last merge operation]'
)
_actions() {
    _values "emerge actions" \
	'sync[Initiates a portage tree update]' \
	'rsync[Initiates a portage tree update]' \
	'unmerge[Removes all matching packages]' \
	'search[Searches for matches]' \
	'regen[Causes portage to check and update the dependency cache]' \
	'prune[Removes all but the latest versions of matching packages]' \
	'inject[Portage thinks that this package is installed]' \
	'info[This is a list of information to include in bug reports]' \
	'help[Displays help]' \
	'depclean[Clean all packages that have no reason for being installed]'\
	'clean[Cleans the system by removing packages]' \
	'-c[Cleans the system by removing packages]' \
	'-h[Displays help]' \
	'-i[Portage thinks that this package is installed]' \
	'-P[Removes all but the latest versions of matching packages]' \
	'-s[Searches for matches]' \
	'-S[Matches the search string against the description field]' \
	'--searchdesc[Matches the search string against the description field]' \
	'-C[Removes all matching packages]' \
	'world[Represent all packages in the world profiles]' \
	'system[Represent all the system packages]' 
}
local portage_pkglist gentoo_runlevels portdir pkgdir portdir_overlay overlay
#Reading informations from make.conf
[[ -n "${PORTDIR}" ]] && portdir="${PORTDIR}"
[[ -n "${PKGDIR}" ]] && pkgdir="${PKGDIR}"
if [[ -n "${PORTDIR_OVERLAY}" ]] ; then
    for overlay in ${=PORTDIR_OVERLAY} ; do
	portdir_overlay=(${overlay} ${portdir_overlay})
    done
fi
[[ -r /etc/make.globals ]] && source /etc/make.globals
[[ -r /etc/make.conf ]] && source /etc/make.conf
[[ -z "${portdir}" ]] && portdir="${PORTDIR}"
[[ -z "${pkgdir}" ]] && pkgdir="${PKGDIR}"
if [[ -z "${portdir_overlay}" ]] ; then
    for overlay in ${=PORTDIR_OVERLAY} ; do
	portdir_overlay=(${overlay} ${portdir_overlay})
    done
fi
portage_pkglist=(${portdir}/*-*/* ${portdir_overlay}/*-*/*)
portage_pkglist=(${portage_pkglist##*/})
gentoo_runlevels=(/etc/runlevels/*)
gentoo_runlevels=(${${gentoo_runlevels/\/etc\/runlevels\//}%/})
case "$service" in
case "$service" in
	emerge)
	emerge)