1 |
commit: 99c322fb13deffac2f1ee9bebbfd43d3eaf08b33 |
2 |
Author: Vadim A. Misbakh-Soloviov <mva <AT> mva <DOT> name> |
3 |
AuthorDate: Fri Aug 29 18:45:26 2014 +0000 |
4 |
Commit: Vadim A. Misbakh-Soloviov <mva <AT> mva <DOT> name> |
5 |
CommitDate: Fri Aug 29 18:45:26 2014 +0000 |
6 |
URL: http://sources.gentoo.org/gitweb/?p=proj/zsh-completion.git;a=commit;h=99c322fb |
7 |
|
8 |
_gentoo_packages, _portage: Added sets completion |
9 |
|
10 |
Signed-off-by: Vadim A. Misbakh-Soloviov <mva <AT> mva.name> |
11 |
|
12 |
--- |
13 |
_gentoo_packages | 160 +++++++++++++++++++++++++++++++++++++++++-------------- |
14 |
_portage | 6 ++- |
15 |
2 files changed, 125 insertions(+), 41 deletions(-) |
16 |
|
17 |
diff --git a/_gentoo_packages b/_gentoo_packages |
18 |
index f991cfb..e770181 100644 |
19 |
--- a/_gentoo_packages |
20 |
+++ b/_gentoo_packages |
21 |
@@ -1,5 +1,6 @@ |
22 |
#autoload |
23 |
|
24 |
+setopt extendedglob bareglobqual |
25 |
#Description: |
26 |
# functions for gentoo packages |
27 |
# inspired by _deb_packages |
28 |
@@ -18,12 +19,9 @@ _portdir() { |
29 |
source /etc/make.conf 2>/dev/null |
30 |
source /etc/portage/make.conf 2>/dev/null |
31 |
|
32 |
- overlaypath+=(${PORTDIR_OVERLAY}) |
33 |
+ overlaypath+=(${(@)PORTDIR_OVERLAY}) |
34 |
|
35 |
- # strip out duplicates |
36 |
- overlaypath=($(printf "%s\n" "${overlaypath[@]}" | sort -u)) |
37 |
- |
38 |
- echo "${overlaypath[@]}" |
39 |
+ echo "${(@u)overlaypath}" |
40 |
else |
41 |
mainreponame=$(_parsereposconf DEFAULT main-repo) |
42 |
mainrepopath=$(_parsereposconf ${mainreponame} location) |
43 |
@@ -35,68 +33,146 @@ _portdir() { |
44 |
source /etc/make.conf 2>/dev/null |
45 |
source /etc/portage/make.conf 2>/dev/null |
46 |
|
47 |
- echo "${PORTDIR}" |
48 |
- |
49 |
- if [[ ${1} == -o ]]; then⋅ |
50 |
- echo "${PORTDIR_OVERLAY}" |
51 |
- fi⋅⋅⋅ |
52 |
+ if [[ "-o" == ${1} ]]; then |
53 |
+ echo "${(@u)PORTDIR_OVERLAY}" |
54 |
+ else |
55 |
+ echo "${PORTDIR}" |
56 |
+ fi |
57 |
fi |
58 |
} |
59 |
|
60 |
_parsereposconf() { |
61 |
- local f insection line section v value var |
62 |
+ local v f insection section arr; |
63 |
|
64 |
for f in /usr/share/portage/config/repos.conf \ |
65 |
/etc/portage/repos.conf \ |
66 |
/etc/portage/repos.conf/*.conf; do |
67 |
|
68 |
[[ -f ${f} ]] || continue |
69 |
- insection=0 |
70 |
+ insection=0; |
71 |
+ declare -A arr; |
72 |
+ IFS='= '; |
73 |
|
74 |
- while read -r line; do |
75 |
- # skip comments and blank lines |
76 |
- [[ -z ${line} || ${line} == '#'* ]] && continue |
77 |
+ while read -r name value; do |
78 |
+ [[ -z ${name} || ${name} == '#'* ]] && continue |
79 |
|
80 |
- if [[ ${insection} == 1 && ${line} == '['*']' ]]; then |
81 |
- # End of the section we were interested in so stop |
82 |
- secname+=(${line//[(\[|\])]/}) # record name for -l |
83 |
+ if [[ (${name} == '['*']') && (-z ${value}) ]]; then |
84 |
+ value=${name//(\]|\[)}; |
85 |
+ name="section"; |
86 |
+ fi; |
87 |
+ arr[${name}]=${value}; |
88 |
+ |
89 |
+ if [[ ${insection} == 1 && ${name} == "section" ]]; then |
90 |
break |
91 |
- elif [[ ${line} == '['*']' ]]; then |
92 |
- # Entering a new section, check if it's the one we want |
93 |
- section=${line//[(\[|\])]/} |
94 |
- [[ ${section} == "${1}" ]] && insection=1 |
95 |
- secname+=(${section}) # record name for -l |
96 |
+ elif [[ ${name} == "section" ]]; then |
97 |
+ [[ ${value} == ${1} ]] && insection=1 |
98 |
+ secname+=(${value}) |
99 |
elif [[ ${insection} == 1 ]]; then |
100 |
- # We're in the section we want, grab the values |
101 |
- var=${line%%=*} |
102 |
- var=${var// /} |
103 |
- value=${line#*=} |
104 |
- value=${value# } |
105 |
- [[ ${var} == ${2} ]] && v=${value} |
106 |
+ if [[ ${name} == ${2} ]]; then |
107 |
+ v=${value}; |
108 |
+ fi |
109 |
fi |
110 |
continue |
111 |
- done < "${f}" |
112 |
+ done < ${f} |
113 |
done |
114 |
|
115 |
- if [[ ${1} == -l ]]; then |
116 |
- echo "${secname[@]}" |
117 |
+ if [[ "-l" == ${1} ]]; then |
118 |
+ echo "${(@)secname}" |
119 |
else |
120 |
echo "${v}" |
121 |
fi |
122 |
} |
123 |
|
124 |
+_parsesetsconf() { |
125 |
+ [[ -d ${1} ]] || continue |
126 |
+ |
127 |
+ local v f places sections setsconf insection section arr; |
128 |
+ |
129 |
+ if [[ -d ${1}/sets ]]; then |
130 |
+ setsconf=(${1}/sets/*.conf(N)); |
131 |
+ [[ (($#setsconf > 0)) ]] && places=(${setsconf}) |
132 |
+ elif [[ -f ${1}/sets.conf ]]; then |
133 |
+ places=(${1}/sets.conf) |
134 |
+ fi |
135 |
+ |
136 |
+ for f in ${(@)places}; do |
137 |
+ if [[ -r ${f} ]]; then |
138 |
+ insection=0; |
139 |
+ declare -A arr; |
140 |
+ IFS='= '; |
141 |
+ while read -r name value; do |
142 |
+ [[ -z ${name} || ${name} == '#'* ]] && continue |
143 |
+ |
144 |
+ if [[ (${name} == '['*']') && (-z ${value}) ]]; then |
145 |
+ value=${name//(\]|\[)}; |
146 |
+ name="section"; |
147 |
+ fi; |
148 |
+ arr[${name}]=${value}; |
149 |
+ |
150 |
+ if [[ ${insection} == 1 && ${name} == "section" ]]; then |
151 |
+ [[ "sets" == ${2} ]] && [[ ! ${value} =~ "sets" ]] && sections+=(${value}) |
152 |
+ insection=0; |
153 |
+ elif [[ ${name} == "section" ]]; then |
154 |
+ [[ ${value} =~ "${1:t} sets" ]] && insection=1 |
155 |
+ [[ "sets" == ${2} ]] && [[ ! ${value} =~ "sets" ]] && sections+=(${value}) |
156 |
+ elif [[ ${insection} == 1 ]]; then |
157 |
+ [[ "sets" == ${2} ]] && continue |
158 |
+ if [[ ${name} == "directory" ]]; then |
159 |
+ v=${value}; |
160 |
+ fi |
161 |
+ fi |
162 |
+ continue |
163 |
+ done < ${f} |
164 |
+ fi |
165 |
+ done |
166 |
+ |
167 |
+ if [[ "sets" == ${2} ]]; then |
168 |
+ [[ ((${#sections} > 0)) ]] && echo ${(@)sections} |
169 |
+ else |
170 |
+ [[ ((${#v} > 0)) ]] && echo ${v:t}; |
171 |
+ fi |
172 |
+} |
173 |
+ |
174 |
+_get_installed_sets() { |
175 |
+ local sets; |
176 |
+ sets=($(</var/lib/portage/world_sets)); |
177 |
+ if [[ ((${#sets} > 0)) ]]; then |
178 |
+ echo "${(o@)^sets}" |
179 |
+ fi |
180 |
+} |
181 |
+ |
182 |
+_get_available_sets() { |
183 |
+ trees=($(_portdir -o) /etc/portage /usr/share/portage/config) |
184 |
+ for PORTDIR in ${(@)trees}; do |
185 |
+ if [[ -d ${PORTDIR} ]]; then |
186 |
+ setsdir="$(_parsesetsconf ${PORTDIR})" |
187 |
+ [[ ! -z "${setsdir}" ]] && setspath="${PORTDIR}/${setsdir}" || setspath="${PORTDIR}/sets" |
188 |
+ if [[ -d "${setspath}" ]]; then |
189 |
+ setsfiles=(${setspath}/*~*.conf(N)) |
190 |
+ for set in ${setsfiles[@]}; do |
191 |
+ sets+=(${set}(:t)) |
192 |
+ done; |
193 |
+ sets+=($(_parsesetsconf ${PORTDIR} sets)) |
194 |
+ fi |
195 |
+ fi |
196 |
+ done |
197 |
+ if [[ ((${#sets} > 0)) ]]; then |
198 |
+ echo "@${(o@)^sets}" |
199 |
+ fi |
200 |
+} |
201 |
+ |
202 |
# Completion function to show useflags. |
203 |
_gentoo_packages_update_useflag(){ |
204 |
local flags trees |
205 |
|
206 |
flags=() |
207 |
- trees=( $(_portdir) $(_portdir -o) ) |
208 |
+ trees=($(_portdir) $(_portdir -o)) |
209 |
|
210 |
for PORTDIR in ${trees[@]}; do |
211 |
[[ -r ${PORTDIR}/profiles/use.desc ]] && |
212 |
- flags+=( ${${(M)${(f)"$(<$PORTDIR/profiles/use.desc)"}:#* - *}%% - *} ) |
213 |
+ flags+=(${${(M)${(f)"$(<$PORTDIR/profiles/use.desc)"}:#* - *}%% - *}) |
214 |
[[ -r ${PORTDIR}/profiles/use.local.desc ]] && |
215 |
- flags+=( ${${${(M)${(f)"$(<$PORTDIR/profiles/use.local.desc)"}#* - *}%% - *}#*:} ) |
216 |
+ flags+=(${${${(M)${(f)"$(<$PORTDIR/profiles/use.local.desc)"}#* - *}%% - *}#*:}) |
217 |
done |
218 |
|
219 |
compadd $flags |
220 |
@@ -115,7 +191,7 @@ _gentoo_packages_update_active_useflag(){ |
221 |
_gentoo_packages_update_category(){ |
222 |
local trees category |
223 |
|
224 |
- trees=( $(_portdir) $(_portdir -o) ) |
225 |
+ trees=($(_portdir) $(_portdir -o)) |
226 |
category=( $trees/*-*(/:t) ) |
227 |
_wanted cat_packages expl 'category' compadd "$@" $category |
228 |
} |
229 |
@@ -125,8 +201,11 @@ _gentoo_packages_update_installed(){ |
230 |
installed_dir="/var/db/pkg" |
231 |
installed_portage=($installed_dir/*-*/*) |
232 |
|
233 |
- installed_pkgname=( ${${installed_portage:t}%%-[0-9]*} ) |
234 |
- _wanted packages expl 'category/package' compadd "$@" ${installed_pkgname} |
235 |
+ installed_sets=($(_get_installed_sets)) |
236 |
+ _wanted installed_sets expl 'installed set' compadd "$@" "${(o@)^installed_sets}" |
237 |
+ |
238 |
+ installed_pkgname=(${${installed_portage:t}%%-[0-9]*}) |
239 |
+ _wanted packages expl 'package' compadd "$@" ${installed_pkgname} |
240 |
|
241 |
installed_list=( ${${installed_portage#$installed_dir/}%%-[0-9]*} ) |
242 |
_wanted cat_packages expl 'category/package' _multi_parts "$@" / installed_list |
243 |
@@ -138,7 +217,7 @@ _gentoo_packages_update_installed_versions(){ |
244 |
installed_portage=(/var/db/pkg/*-*/*) |
245 |
_wanted packages expl 'package' compadd "$@" ${installed_portage:t} |
246 |
|
247 |
- installed_list=( ${installed_portage##*/pkg/} ) |
248 |
+ installed_list=(${installed_portage##*/pkg/}) |
249 |
_wanted cat_packages expl 'category/package' _multi_parts "$@" / installed_list |
250 |
} |
251 |
|
252 |
@@ -157,6 +236,9 @@ _gentoo_packages_update_available(){ |
253 |
trees=( $(_portdir) $(_portdir -o) ) |
254 |
category=( $trees/*-*(/:t) ) |
255 |
|
256 |
+ available_sets=( $(_get_available_sets) ) |
257 |
+ _wanted available_sets expl 'available sets' compadd "${@}" "${(@)available_sets}" |
258 |
+ |
259 |
packages=( $trees/*-*/*(:t) ) |
260 |
_wanted packages expl 'package' compadd - "${(@)packages}" |
261 |
|
262 |
|
263 |
diff --git a/_portage b/_portage |
264 |
index ee7b2ab..e241357 100644 |
265 |
--- a/_portage |
266 |
+++ b/_portage |
267 |
@@ -138,7 +138,8 @@ _emerge () { |
268 |
else |
269 |
_arguments -s \ |
270 |
"$common_args[@]" "$install_args[@]" \ |
271 |
- "*:installed package:_gentoo_packages installed" && return 0 |
272 |
+ "*:installed package:_gentoo_packages installed" \ |
273 |
+ && return 0 |
274 |
fi |
275 |
|
276 |
elif (( $words[(I)(world|system)] )) ; then |
277 |
@@ -167,7 +168,8 @@ _emerge () { |
278 |
_arguments -s \ |
279 |
"$common_args[@]" "$install_args[@]" \ |
280 |
"($nopkg_opts)::portage: _values 'profile' \$profiles[@] " \ |
281 |
- "($nopkg_opts)*:portage:_gentoo_packages available" && return 0 |
282 |
+ "($nopkg_opts)*:portage:_gentoo_packages available" \ |
283 |
+ && return 0 |
284 |
fi |
285 |
fi |
286 |
} |