1 |
commit: 8a1dcc8e862e1ca00fec39f921bcd2d9cf55c0e7 |
2 |
Author: Felix Neumärker <xdch47 <AT> posteo <DOT> de> |
3 |
AuthorDate: Wed Feb 19 16:44:18 2020 +0000 |
4 |
Commit: Vadim Misbakh-Soloviov <mva <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Feb 19 18:50:56 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/zsh-completion.git/commit/?id=8a1dcc8e |
7 |
|
8 |
Merge PR #22 (eselect fixes) |
9 |
|
10 |
[PATCH 1/6] _eselect: php-module completion |
11 |
[PATCH 2/6] _eselect: generic uses _describe instead of values |
12 |
[PATCH 3/6] _ekeyword: inital completion |
13 |
[PATCH 4/6] _eselect: news modules - fix order |
14 |
[PATCH 5/6] _eselect: completion for rc module / rc-config |
15 |
[PATCH 6/6] _eselect: repository fixes + options |
16 |
|
17 |
Signed-off-by: Felix Neumärker <xdch47 <AT> posteo.de> |
18 |
Signed-off-by: Vadim Misbakh-Soloviov <mva <AT> gentoo.org> |
19 |
|
20 |
src/_ekeyword | 23 +++++++++ |
21 |
src/_eselect | 161 ++++++++++++++++++++++++++++++++++++++++++---------------- |
22 |
2 files changed, 139 insertions(+), 45 deletions(-) |
23 |
|
24 |
diff --git a/src/_ekeyword b/src/_ekeyword |
25 |
new file mode 100644 |
26 |
index 0000000..c86ebb0 |
27 |
--- /dev/null |
28 |
+++ b/src/_ekeyword |
29 |
@@ -0,0 +1,23 @@ |
30 |
+#compdef ekeyword |
31 |
+ |
32 |
+local -a arguments=( |
33 |
+ '(- :)'{-h,--help}'[Show this help message and exit]' |
34 |
+ '(-m --manifest)'{-m,--manifest}'[Run `ebuild manifest` on the ebuild after modifying it]' |
35 |
+ '(-n --dry-run)'{-n,--dry-run}'[Show what would be changed, but do not commit]' |
36 |
+ '(-v --verbose)'{-v,--verbose}'[Be verbose while processing things]' |
37 |
+ '(-q --quiet)'{-q,--quiet}'[Be quiet while processing things (only show errors)]' |
38 |
+ '(--format)'--format':Select output format for showing differences:_values -V ekeywordsfmt "ekeywords formats" auto color-inline inline short-multi long-multi' |
39 |
+ '(- :)'{-V,--version}'[Show version information]' |
40 |
+) |
41 |
+ |
42 |
+(( $+functions[_ekeywordargs] )) || _ekeywordargs() { |
43 |
+ _files -g \*.ebuild |
44 |
+ |
45 |
+ local -a keywords=(all $(_gentoo_arches)) |
46 |
+ |
47 |
+ compset -P '(\^|\~)' |
48 |
+ _values -V "keywords" "gentoo arches" ${keywords[@]} |
49 |
+} |
50 |
+ |
51 |
+_arguments ${arguments[@]} "*:ekeywordargs:_ekeywordargs" |
52 |
+ |
53 |
|
54 |
diff --git a/src/_eselect b/src/_eselect |
55 |
index 77b9fd6..ce185a8 100644 |
56 |
--- a/src/_eselect |
57 |
+++ b/src/_eselect |
58 |
@@ -45,25 +45,24 @@ _eselect_parse_generic() { |
59 |
} |
60 |
|
61 |
_eselect_parse_action_list() { |
62 |
- local eselect_list |
63 |
- local idx descr |
64 |
- local arr_items_selected=$2 |
65 |
- local arr_items_unselected=$3 |
66 |
- |
67 |
- eselect_list="$(LANG=C COLUMNS=100 eselect --colour=no $1 list 2> /dev/null)" |
68 |
- while IFS="" read -r ele ; do |
69 |
- echo "$ele" | read idx descr |
70 |
- idx=${idx#*\[} |
71 |
- idx=${idx%\]*} |
72 |
- if [[ "$idx" =~ '^[0-9]+$' ]]; then |
73 |
- local stripped_descr="${descr% *\**}" |
74 |
- if [[ "${stripped_descr}" != "${descr}" ]] ; then |
75 |
- set -A $arr_items_selected ${(P)arr_items_selected} "$idx:${(q)descr}" |
76 |
- else |
77 |
- set -A $arr_items_unselected ${(P)arr_items_unselected} "$idx:${(q)descr}" |
78 |
- fi |
79 |
+ local idx item tag |
80 |
+ local -a _sel_items |
81 |
+ local -a _unsel_items |
82 |
+ |
83 |
+ while read idx item tag descr ; do |
84 |
+ if [[ "$idx" == '[' && "$item" == ']' ]] ; then |
85 |
+ continue |
86 |
+ fi |
87 |
+ if [[ ${tag} =~ '^[*@#]$' ]] ; then |
88 |
+ _sel_items+=($item) |
89 |
+ else |
90 |
+ _unsel_items+=($item) |
91 |
fi |
92 |
- done <<< "$eselect_list" |
93 |
+ done <<< $(LANG=C COLUMNS=100 eselect --colour=no $1 list 2> /dev/null | tail -n +2) |
94 |
+ |
95 |
+ set -A $2 ${_sel_items[@]} |
96 |
+ set -A $3 ${_unsel_items[@]} |
97 |
+ |
98 |
} |
99 |
|
100 |
_eselect_module_action() { |
101 |
@@ -78,9 +77,15 @@ _eselect_complete_action() { |
102 |
local actionname=$(_eselect_get_module) |
103 |
if (( $+functions[_eselect_complete_${actionname}_action] )) ; then |
104 |
_eselect_complete_${actionname}_action |
105 |
- else |
106 |
+ return 0 |
107 |
+ fi |
108 |
+ |
109 |
+ if (( $NORMARG + $(_eselect_action_index) == $CURRENT )) ; then |
110 |
_eselect_complete_action_generic ${actionname} |
111 |
+ return 0 |
112 |
fi |
113 |
+ |
114 |
+ _nothing |
115 |
} |
116 |
|
117 |
_eselect_get_module() { |
118 |
@@ -110,31 +115,29 @@ _eselect_module() { |
119 |
_eselect_parse_generic |
120 |
} |
121 |
|
122 |
-_eselect_complete_action_generic() { |
123 |
+(( $+function[_eselect_complete_action_generic] )) || _eselect_complete_action_generic() { |
124 |
local -a sel_items |
125 |
local -a unsel_items |
126 |
|
127 |
- if (( $NORMARG + $(_eselect_action_index) == $CURRENT )) ; then |
128 |
- case "$(_eselect_get_action)" in |
129 |
- ("set"|"enable")) |
130 |
- _eselect_parse_action_list $1 sel_items unsel_items |
131 |
- if (( $#unsel_items + $#sel_items > 0 )) ; then |
132 |
- _describe -t eselect_sel -V 'eselect items' unsel_items |
133 |
- if (( $#unsel_items + $#sel_items < 10 )) ; then |
134 |
- _describe -t eselect_unsel -V 'eselect already selected items' sel_items |
135 |
- fi |
136 |
- return 0 |
137 |
- fi |
138 |
- ;; |
139 |
- ("remove"|"disable")) |
140 |
- _eselect_parse_action_list $1 sel_items unsel_items |
141 |
- if [[ -n "${sel_items[@]}" ]] ; then |
142 |
- _describe -V 'eselect items' sel_items |
143 |
- return 0 |
144 |
+ case "$(_eselect_get_action)" in |
145 |
+ ("set"|"enable")) |
146 |
+ _eselect_parse_action_list $1 sel_items unsel_items |
147 |
+ if (( $#unsel_items + $#sel_items > 0 )) ; then |
148 |
+ _describe -t eselect_sel -V 'eselect items' unsel_items |
149 |
+ if (( $#unsel_items + $#sel_items < 10 )) ; then |
150 |
+ _describe -t eselect_unsel -V 'eselect already selected items' sel_items |
151 |
fi |
152 |
- ;; |
153 |
- esac |
154 |
- fi |
155 |
+ return 0 |
156 |
+ fi |
157 |
+ ;; |
158 |
+ ("remove"|"disable")) |
159 |
+ _eselect_parse_action_list $1 sel_items unsel_items |
160 |
+ if [[ -n "${sel_items[@]}" ]] ; then |
161 |
+ _describe -V 'eselect items' sel_items |
162 |
+ return 0 |
163 |
+ fi |
164 |
+ ;; |
165 |
+ esac |
166 |
|
167 |
_nothing |
168 |
} |
169 |
@@ -145,15 +148,19 @@ _eselect_complete_action_generic() { |
170 |
|
171 |
case "$(_eselect_get_action)" in |
172 |
("read"|"unread")) |
173 |
- local -a extra_items=('all:Read all news items') |
174 |
+ local idx descr |
175 |
+ while read idx descr ; do |
176 |
+ idx=${idx#'['} |
177 |
+ idx=${idx%']'} |
178 |
+ items=(${idx}:${(q)descr} ${items[@]}) |
179 |
+ done <<< $(eselect --colour=no news list 2> /dev/null | tail -n +2) |
180 |
+ items+=('all:Read all news items') |
181 |
if [[ $(_eselect_get_action) == "read" ]] ; then |
182 |
- extra_items=('new:Read unread news items (default)' "${extra_items[@]}") |
183 |
+ items+=('new:Read unread news items (default)') |
184 |
fi |
185 |
- _eselect_parse_action_list news items items |
186 |
|
187 |
- items=(${(q)extra_items[@]} ${(Oa)items}) |
188 |
if [[ -n "${items[@]}" ]] ; then |
189 |
- _describe -V 'eselect items' items |
190 |
+ _describe -V 'eselect news' items |
191 |
return 0 |
192 |
fi |
193 |
;; |
194 |
@@ -207,6 +214,70 @@ _eselect_complete_action_generic() { |
195 |
_nothing |
196 |
} |
197 |
|
198 |
+(( $+functions[_eselect_complete_php_action] )) || _eselect_complete_php_action() { |
199 |
+ if (( $NORMARG + $(_eselect_action_index) == $CURRENT )) ; then |
200 |
+ case "$(_eselect_get_action)" in |
201 |
+ ("list"|"set"|"show"|"update")) |
202 |
+ _values 'eselect php modules' $(eselect --colour=no --brief php list-modules) |
203 |
+ return 0 |
204 |
+ ;; |
205 |
+ esac |
206 |
+ elif (( $NORMARG + $(_eselect_action_index) + 1 == $CURRENT )) ; then |
207 |
+ case "$words[$CURRENT-2]" in |
208 |
+ "set") |
209 |
+ local targets=($(eselect --colour=no --brief php list "$words[$CURRENT-1]" 2> /dev/null)) |
210 |
+ if [ -n "$targets" ]; then |
211 |
+ _values 'eselect php modules' ${targets[@]} |
212 |
+ return 0 |
213 |
+ fi |
214 |
+ ;; |
215 |
+ esac |
216 |
+ fi |
217 |
+ |
218 |
+ _nothing |
219 |
+} |
220 |
+ |
221 |
+(( $+functions[_eselect_complete_rc_action] )) || _eselect_complete_rc_action() { |
222 |
+ if (( $NORMARG + $(_eselect_action_index) == $CURRENT )) ; then |
223 |
+ case "$(_eselect_get_action)" in |
224 |
+ ("list"|"show")) |
225 |
+ _values 'runlevels' $(command ls --color=never ${EPREFIX}/etc/runlevels) |
226 |
+ return 0 |
227 |
+ ;; |
228 |
+ ("add"|"delete"|"pause"|"reload"|"restart"|"start"|"stop")) |
229 |
+ _values 'scripts' $(rc-service -l) |
230 |
+ return 0 |
231 |
+ ;; |
232 |
+ esac |
233 |
+ elif (( $NORMARG + $(_eselect_action_index) + 1 == $CURRENT )) ; then |
234 |
+ case "$words[$CURRENT-2]" in |
235 |
+ ("add"|"delete")) |
236 |
+ _values 'runlevels' $(command ls --color=never ${EPREFIX}/etc/runlevels) |
237 |
+ return 0 |
238 |
+ ;; |
239 |
+ esac |
240 |
+ fi |
241 |
+ |
242 |
+ _nothing |
243 |
+} |
244 |
+ |
245 |
+ |
246 |
+(( $+functions[_eselect_complete_repository_action] )) || _eselect_complete_repository_action() { |
247 |
+ local -a opts |
248 |
+ |
249 |
+ case "$(_eselect_get_action)" in |
250 |
+ ("disable"|"remove")) |
251 |
+ opts=('-f:Force potentially dangerous removals') |
252 |
+ ;; |
253 |
+ "list") |
254 |
+ opts=('-i:Only list installed') |
255 |
+ ;; |
256 |
+ esac |
257 |
+ |
258 |
+ _describe -o 'options' opts |
259 |
+ _eselect_complete_action_generic repository |
260 |
+} |
261 |
+ |
262 |
eselect_comp() { |
263 |
integer NORMARG |