#autoload # ------------------------------------------------------------------------------ # Copyright (c) 2011 Github zsh-users - http://github.com/zsh-users # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of the zsh-users nor the # names of its contributors may be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ------------------------------------------------------------------------------ # Description # ----------- # # functions for gentoo packages # inspired by _deb_packages # # ------------------------------------------------------------------------------ # Authors # ------- # # * Vadim A. Misbakh-Soloviev # * Bapt # * kaworu # * David Durrleman # * oberyno # * Mamoru Komachi # # ------------------------------------------------------------------------------ # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------ #Usage: _gentoo_packages installed|available|installed_versions|available_versions|binary|category|useflag|overlays|sets|licenses # List installed overlays _gentoo_packages_overlays () { for f in /etc/make.conf /etc/make.globals; do [[ -z "$PORTDIR_OVERLAY" && -r "$f" ]] && local PORTDIR_OVERLAY="`. "$f" 2>/dev/null; echo ${PORTDIR_OVERLAY}`" done compadd $=PORTDIR_OVERLAY } #List the sets _gentoo_packages_sets() { local sets [[ -f /usr/share/portage/config/sets.conf ]] && sets=(${${${(M)${(f)"$(, 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_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_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[$#]" [[ "$command" == (sets|licenses|installed(_versions|)|available(_versions|)|binary|category|(active_|)useflag|available_pkgnames_only|overlays) ]] || { _message "unknown command: $command" return 1 } _gentoo_packages_$command } _gentoo_packages "$@"