Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 71957 | Differences between
and this patch

Collapse All | Expand All

(-)zsh-completion-20040730/_gcc-config (-2 / +2 lines)
Lines 19-26 Link Here
19
19
20
_gcc_profile(){
20
_gcc_profile(){
21
    local profile
21
    local profile
22
    profile=$(_call_program tag gcc-config --list-profiles)
22
    profile=(${(f)"$(_call_program gcc-installed gcc-config --list-profiles)"})
23
    profile=${profile/\[([^]]*)\]/}
23
    profile=${${profile/\[([^]]*)\]/}/\*}
24
    _tags profile && { compadd "$@" -k profile || compadd "$@" ${(kv)=profile} }
24
    _tags profile && { compadd "$@" -k profile || compadd "$@" ${(kv)=profile} }
25
}
25
}
26
26
(-)zsh-completion-20040730/_genlop (-36 / +1 lines)
Lines 61-67 Link Here
61
		"($single --time -t)"{--time,-t}"[display merge time]" \
61
		"($single --time -t)"{--time,-t}"[display merge time]" \
62
		"($single --rsync -r --unmerge -u)"{--unmerge,-u}"[display when packages have been unmerged]" \
62
		"($single --rsync -r --unmerge -u)"{--unmerge,-u}"[display when packages have been unmerged]" \
63
		"($single $arg *)"{--version,-v}"[display version information]" \
63
		"($single $arg *)"{--version,-v}"[display version information]" \
64
		"($single)*:package:_portage_pkglist"
64
		"($single)*:package:_gentoo_packages available"
65
	;;
65
	;;
66
    esac
66
    esac
67
	
67
	
Lines 79-91 Link Here
79
    done   
79
    done   
80
}
80
}
81
81
82
#Function to show all available portage names
83
_portage_pkglist(){
84
    portage_pkglist="$portage_pkglist"
85
    _tags -s portage_pkglist && { compadd "$@" ${(kv)=portage_pkglist} }
86
    _path_files -/ -F "*CVSROOT" -F "*eclass" -F "*distfiles" -F "*licences" -F "*files" -W "${portdir}"
87
}
88
89
_days() {
82
_days() {
90
	local m="monday" t="tuesday" w="wednesday" T="thursday" f="friday" s="saturday" S="sunday"	
83
	local m="monday" t="tuesday" w="wednesday" T="thursday" f="friday" s="saturday" S="sunday"	
91
	local day=$(date +%u)
84
	local day=$(date +%u)
Lines 115-145 Link Here
115
	elif [[ ${month} == 12 ]] then compadd $j $f $m $a $M $ju $J $A $s $o $n $d
108
	elif [[ ${month} == 12 ]] then compadd $j $f $m $a $M $ju $J $A $s $o $n $d
116
	fi
109
	fi
117
}
110
}
118
119
#Reading informations from make.conf
120
#
121
# Using portageq is the right way to get PORTDIR, but it is very slow :-(
122
#
123
#portdir="$(portageq portdir)"
124
#pkgdir="$(portageq pkgdir)"
125
#portdir_overlay="$(portageq portdir_overlay)"
126
[[ -n "${PORTDIR}" ]] && portdir="${PORTDIR}"
127
[[ -n "${PKGDIR}" ]] && pkgdir="${PKGDIR}"
128
if [[ -n "${PORTDIR_OVERLAY}" ]] ; then
129
    for overlay in ${=PORTDIR_OVERLAY} ; do
130
	portdir_overlay=(${overlay} ${portdir_overlay})
131
    done
132
fi
133
[[ -r /etc/make.globals ]] && source /etc/make.globals
134
[[ -r /etc/make.conf ]] && source /etc/make.conf
135
136
[[ -z "${portdir}" ]] && portdir="${PORTDIR}"
137
[[ -z "${pkgdir}" ]] && pkgdir="${PKGDIR}"
138
if [[ -z "${portdir_overlay}" ]] ; then
139
    for overlay in ${=PORTDIR_OVERLAY} ; do
140
	portdir_overlay=(${overlay} ${portdir_overlay})
141
    done
142
fi
143
144
portage_pkglist=(${portdir}/*-*/* ${=portdir_overlay}/*-*/*)
145
portage_pkglist=(${portage_pkglist##*/})
(-)zsh-completion-20040730/_gentoolkit (-60 / +11 lines)
Lines 12-30 Link Here
12
    _tags overlay && { compadd "$@" ${(kv)=overlay} }
12
    _tags overlay && { compadd "$@" ${(kv)=overlay} }
13
}
13
}
14
14
15
#show portage categories without / at end; app-cdr instead of app-cdr/ -- this can probably be done with _files, but I'm lazy
16
_category(){
17
 categories=($portdir/metadata/cache/*-*)
18
    category=${(M)${${categories##*/}}}
19
_tags -s category && { compadd "$@" ${(kv)=category} }
20
}
21
22
#Function to show only installed packages   -- pkgname (no category or version #)
23
_portage_installed(){
24
    installed_portage=(/var/db/pkg/*-*/*)
25
    installed_pkgname=${(M)${${installed_portage##*/}%%-[0-9]*}}
26
    _tags -s installed_pkgname && { compadd "$@" ${(kv)=installed_pkgname} }
27
}
28
#moved out of equery 
15
#moved out of equery 
29
_equery_val(){
16
_equery_val(){
30
    _values  "equery actions" \
17
    _values  "equery actions" \
Lines 38-79 Link Here
38
	'size[print size of files contained in package]' 
25
	'size[print size of files contained in package]' 
39
	}
26
	}
40
27
41
#Function to show all available portage names
42
_portage_pkglist(){
43
    portage_pkglist="$portage_pkglist"
44
    _tags -s portage_pkglist && { compadd "$@" ${(kv)=portage_pkglist} }
45
    _path_files -/ -F "*CVSROOT" -F "*eclass" -F "*distfiles" -F "*licences" -W "${portdir}"
46
}
47
48
#Reading informations from Portage
49
#
50
# Using portageq is the right way to get PORTDIR, but it is very slow :-(
51
#
52
#portdir="$(portageq portdir)"
53
#pkgdir="$(portageq pkgdir)"
54
#portdir_overlay="$(portageq portdir_overlay)"
55
[[ -n "${PORTDIR}" ]] && portdir="${PORTDIR}"
56
[[ -n "${PKGDIR}" ]] && pkgdir="${PKGDIR}"
57
if [[ -n "${PORTDIR_OVERLAY}" ]] ; then
58
    for overlay in ${=PORTDIR_OVERLAY} ; do
59
	portdir_overlay=(${overlay} ${portdir_overlay})
60
    done
61
fi
62
[[ -r /etc/make.globals ]] && source /etc/make.globals
63
[[ -r /etc/make.conf ]] && source /etc/make.conf
64
65
[[ -z "${portdir}" ]] && portdir="${PORTDIR}"
66
[[ -z "${pkgdir}" ]] && pkgdir="${PKGDIR}"
67
if [[ -z "${portdir_overlay}" ]] ; then
68
    for overlay in ${=PORTDIR_OVERLAY} ; do
69
	portdir_overlay=(${overlay} ${portdir_overlay})
70
    done
71
fi
72
73
portage_pkglist=(${portdir}/*-*/* ${portdir_overlay}/*-*/*)
74
portage_pkglist=(${portage_pkglist##*/})
75
76
77
case $service in
28
case $service in
78
29
79
  gensync) 
30
  gensync) 
Lines 99-118 Link Here
99
	"($excl $check $arg $find --slot -s 1)"{--slot,-s}"[only print duplicates of the same slot]" \
50
	"($excl $check $arg $find --slot -s 1)"{--slot,-s}"[only print duplicates of the same slot]" \
100
	"($check $excl --installed -I --uninstalled -U $dups -d)"{--uninstalled,-U}"[include only uninstalled packages]" \
51
	"($check $excl --installed -I --uninstalled -U $dups -d)"{--uninstalled,-U}"[include only uninstalled packages]" \
101
	"($excl --uninstalled -U --installed -I $dups -d)"{--installed,-I}"[include only installed packages]" \
52
	"($excl --uninstalled -U --installed -I $dups -d)"{--installed,-I}"[include only installed packages]" \
102
	"($excl --group -g $dups -d)"{--group,-g}"[find by group]:group:_category" \
53
	"($excl --group -g $dups -d)"{--group,-g}"[find by group]:group:_gentoo_packages category" \
103
	"($check $excl --list -l $dups -d)"{--list,-l}"[list package contents]" \
54
	"($check $excl --list -l $dups -d)"{--list,-l}"[list package contents]" \
104
	"($excl --info -i $dups -d 1)"{--info,-i}"[get package description and home page]:package:_portage_pkglist" \
55
	"($excl --info -i $dups -d 1)"{--info,-i}"[get package description and home page]:package:_gentoo_packages available" \
105
	"($excl $check $find $dups --uninstalled -U)"{--check-time,-ct}"[verify package file timestamps]" \
56
	"($excl $check $find $dups --uninstalled -U)"{--check-time,-ct}"[verify package file timestamps]" \
106
	"($excl $check $find $dups --uninstalled -U)"{--check-md5,-cm}"[verify package files md5]" \
57
	"($excl $check $find $dups --uninstalled -U)"{--check-md5,-cm}"[verify package files md5]" \
107
	"($excl $check $find $dups --uninstalled -U)"{--check,-c}"[verify mtimes and md5]" \
58
	"($excl $check $find $dups --uninstalled -U)"{--check,-c}"[verify mtimes and md5]" \
108
	"($excl $find --query-deps -q $dups -d 1)"{--query-deps,-q}"[display all installed packages depending on selected packages]:package:_portage_pkglist" \
59
	"($excl $find --query-deps -q $dups -d 1)"{--query-deps,-q}"[display all installed packages depending on selected packages]:package:_gentoo_packages available" \
109
	"()"{--no-color,-nc}"[dont use colors]" \
60
	"()"{--no-color,-nc}"[dont use colors]" \
110
	"*--verbose[be more verbose (2 levels)]" \
61
	"*--verbose[be more verbose (2 levels)]" \
111
	"*-v[be more verbose (2 levels)]" \
62
	"*-v[be more verbose (2 levels)]" \
112
	"($excl --non-masked -n --masked -m $dups)"{--masked,-m}"[include only masked packages]" \
63
	"($excl --non-masked -n --masked -m $dups)"{--masked,-m}"[include only masked packages]" \
113
	"($excl --non-masked -n --masked -m $dups)"{--non-masked,-n}"[include only non-masked packages]" \
64
	"($excl --non-masked -n --masked -m $dups)"{--non-masked,-n}"[include only non-masked packages]" \
114
	"(- :)"{--help,-h}"[show help]" \
65
	"(- :)"{--help,-h}"[show help]" \
115
	"(--info -i --query-deps -q --slot -s)1:package:_portage_installed"
66
	"(--info -i --query-deps -q --slot -s)1:package:_gentoo_packages installed_versions"
116
;;
67
;;
117
 
68
 
118
equery)
69
equery)
Lines 130-136 Link Here
130
		 '--timestamp[append timestamp]' \
81
		 '--timestamp[append timestamp]' \
131
		 '--md5sum[append md5sum]' \
82
		 '--md5sum[append md5sum]' \
132
		 '--type[prepend file type]' \
83
		 '--type[prepend file type]' \
133
		 '*:installed pkgname:_portage_installed' && return 0
84
		 '*:installed pkgname:_gentoo_packages installed_versions' && return 0
134
		;;
85
		;;
135
	    belongs|--earlyout)
86
	    belongs|--earlyout)
136
		  _arguments -s \
87
		  _arguments -s \
Lines 140-146 Link Here
140
		;;
91
		;;
141
	    --category|-c)  
92
	    --category|-c)  
142
	    	_arguments -s \
93
	    	_arguments -s \
143
			'*:category:_category' && return 0
94
			'*:category:_gentoo_packages category' && return 0
144
	    ;;
95
	    ;;
145
 	    list|--installed|-i|--exclude-installed|-I|-p|--portage-tree|-o|--overlay-tree)
96
 	    list|--installed|-i|--exclude-installed|-I|-p|--portage-tree|-o|--overlay-tree)
146
	    	_arguments -s \
97
	    	_arguments -s \
Lines 148-176 Link Here
148
		 '(-I --exclude-installed -i --installed)'{-I,--exclude-installed}'[do not search installed packages]' \
99
		 '(-I --exclude-installed -i --installed)'{-I,--exclude-installed}'[do not search installed packages]' \
149
		 '(-p --portage)'{-p,--portage-tree}'[also search in portage tree]' \
100
		 '(-p --portage)'{-p,--portage-tree}'[also search in portage tree]' \
150
		 '(-o --overlay-tree)'{-o,--overlay-tree}'[also search in overlay tree]' \
101
		 '(-o --overlay-tree)'{-o,--overlay-tree}'[also search in overlay tree]' \
151
		 '*:package:_portage_installed' && return 0
102
		 '*:package:_gentoo_packages installed_versions' && return 0
152
		;;
103
		;;
153
	    uses|which)
104
	    uses|which)
154
	    	_arguments \
105
	    	_arguments \
155
		'*:package:_portage_pkglist' \
106
		'*:package:_gentoo_packages installed_versions' \
156
		     && return 0
107
		     && return 0
157
		;;
108
		;;
158
	    depgraph|-U|--no-useflags|-l|--linear)
109
	    depgraph|-U|--no-useflags|-l|--linear)
159
	    	_arguments -s \
110
	    	_arguments -s \
160
		'(-U --no-useflags)'{-U,--no-useflags}'[do not show USE flags]' \
111
		'(-U --no-useflags)'{-U,--no-useflags}'[do not show USE flags]' \
161
		'(-l --linear)'{-l,--linear}'[do not use fancy formatting]' \
112
		'(-l --linear)'{-l,--linear}'[do not use fancy formatting]' \
162
		 '*:package:_portage_installed' \
113
		 '*:package:_gentoo_packages installed_versions' \
163
		   && return 0
114
		   && return 0
164
		;;
115
		;;
165
	    size|-b|--bytes)
116
	    size|-b|--bytes)
166
	    	_arguments -s \
117
	    	_arguments -s \
167
		'(-b --bytes)'{-b,--bytes}'[report size in bytes]' \
118
		'(-b --bytes)'{-b,--bytes}'[report size in bytes]' \
168
		'*:package:_portage_installed' \
119
		'*:package:_gentoo_packages installed_versions' \
169
		    && return 0
120
		    && return 0
170
		;;
121
		;;
171
	    check)
122
	    check)
172
		_arguments -s \
123
		_arguments -s \
173
		'*:package:_portage_installed' \
124
		'*:package:_gentoo_packages installed_versions' \
174
		    && return 0
125
		    && return 0
175
	        ;;
126
	        ;;
176
	    --nocolor|-C|--quiet|-q)
127
	    --nocolor|-C|--quiet|-q)
(-)zsh-completion-20040730/_gentoo_packages (+134 lines)
Line 0 Link Here
1
#autoload
2
3
#Author: baptux <bapt@ifrance.com>
4
#Author: oberyno <oberyno@gmail.com>
5
#Description:
6
# functions for gentoo packages
7
# inspired by _deb_packages
8
#Usage: _gentoo_packages installed|available|installed_versions|available_versions|binary|category
9
10
11
_gentoo_packages_update_category(){
12
    local var trees category
13
    for var in PORTDIR PORTDIR_OVERLAY ; do
14
	[[ -z ${(P)var} && -r /etc/make.conf ]] &&
15
	    local $var="`. /etc/make.conf 2>/dev/null; echo ${(P)var}`"
16
	[[ -z ${(P)var} && -r /etc/make.globals ]] &&
17
	    local $var="`. /etc/make.globals 2>/dev/null; echo ${(P)var}`"
18
    done
19
    trees=($PORTDIR $=PORTDIR_OVERLAY)
20
    category=( $trees/*-*(/:t) )
21
    _wanted cat_packages expl 'category' compadd "$@" $category
22
}
23
24
_gentoo_packages_update_installed(){
25
 local installed_dir installed_portage installed_list expl
26
    installed_dir="/var/db/pkg"
27
    installed_portage=($installed_dir/*-*/*)
28
29
    installed_pkgname=( ${${installed_portage:t}%%-[0-9]*} )
30
    _wanted packages expl 'category/package' compadd "$@" ${installed_pkgname}
31
32
    installed_list=( ${${installed_portage#$installed_dir/}%%-[0-9]*} )
33
    _wanted cat_packages expl 'category/package' _multi_parts "$@" / installed_list
34
35
}
36
37
_gentoo_packages_update_installed_versions(){
38
    local installed_list installed_portage expl
39
40
    installed_portage=(/var/db/pkg/*-*/*)
41
    _wanted packages expl 'package' compadd "$@" ${installed_portage:t}
42
43
    installed_list=( ${installed_portage##*/pkg/} )
44
    _wanted cat_packages expl 'category/package' _multi_parts "$@" / installed_list
45
}
46
47
_gentoo_packages_update_available(){
48
    local var trees category packages pkg expl
49
50
    for var in PORTDIR PORTDIR_OVERLAY ; do
51
	[[ -z ${(P)var} && -r /etc/make.conf ]] &&
52
	    local $var="`. /etc/make.conf 2>/dev/null; echo ${(P)var}`"
53
	[[ -z ${(P)var} && -r /etc/make.globals ]] &&
54
	    local $var="`. /etc/make.globals 2>/dev/null; echo ${(P)var}`"
55
    done
56
    trees=( $PORTDIR $=PORTDIR_OVERLAY)
57
    category=( $trees/*-*(/:t) )
58
59
    packages=( $trees/*-*/*(:t) )
60
    _wanted packages expl 'package' compadd  - "${(@)packages}"
61
62
    # Complete cat/pkg. _multi_parts is much to slow for such a large task,
63
    # _sep_parts removes the dash from gnome-<tab>, and _path_files wants to
64
    # complete cat/pkg/files (if "files" is ignored with -F, miscfiles, etc...
65
    # don't get completed).
66
    if [[ $PREFIX != */* ]] ; then
67
	_wanted cat_packages expl 'category/package' compadd -S '/' $category
68
    else
69
	compset -P '*/'
70
	pkg=( $trees/$IPREFIX/*(:t) )
71
	_wanted cat_packages expl 'category/package' compadd $pkg
72
    fi
73
}
74
75
_gentoo_packages_update_available_versions(){
76
    local var overlay_ebuilds portage_ebuilds expl trees category
77
78
    for var in PORTDIR PORTDIR_OVERLAY ; do
79
	[[ -z ${(P)var} && -r /etc/make.conf ]] &&
80
	    local $var="`. /etc/make.conf 2>/dev/null; echo ${(P)var}`"
81
	[[ -z ${(P)var} && -r /etc/make.globals ]] &&
82
	    local $var="`. /etc/make.globals 2>/dev/null; echo ${(P)var}`"
83
    done
84
    trees=($PORTDIR $=PORTDIR_OVERLAY)
85
    category=( $trees/*-*(/:t) )
86
    typeset -U category
87
88
    if [[  $#PREFIX -ge 1  &&  -z $words[(r)(--inject|-i)]  ]] ; then
89
	overlay_ebuilds=($=PORTDIR_OVERLAY/*-*/${PREFIX%%-[0-9]#*}*/*.ebuild(:t:r) )
90
	portage_ebuilds=($PORTDIR/metadata/cache/*-*/${PREFIX%%-[0-9]#*}*(:t))
91
	_wanted packages expl 'package'  compadd  $portage_ebuilds $overlay_ebuilds
92
    fi
93
    pkg=( $trees/${PREFIX%%/*}/*/*.ebuild(:t:r) )
94
    _wanted cat_packages expl 'category/package' _sep_parts category / pkg
95
}
96
97
#Function to show tbz2 files available
98
_gentoo_packages_update_binary() {
99
    [[ -z $PKGDIR && -r /etc/make.conf ]] &&
100
	local PKGDIR="`. /etc/make.conf 2>/dev/null; echo $PKGDIR`"
101
    [[ -z $PKGDIR && -r /etc/make.globals ]] &&
102
	local PKGDIR="`. /etc/make.globals 2>/dev/null; echo $PKGDIR`"
103
104
    # this doesn't take care of ${PORTAGE_BINHOST}. If Gentoo official
105
    # binary mirror will be available we should rewrite it accordingly.
106
    _path_files -g \*.tbz2 -W "$PKGDIR/All"
107
}
108
109
_gentoo_packages () {
110
	local command="$argv[$#]" expl cachevar pkgset update_policy
111
	zstyle -s ":completion:*:*:$service:*" cache-policy update_policy
112
	if [[ -z "$update_policy" ]]; then
113
		zstyle ":completion:*:*:$service:*" cache-policy _gentoo_cache_policy
114
	fi
115
	[[ "$command" == (installed(_versions|)|available(_versions|)|binary|category) ]] || {
116
		_message "unknown command: $command"
117
		return
118
	}
119
	[[ "$pkgset" ==  (installed(_versions|)|available(_versions|)|binary|category) ]] || {
120
		pkgset="$command"
121
	}
122
	expl=("${(@)argv[1,-2]}")
123
	_gentoo_packages_update_$pkgset
124
125
}
126
127
_gentoo_cache_policy () {
128
  # rebuild if cache is more than a week old
129
    oldp=( "$1"(mw+1) )
130
      (( $#oldp )) && return 0
131
}
132
133
134
_gentoo_packages "$@"
(-)zsh-completion-20040730/_portage (-240 / +124 lines)
Lines 5-14 Link Here
5
# ZSH completion function for Portage
5
# ZSH completion function for Portage
6
# Author: baptux <bapt@ifrance.com>
6
# Author: baptux <bapt@ifrance.com>
7
# Author: Mamoru KOMACHI <usata@gentoo.org>
7
# Author: Mamoru KOMACHI <usata@gentoo.org>
8
# Author: oberyno <oberyno@gmail.com>
8
9
9
# Already done:
10
# Already done:
10
#
11
#
11
# emerge (fully done) 
12
# emerge (fully done)
12
# rc-update (fully done)
13
# rc-update (fully done)
13
# rc-status (fully done)
14
# rc-status (fully done)
14
# ebuild (fully done)
15
# ebuild (fully done)
Lines 57-63 Link Here
57
		'package[This command is a lot like the merge command, but create a .tbz2 package]' \
58
		'package[This command is a lot like the merge command, but create a .tbz2 package]' \
58
		'rpm[Builds a RedHat RPM package]'
59
		'rpm[Builds a RedHat RPM package]'
59
	fi
60
	fi
60
	
61
61
}
62
}
62
63
63
# Stuff for rc-status
64
# Stuff for rc-status
Lines 77-82 Link Here
77
# Stuff for rc-update
78
# Stuff for rc-update
78
79
79
_rc-update () {
80
_rc-update () {
81
local used_init
82
    used_init=(${=${(M)${(f)"$(rc-update show 2>/dev/null)"}:#*|*[a-z]*}% |*})
80
    if (( CURRENT == 2 ));then
83
    if (( CURRENT == 2 ));then
81
       _values "rc-update actions" \
84
       _values "rc-update actions" \
82
       'add[Add script to a runlevel]' \
85
       'add[Add script to a runlevel]' \
Lines 87-95 Link Here
87
       '-s[Show scripts lanched at a runlevel]'
90
       '-s[Show scripts lanched at a runlevel]'
88
    elif (( CURRENT == 3 ));then
91
    elif (( CURRENT == 3 ));then
89
	case "$words[2]" in
92
	case "$words[2]" in
90
		add|-a|del|-d)
93
		add|-a)
91
		    _arguments -s \
94
		 _values "scripts" /etc/init.d/*~*.sh(:t)
92
		        '*:scripts:_files -W /etc/init.d/'
95
		;;
96
		del|-d)
97
		_values "scripts" $used_init
93
		;;
98
		;;
94
		show|-s)
99
		show|-s)
95
		    _values "runlevels" $gentoo_runlevels
100
		    _values "runlevels" $gentoo_runlevels
Lines 107-361 Link Here
107
# Stuff for quickpkg
112
# Stuff for quickpkg
108
113
109
_quickpkg () {
114
_quickpkg () {
110
	if compset -P '(\\|)[><][=]'; then
115
	if compset -P '(\\|)(>=|<=|<|>|=)'; then
111
	_arguments -s \
116
	_arguments -s \
112
    	    '*:installed pkgname with versions:_portage_unmerge_vers' && return 0
117
    	    '*:installed package:_gentoo_packages installed_versions'
113
	  elif compset -P '(\\|)[<=>]'; then
114
		_arguments -s \
115
		    '*:installed pkgname with versions:_portage_unmerge_vers' && return 0
116
	  elif compset -P '(\\|)[/]'; then
118
	  elif compset -P '(\\|)[/]'; then
117
		_files -W / -/ && return 0
119
		_path_files -W / -/
118
	  else 
120
	  else
119
		_arguments -s \
121
    		_arguments \
120
		    '*:installed pkgname:_portage_quickpkg' && return 0
122
		    '*:installed package:_gentoo_packages installed'
121
	  fi
123
	  fi
122
}
124
}
123
 
125
124
# Stuff for emerge
126
# Stuff for emerge
125
127
126
_emerge () {
128
_emerge () {
127
    local state
129
    local nopkg_opts all noask_opts bopts install_args common_args profiles
128
    if (( CURRENT == 2 ));then
129
        _arguments -s \
130
            '*:*:->actions' \
131
            "$common_args[@]" "$install_args[@]" && return 0
132
    elif (( CURRENT > 2 ));then
133
        case "$words[2]" in
134
	    unmerge|-C)
135
	 	  if compset -P '(\\|)[><][=]'; then
136
			_arguments -s \
137
		    	'*:installed pkgname with versions:_portage_unmerge_vers' "$common_args[@]" && return 0
138
		  elif compset -P '(\\|)[<=>]'; then
139
			_arguments -s \
140
		    	'*:installed pkgname with versions:_portage_unmerge_vers' "$common_args[@]" && return 0
141
		  else 
142
			_arguments -s \
143
		    	'*:installed pkgname:_portage_unmerge' "$common_args[@]" && return 0
144
		  fi
145
		;;
146
	    clean|-c)
147
	    	_arguments -s \
148
		    '*:installed pkgname:_portage_clean' "$common_args[@]" && return 0
149
		;;
150
	    --usepkgonly|-K)
151
		_arguments -s \
152
		    '*:use package only:_portage_tbz2list' "$common_args[@]" && return 0
153
		;;
154
	    depclean|help|-h|info|regen|sync|rsync|--searchdesc|-S|search|-s|prune|-P)
155
		;;
156
	    --resume|--skipfirst)
157
	    	_arguments -s \
158
		 '--skipfirst[Removes the first package in the resume list]' \
159
		    "$common_args[@]"  && return 0
160
		;;
161
	    *)
162
		_arguments -s \
163
		    '*:*:->install_portage' \
164
		    "$common_args[@]" \
165
		    "$install_args[@]" && return 0
166
		;;
167
        esac
168
    fi
169
    while [[ -n "$state" ]]; do
170
        lstate=$state
171
        state=''
172
        case "$lstate" in
173
	    actions)
174
		if compset -P '(\\|)[><][=]'; then
175
		_alternative \
176
			'*:portage:_ebuild_cache'
177
178
		elif compset -P '(\\|)[<=>]'; then
179
		_alternative \
180
			'*:portage:_ebuild_cache'
181
				
182
		else 
183
		_alternative \
184
		':emerge actions:_actions' \
185
		     '*:portage:_portage_pkglist'
186
		fi
187
188
		;;
189
	    install_portage)
190
		if compset -P '(\\|)[><][=]'; then
191
		_alternative \
192
			'*:portage:_ebuild_cache'
193
		elif compset -P '(\\|)[<=>]'; then
194
		_alternative \
195
			'*:portage:_ebuild_cache'
196
		else
197
		_alternative \
198
		     '*:portage:_portage_pkglist'
199
		fi
200
		;;
201
        esac
202
    done
203
}
204
205
#Function to show only installed packages   -- pkgname (no category or version #)
206
_portage_unmerge(){
207
    installed_portage=(/var/db/pkg/*-*/*)
208
    installed_pkgname=${(M)${${installed_portage##*/}%%-[0-9]*}}
209
    _tags -s installed_pkgname && { compadd "$@" ${(kv)=installed_pkgname} }
210
    _path_files -/ -W "/var/db/pkg/"
211
}
212
130
213
#Function to show only installed packages -- no _path_files 
131
  noask_opts=(-p -a --pretend --ask --regen --info --search -s --searchdesc \
214
_portage_quickpkg(){
132
  -S --version -V --help -h --metadata)
215
    installed_portage=(/var/db/pkg/*-*/*)
216
    installed_pkgname=${(M)${${installed_portage##*/}%%-[0-9]*}}
217
    _tags -s installed_pkgname && { compadd "$@" ${(kv)=installed_pkgname} }
218
}
219
220
#Function to show only installed packages -- cat/name-ver
221
_portage_unmerge_vers(){
222
    installed_portage=(/var/db/pkg/*-*/*)
223
    installed_pkgname=${(M)${${installed_portage##*/}}}
224
    _tags -s installed_pkgname && {  compadd "$@" ${(kv)=installed_pkgname} }
225
    _path_files -/ -W "/var/db/pkg/"
226
}
227
133
228
#Functions to show "cat/name", classes and dependencies
134
  nopkg_opts=(--resume --skipfirst -c --clean -h --help --depclean --info \
229
_portage_clean() {
135
  --metadata -P --prune --regen -s --search -S --searchdesc --sync -C \
230
    installed_portage=(/var/db/pkg/*-*/*)
136
  --unmerge -V --version -i --inject)
231
    installed_dir=/var/db/pkg/
137
232
    installed_pkg=${installed_portage//$installed_dir/}
138
  bopts=($nopkg_opts -b --buildpkg -B --buildpkgonly -G --getbinpkgonly -g \
233
    installed_pkgname=${(M)${${installed_portage##*/}%%-[0-9]*}}
139
  --getbinpkg -k --usepkg -K --usepkgonly --fetch-all-uri -f -F --fetchonly)
234
    _tags -s installed_pkg && { compadd "$@" -k installed_pkg || compadd "$@" ${(kv)=installed_pkg} }
140
235
    _tags -s installed_pkgname && { compadd "$@" -k installed_pkgname || compadd "$@" ${(kv)=installed_pkgname} }
141
  all=($bopts -l --changelog --columns --deep -D --emptytree -e --newuse \
236
}
142
  --noconfmem --nodeps -O --noreplace -n --oneshot -1 -o --onlydeps --tree -t \
237
143
  -u --update -U --upgradeonly)
238
#Function to show tbz2 files available
144
239
_portage_tbz2list() {
145
  common_args=(
240
    # this doesn't take care of ${PORTAGE_BINHOST}. If Gentoo official
146
    "($noask_opts --sync)"{-p,--pretend}"[Simply  display  what would be done]"
241
    # binary mirror will be available we should rewrite it accordingly.
147
    "($noask_opts)"{-a,--ask}"[Ask what would be done]"
242
    _path_files -g \*.tbz2 -W "${pkgdir}/All"
148
    '(-d --debug --help -h --version -V)'{-d,--debug}'[Tells emerge to run the emerge command in debug mode]'
243
}
149
    '(--quiet -q --verbose -v)'{-q,--quiet}'[General outcome is a reduced or condensed output]'
150
    '(--verbose -v --quiet -q)'{-v,--verbose}'[Tell emerge to run in verbose mode]'
151
    '--nospinner[Disables the spinner for the session]'
152
  )
153
  install_args=(
154
    "($bopts)"{-b,--buildpkg}"[Tells emerge to build binary packages]"
155
    "($bopts)"{-B,--buildpkgonly}"[Tells emerge to only build binary packages]"
156
    "($nopkg_opts --emptytree -e -l --changelog --usepkgonly -K)"{-l,--changelog}"[This will show the ChangeLog]"
157
    "($nopkg_opts -t --tree)--columns[Displays versions in aligned format]"
158
    "($nopkg_opts -D --deep)"{-D,--deep}"[Consider the entire dependency tree of packages]"
159
    "($nopkg_opts -e -l --changelog --emptytree)"{-e,--emptytree}"[Only consider glibc as installed packages]"
160
    "($all --nospinner --pretend -p)"{-i,--inject}"[Portage thinks that this package is installed]"
161
    "($nopkg_opts $bopts)"{-f,--fetchonly}"[Just perform fetches for all packages]"
162
    "($nopkg_opts $bopts)"{-F,--fetch-all-uri}"[As -f, but prints all mirrors when used with -p]"
163
    "($bopts)"{-g,--getbinpkg}"[Tells emerge to download binary package]"
164
    "($bopts)"{-G,--getbinpkgonly}"[As --getbinpkg, but does not use local info]"
165
    "($nopkg_opts)--noconfmem[Causes portage to disregard merge records]"
166
    "($nopkg_opts -O --nodeps)"{-O,--nodeps}"[Merges specified packages without merging dependencies]"
167
    "($nopkg_opts -n --noreplace)"{-n,--noreplace}"[Skip packages already installed]"
168
    "($nopkg_opts)"{-1,--oneshot}"[Do not add package to the world profile]"
169
    "($nopkg_opts --onlydeps -o)"{-o,--onlydeps}"[Only merge (or pretend to merge) the dependencies]"
170
    "($nopkg_opts --columns -t --tree)"{-t,--tree}"[Show dependency tree]"
171
    "($nopkg_opts --update -u)"{-u,--update}"[Updates packages to the most recent version available]"
172
    "($nopkg_opts --upgradeonly -U)"{-U,--upgradeonly}"[Do not update packages to a lower version]"
173
    "($bopts)"{-k,--usepkg}"[Tells emerge to use binary packages if available]"
174
    "($bopts --changelog -l)"{-K,--usepkgonly}"[Tells emerge to use binary packages only]"
175
    "($all)"{-c,--clean}"[Cleans the system by removing packages]"
176
    '(: -)'{-h,--help}'[Displays help]:subject:(sync config system)'
177
    "(: $all)--depclean[Clean all packages that have no reason for being installed]"
178
    "(: $all $noask_opts --nospinner --quiet -q)--info[This is a list of information to include in bug reports]"
179
    "(: -)--metadata[Generate metadata]"
180
    "($nopkg_opts --usepkgonly -K)--newuse[Include installed packages which have changed USE flags]"
181
    "($all)"{-P,--prune}"[Removes all but the latest versions of matching packages]"
182
    "(: $all $noask_opts --verbose -v)--regen[Causes portage to check and update the dependency cache]"
183
    "(: $all $noask_opts --verbose -v)"{-s,--search}"[Searches for matches]"
184
    "(: $all $noask_opts --verbose -v)"{-S,--searchdesc}"[Matches the seachdesc string against the description field]"
185
    "(: $all --pretend -p)--sync[Initiates a portage tree update]"
186
    "($all)"{-C,--unmerge}"[Removes all matching packages]"
187
    '(: -)'{-V,--version}'[Display version info]'
188
    "(: $all[3,-1])--resume[Resumes the last merge operation]"
189
    "(: $all[3,-1])--skipfirst[Removes the first package in the resume list]"
190
  )
191
  profiles=(
192
    'world[All packages in the world profile]'
193
    'system[All packages in the system profile]'
194
  )
195
196
197
  # Dispatch
198
  if (( $words[(I)(--(unmerge|clean|prune)|-[[:alpha:]]#(C|c|P)[[:alpha:]]#)] )) ; then
199
	if compset -P '(\\|)(>=|<=|<|>|=)'; then
200
	    _arguments -s \
201
		'*:installed package:_gentoo_packages installed_versions' && return 0
202
	else
203
	    _arguments -s \
204
		"$common_args[@]" "$install_args[@]" \
205
		"*:installed package:_gentoo_packages installed" && return 0
206
	fi
244
207
245
#Function to show all available portage names
208
  elif (( $words[(I)(world|system)] )) ; then
246
_portage_pkglist(){
209
    _arguments -s \
247
    portage_classlist="world system"
210
	"$common_args[@]" "$install_args[@]" \
248
    portage_pkglist="$portage_pkglist ${portage_classlist}"
211
	"($nopkg_opts[1,-2] --inject -i --oneshot -1):" && return 0
249
    _tags -s portage_pkglist && { compadd "$@" -k portage_pkglist || compadd "$@" ${(kv)=portage_pkglist} }
212
250
    _path_files -/ -W "${portdir}"
213
  elif (( $words[(I)(--usepkgonly|-[[:alnum:]]#K[[:alnum:]]#)] )) ; then
251
    # XXX: If I add ${portdir_overlay} category completion won't work properly
214
    _arguments -s \
252
    #[[ -n "${portdir_overlay}" ]] && _path_files -/ -W "${portdir_overlay}"
215
	"$common_args[@]" "$install_args[@]" \
253
    _path_files -g \*.ebuild
216
	'*:binary package:_gentoo_packages binary' && return 0
217
218
  elif [[ $words[-3] == (--help|-h) ]] ; then
219
      _message "No more arguments" && return 0
220
221
  else
222
	if compset -P '(\\|)(>=|<=|<|>|=)'; then
223
	    _arguments \
224
		"*:portage:_gentoo_packages available_versions" && return 0
225
226
	elif (( $words[(I)(--inject|-i)] )) ; then
227
	    _arguments -s \
228
		"$common_args[@]" "$install_args[@]" \
229
		"*:portage:_gentoo_packages available_versions" && return 0
230
	else
231
	    _arguments -s \
232
		"$common_args[@]" "$install_args[@]" \
233
		"($nopkg_opts)::portage: _values 'profile' \$profiles[@] " \
234
		"($nopkg_opts)*:portage:_gentoo_packages available" && return 0
235
	fi
236
  fi
254
}
237
}
255
#Function for matching all ebuilds  pkg-ver (slow if asking for all packages)
256
_ebuild_cache(){
257
    if _cache_invalid portage_ebuilds || ! _retrieve_cache portage_ebuilds; then
258
259
    overlay_ebuilds=($portdir_overlay/*-*/*/*)
260
    overlay_list=${${(M)${overlay_ebuilds##*/}#*ebuild}%%.ebuild}
261
    metadata_ebuilds=($portdir/metadata/cache/*-*/*)
262
    metadata_list=${(M)${${metadata_ebuilds##*/}}}
263
238
264
	 _store_cache portage_ebuilds metadata_list overlay_list
265
    fi
266
    _tags -s metadata_list && {compadd "$@" ${(kv)=metadata_list} } 
267
    _tags -s overlay_list && {compadd "$@" ${(kv)=overlay_list} }
268
}
269
239
270
local update_policy
271
zstyle -s ":completion:*:*:emerge:*" cache-policy update_policy
272
if [[ -z "$update_policy" ]]; then
273
  zstyle ":completion:*:*:emerge:*" cache-policy _ebuilds_caching_policy
274
fi
275
276
_ebuilds_caching_policy () {
277
  # rebuild if cache is more than a week old
278
  oldp=( "$1"(mw+1) )
279
  (( $#oldp )) && return 0
280
}
281
240
282
common_args=(
241
local gentoo_runlevels
283
    {'(-p -a --ask)--pretend','(--pretend -a --ask)-p'}'[simply  display  what would be done]'
242
gentoo_runlevels=(/etc/runlevels/*(:t))
284
    {'(-p -a --pretend)--ask','(--pretend -p --ask)-a'}'[ask what would be done]'
285
    {'(-d)--debug','(--debug)-d'}'[Tells emerge to run the emerge command in debug mode]'
286
)
287
install_args=(
288
    {'(--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]'
289
    {'(-b --buildpkgonly -B --changelog -l)--buildpkg','(--changelog -l --buildpkg --buildpkgonly -B)-b'}'[Tells emerge to build binary packages]'
290
    {'(-B -b --buildpkg --changelog -l)--buildpkgonly','(--changelog -l --buildpkgonly --buildpkg -b)-B'}'[Tells emerge to only build binary packages]'
291
    {'(-D --changelog -l)--deep','(-l --changelog --deep)-D'}'[Consider the entire dependency tree of packages]'
292
    {'(-e -l --changelog)--emptytree','(--emptytree -l --changelog)-e'}'[Only consider glibc as installed packages]'
293
    {'(-f -l --changelog)--fetchonly','(-l --changelog --fetchonly)-f'}'[Just perform fetches for all packages]'
294
    '(-l --changelog)--noconfmem[Causes portage to disregard merge records]'
295
    {'(--changelog -l -O)--nodeps','(--nodeps --changelog -l)-O'}'[Merges specified packages without merging dependencies]'
296
    {'(-l --changelog -n)--noreplace','(-l --changelog --noreplace)-n'}'[Skip packages already installed]'
297
    '(-l --changelog)--nospiner[Disables the spinner for the session]'
298
    '(-l --changelog)--oneshot[Do not add package to the world profile]'
299
    {'(--onlydeps --changelog -l)-o','(--changelog -o -l)--onlydeps'}'[Only merge (or pretend to merge) the dependencies]'
300
    {'(--quiet --changelog -l)-q','(-q --changelog -l)--quiet'}'[General outcome is a reduced or condensed output]'
301
    {'(-l --changelog -t)--tree','(-l --changelog --tree)-t'}'[Show dependency tree]'
302
    {'(--update --changelog -l)-u','(-u --changelog -l)--update'}'[Updates packages to the most recent version available]'
303
    {'(--upgradeonly --changelog -l)-U','(-U --changelog -l)--upgradeonly'}'[Do not update packages to a lower version]'
304
    {'(--usepkg --changelog -l)-k','(-k --changelog -l)--usepkg'}'[Tells emerge to use binary packages if available]'
305
    {'(--usepkgonly --changelog -l)-K','(-K --changelog -l)--usepkgonly'}'[Tells emerge to use binary packages only]'
306
    {'(--verbose)-v','(-v)--verbose'}'[Tell emerge to run in verbose mode]'
307
    '(-p --pretend -a --ask)--columns[Displays versions in aligned format]'
308
    '--resume[Resumes the last merge operation]'
309
)
310
311
_actions() {
312
    _values "emerge actions" \
313
	'sync[Initiates a portage tree update]' \
314
	'rsync[Initiates a portage tree update]' \
315
	'unmerge[Removes all matching packages]' \
316
	'search[Searches for matches]' \
317
	'regen[Causes portage to check and update the dependency cache]' \
318
	'prune[Removes all but the latest versions of matching packages]' \
319
	'inject[Portage thinks that this package is installed]' \
320
	'info[This is a list of information to include in bug reports]' \
321
	'help[Displays help]' \
322
	'depclean[Clean all packages that have no reason for being installed]'\
323
	'clean[Cleans the system by removing packages]' \
324
	'-c[Cleans the system by removing packages]' \
325
	'-h[Displays help]' \
326
	'-i[Portage thinks that this package is installed]' \
327
	'-P[Removes all but the latest versions of matching packages]' \
328
	'-s[Searches for matches]' \
329
	'-S[Matches the search string against the description field]' \
330
	'--searchdesc[Matches the search string against the description field]' \
331
	'-C[Removes all matching packages]' \
332
	'world[Represent all packages in the world profiles]' \
333
	'system[Represent all the system packages]' 
334
}
335
local portage_pkglist gentoo_runlevels portdir pkgdir portdir_overlay overlay
336
#Reading informations from make.conf
337
[[ -n "${PORTDIR}" ]] && portdir="${PORTDIR}"
338
[[ -n "${PKGDIR}" ]] && pkgdir="${PKGDIR}"
339
if [[ -n "${PORTDIR_OVERLAY}" ]] ; then
340
    for overlay in ${=PORTDIR_OVERLAY} ; do
341
	portdir_overlay=(${overlay} ${portdir_overlay})
342
    done
343
fi
344
[[ -r /etc/make.globals ]] && source /etc/make.globals
345
[[ -r /etc/make.conf ]] && source /etc/make.conf
346
347
[[ -z "${portdir}" ]] && portdir="${PORTDIR}"
348
[[ -z "${pkgdir}" ]] && pkgdir="${PKGDIR}"
349
if [[ -z "${portdir_overlay}" ]] ; then
350
    for overlay in ${=PORTDIR_OVERLAY} ; do
351
	portdir_overlay=(${overlay} ${portdir_overlay})
352
    done
353
fi
354
355
portage_pkglist=(${portdir}/*-*/* ${portdir_overlay}/*-*/*)
356
portage_pkglist=(${portage_pkglist##*/})
357
gentoo_runlevels=(/etc/runlevels/*)
358
gentoo_runlevels=(${${gentoo_runlevels/\/etc\/runlevels\//}%/})
359
243
360
case "$service" in
244
case "$service" in
361
	emerge)
245
	emerge)

Return to bug 71957