1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
# bash completion for mic
#
# Copyright (c) 2013 Intel, Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; version 2 of the License
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
__miccomp_1 ()
{
local c IFS=$' \t\n'
for c in $1; do
c="$c$2"
case $c in
--*=*|*.) ;;
*) c="$c " ;;
esac
printf '%s\n' "$c"
done
}
__miccomp ()
{
local cur_="${3-$cur}"
case "$cur_" in
--*=)
COMPREPLY=()
;;
*)
local IFS=$'\n'
COMPREPLY=($(compgen -P "${2-}" \
-W "$(__miccomp_1 "${1-}" "${4-}")" \
-- "$cur_"))
;;
esac
}
__mic_find_on_cmdline ()
{
local word subcommand c=1
while [ $c -lt $cword ]; do
word="${words[c]}"
for subcommand in $1; do
if [ "$subcommand" = "$word" ]; then
echo "$subcommand"
return
fi
done
let c++
done
}
__mic_expand_alias ()
{
case ${subcommand} in
cr*) subcommand="create" ;;
ch*) subcommand="chroot" ;;
c*v*) subcommand="convert" ;;
esac
}
__mic_complete_opt()
{
fs_exts="
--include-src
"
loop_exts="
--shrink
--compress-image=
--compress-disk-image=
"
raw_exts="
--fstab-entry=
--generate-bmap
--compress-image=
--compress-disk-image=
"
keyword="$(__mic_find_on_cmdline "fs loop raw")"
eval extensions="$"{${keyword}_exts}
__miccomp "${options} ${extensions}"
}
__mic_complete_val()
{
_values="
"
arch_values="
ia64
i686
i586
x86_64
armv5l
armv6l
armv7l
armv7hl
armv7thl
armv7nhl
armv5tel
armv5tejl
armv7tnhl
riscv64
"
pkgmgr_values="
yum
zypper
"
release_values="
latest
"
runtime_values="
bootstrap
"
record_pkgs_values="
vcs
name
content
license
"
fstab_entry_values="
name
uuid
"
install_pkgs_values="
source
debuginfo
debugsoure
"
compress_image_values="
gz
bz2
lzo
"
compress_disk_image_values="
gz
bz2
lzo
"
declare -F _split_longopt &>/dev/null && _split_longopt
prev_=${prev##--}
eval values="$"{${prev_//-/_}_values}
__miccomp "${values}"
}
__mic_complete_arg()
{
local before c=$((cword-1))
while [[ $c -gt 0 ]]; do
before=${words[c]} && [[ "$before" != -* ]] && break;
let c--
done
case ${subcommand},${before} in
cr*,cr*)
__miccomp "${arguments}"
return 0
;;
c*v*,fs|loop|raw|livecd|liveusb)
__miccomp "${arguments}"
return 0
;;
help,help)
__miccomp "${arguments}"
return 0
;;
esac
return 1
}
__mic ()
{
if [ -z "$subcommand" ]; then
case "$cur" in
-*)
__miccomp "${options}"
;;
*)
__miccomp "${subcommands}"
;;
esac
else
case "$cur" in
--*=*)
__mic_complete_val
;;
-*)
__mic_complete_opt
;;
*)
__mic_complete_arg || COMPREPLY=()
;;
esac
fi
}
__mic_main ()
{
subcommands="
help
create
chroot
convert
"
alias="
cr
ch
cv
"
_opts="
--version
"
common_opts="
--help
--debug
--verbose
"
create_opts="
--arch=
--tmpfs
--config=
--pkgmgr=
--outdir=
--pack-to=
--logfile=
--runtime=
--release=
--cachedir=
--copy-kernel
--check-pkgs=
--record-pkgs=
--install-pkgs=
--local-pkgs-path=
"
convert_opts="
--shell
"
chroot_opts="
--saveto=
"
help_opts="
"
_args="
"
create_args="
auto
fs
livecd
liveusb
loop
raw
"
convert_args="
fs
livecd
liveusb
loop
raw
"
chroot_args="
"
help_args="
create
convert
chroot
"
local cur prev words cword
if declare -F _get_comp_words_by_ref &>/dev/null ; then
_get_comp_words_by_ref cur prev words cword
else
cur=$2 prev=$3 words=("${COMP_WORDS[@]}") cword=$COMP_CWORD
fi
local subcommand
subcommand="$(__mic_find_on_cmdline "$subcommands $alias")"
__mic_expand_alias
local options arguments
eval options="$"{${subcommand}_opts}"\ $"{common_opts}
eval arguments="$"{${subcommand}_args}
__mic && return
} &&
complete -F __mic_main -o bashdefault -o default -o nospace mic
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh
|