head	1.4;
access;
symbols;
locks; strict;
comment	@# @;


1.4
date	2006.06.17.15.55.51;	author usata;	state Exp;
branches;
next	1.3;

1.3
date	2005.05.03.07.30.52;	author usata;	state Exp;
branches;
next	1.2;

1.2
date	2005.02.22.14.16.48;	author usata;	state Exp;
branches;
next	1.1;

1.1
date	2005.02.22.13.49.31;	author usata;	state Exp;
branches;
next	;


desc
@@


1.4
log
@Added eclean functionality. Thanks to baptux.
@
text
@#compdef gensync equery qpkg euse eclean

# Author: oberyno <oberyno@@gmail.com>
# Author: baptux <baptiste.daroussin@@gmail.com>

#Function to show gensync overlays located in /etc/gensync
_overlays(){
    local overlay gensynclist gensync_individual
    gensynclist=(/etc/gensync/*.syncsource) 
    foreach gensync_individual ($gensynclist)
    	overlay=($overlay ${${${(M)${(f)"$(<$gensync_individual)"}##id=*}/id=\"/}%\"})
    end
    _tags overlay && { compadd "$@@" ${(kv)=overlay} }
}

_packages(){
    if compset -P '(\\|)(>=|<=|<|>|=)'  ; then
	_gentoo_packages ${*/(#m)(installed|available)/${MATCH}_versions}
    else
	_gentoo_packages $*
    fi
 }

case $service in

  gensync) 
      _arguments \
 	'(- :)'{--list-sources,-l}'[list known rsync sources]' \
	'()'{--no-color,-C}'[turn off colours]:overlays:_overlays' \
	'(- :)'{--help,-h}'[show help]' \
	'(- :)'{--version,-V}'[display version info]' \
	'(- :):overlays:_overlays' 
;;

 qpkg)
  excl=( --help -h --query-deps -q )
  check=( --check-md5 -cm --check-time -ct --check -c )
  arg=( --info -i --list -l --non-masked -n --masked -m --installed -I --uninstalled -U --group -g )
  find=( --find-file -f --find-pattern -fp )
  dups=( --dups -d --slot -s)
  
       _arguments -s \
    	"($check $excl $find $dups 1)"{--find-file,-f}"[finds package that owns file]:file:_files" \
	"($check $excl $find $dups 1)"{--find-pattern,-fp}"[finds package that owns file matching pattern]:pattern:" \
	"($excl $check $arg $find --dups -d )"{--dups,-d}"[print packages that have multiple versions installed]" \
	"($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]" \
	"($excl --uninstalled -U --installed -I $dups -d)"{--installed,-I}"[include only installed packages]" \
	"($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]" \
	"($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-md5,-cm}"[verify package files 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:_gentoo_packages available" \
	"()"{--no-color,-nc}"[dont use colors]" \
	"*--verbose[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)"{--non-masked,-n}"[include only non-masked packages]" \
	"(- :)"{--help,-h}"[show help]" \
	"(--info -i --query-deps -q --slot -s)1:package:_gentoo_packages installed_versions"
;;

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
		;;
	    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
		;;
    	    *)
		_message 'command not found'
		;;
    	    esac
	fi
	;;
    subcommands)
	tmp=(
	    {belongs,b}'[list all packages owning file(s)]'
	    {check,k}'[check MD5sums and timestamps of 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]'
	)
	    _values 'equery command' $tmp && ret=0
    ;;
    esac
  done
;;
eclean)
	local state context line expl ret=1
	local tmp cmd global_option common_args

	global_option=(
			{'(--nocolor)-C','(-C)--nocolor'}'[turns off colors]'
			{'(--destructive)-d','(-d)--destructive'}'[only keep the minimum for a reinstallation]'
			{'(--exclude-file)-e','(-e)--exclude-file'}'[path to the exclusion file]'
			{'(--interactive)-i','(-i)--interactive'}'[ask confirmation before deletions]'
			{'(--package-names)-n','(-n)--package-names'}'[protect all versions (when --destructive)]'
			{'(--pretend)-p','(-p)--pretend'}'[only display what would be cleaned]'
			{'(--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 $global_option \
	    '*::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]
						case "$cmd" in
						  packages)
						  ;;
						  distfiles)
						  _arguments -s \
							  '(-f --fetch-restricted)'{-f,--fetch-restricted}'[protect fetch-restricted files (when --destructive)]' \
							  '(-s --size-limit)'{-s,--size-limit}'[do not delete disfiles bigger than <size>]:size:' 
						  ;;
						esac
						fi
					;;
					subcommands)
					tmp=(
					{packages,}'[clean outdated binary packages]'
					{distfiles,}'[clean outdated packages sources files]'
					)
					_values 'eclean command' $tmp && ret=0
					;;
	    esac
		done
;;
esac

@


1.3
log
@Added euse completion. Thanks to baptux <baptiste.daroussin@@gmail.com>; bug #91196.
@
text
@d1 1
a1 1
#compdef gensync equery qpkg euse
d4 1
d216 54
d271 1
@


1.2
log
@Modified to use _gentoo_packages by baptux <bapt@@ifrance.com> and updated by oberyno <oberyno@@gmail.com>; bug #71957.
@
text
@d1 1
a1 1
#compdef gensync equery qpkg
d64 37
d110 1
@


1.1
log
@Initial revision
@
text
@d15 7
a21 61
#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 
_equery_val(){
    _values  "equery actions" \
	'files[list files owned by pkg]' \
	'list[list all packages matching pattern]' \
	'belongs[list all packages owning file]' \
	'uses[display USE flags for package]' \
	'which[print full path to ebuild for package]' \
	'depgraph[display a dependency tree for package]' \
	'check[check files against recorded md5sums and timestamps]' \
	'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##*/})

d48 1
a48 1
	"($excl --group -g $dups -d)"{--group,-g}"[find by group]:group:_category" \
d50 1
a50 1
	"($excl --info -i $dups -d 1)"{--info,-i}"[get package description and home page]:package:_portage_pkglist" \
d54 1
a54 1
	"($excl $find --query-deps -q $dups -d 1)"{--query-deps,-q}"[display all installed packages depending on selected packages]:package:_portage_pkglist" \
d61 1
a61 1
	"(--info -i --query-deps -q --slot -s)1:package:_portage_installed"
d63 1
a63 1
 
d65 58
a122 11
   local prev="$words[CURRENT-1]" prev2="$words[CURRENT-2]" 

   if (( CURRENT == 2 ));then
  	    _equery_val
	    _arguments \
 	$common_args && return 0
   elif (( CURRENT > 2 ));then

        case "$prev" in
	    files|--timestamp|--md5sum|--type)
	    	_arguments -s \
d126 2
a127 1
		 '*:installed pkgname:_portage_installed' && return 0
d129 18
a146 5
	    belongs|--earlyout)
		  _arguments -s \
		  '(-c --category)'{-c,--category}'[only search in specified category]' \
		  '(-e --earlyout)'{-e,--earlyout}'[stop when first match found]' \
		  '*:file:_files' && return 0 	 
d148 1
a148 37
	    --category|-c)  
	    	_arguments -s \
			'*:category:_category' && return 0
	    ;;
 	    list|--installed|-i|--exclude-installed|-I|-p|--portage-tree|-o|--overlay-tree)
	    	_arguments -s \
		 '(-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]' \
		 '*:package:_portage_installed' && return 0
		;;
	    uses|which)
	    	_arguments \
		'*:package:_portage_pkglist' \
		     && return 0
		;;
	    depgraph|-U|--no-useflags|-l|--linear)
	    	_arguments -s \
		'(-U --no-useflags)'{-U,--no-useflags}'[do not show USE flags]' \
		'(-l --linear)'{-l,--linear}'[do not use fancy formatting]' \
		 '*:package:_portage_installed' \
		   && return 0
		;;
	    size|-b|--bytes)
	    	_arguments -s \
		'(-b --bytes)'{-b,--bytes}'[report size in bytes]' \
		'*:package:_portage_installed' \
		    && return 0
		;;
	    check)
		_arguments -s \
		'*:package:_portage_installed' \
		    && return 0
	        ;;
	    --nocolor|-C|--quiet|-q)
	    	 _equery_val
d150 8
a157 1
 		$common_args && return 0
d159 18
a176 14
        esac

	[[ $prev2 == (--category|-c) ]] &&
		_arguments  '(-c --category)'{-c,--category}'[only search in specified category]' \
		  '(-e --earlyout)'{-e,--earlyout}'[stop when first match found]' \
		  '*:file:_files'  && return 0 

   fi
   common_args=(
 	{'(--nocolor)-C','(-C)--nocolor'}'[turns off colors]'
	{'(--quiet)-q','(-q)--quiet'}'[minimal output]'
	{'(--help)-h','(-h)--help'}'[show help]'
 )
 ;;
@
