#compdef gensync equery # Author oberyno #Function to show gensync overlays located in /etc/gensync _overlays(){ overlay=$(grep -h id= /etc/gensync/* | sed -e 's/id="\(.*\)"$/\1/') _tags overlay && { compadd "$@" -k overlay || compadd "$@" ${(kv)=overlay} } } #show portage categories without / at end; app-cdr instead of app-cdr/ _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} } } #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}" } #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##*/}) 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' ;; equery) local prev="$words[CURRENT-1]" prev3="$words[CURRENT-3]" if (( CURRENT == 2 ));then _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]' \ "$common_args[@]" elif (( CURRENT > 2 ));then case "$words[2]" in files) _arguments -s \ '--timestamp[append timestamp]' \ '--md5sum[append md5sum]' \ '--type[prepend file type]' \ '*:installed pkgname:_portage_installed' \ "$common_args[@]" && return 0 ;; belongs) if [[ ${prev} == (-c|--category) ]] then _arguments -s \ '*:category:_category' && return 0 elif [[ ${prev3} == (-c|--category) ]] then return 0 else _arguments -s \ '(-c --category)'{-c,--category}'[only search in specified category]' \ '(-e --earlyout)'{-e,--earlyout}'[stop when first match found]' \ '*:file:_files' "$common_args[@]" && return 0 fi ;; list) _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_pkglist' \ "$common_args[@]" && return 0 ;; uses|which) _arguments \ '*:package:_portage_pkglist' \ "$common_args[@]" && return 0 ;; depgraph) _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' \ "$common_args[@]" && return 0 ;; size) _arguments -s \ '(-b --bytes)'{-b,--bytes}'[report size in bytes]' \ '*:package:_portage_installed' \ "$common_args[@]" && return 0 ;; check) _arguments -s \ '*:package:_portage_installed' \ "$common_args[@]" && return 0 ;; esac fi common_args=( {'(--nocolor)-C','(-C)--nocolor'}'[turns off colors]' {'(--quiet)-q','(-q)--quiet'}'[minimal output]' {'(--help)-h','(-h)--help'}'[show help]' ) ;; esac