@@ -150,6 +150,18 @@ function printMenu() {
150
150
if [[ $vmstatus == ' Running' ]]; then
151
151
echo " $name VM is running | color=$RUNNING_VM_COLOR "
152
152
echo " --⛔ Stop $name VM | bash=$XBAR_PLUGIN param1=stop param2=$name terminal=false refresh=true"
153
+
154
+ echo " -- Containers"
155
+ for container in $( vmContainers)
156
+ do
157
+ echo " ---- $container "
158
+ # echo "------ start | bash=$XBAR_PLUGIN param1=startContainer param2=$name param3=$container terminal=false refresh=true"
159
+ echo " ------ stop | bash=$XBAR_PLUGIN param1=stopContainer param2=$name param3=$container terminal=false refresh=true"
160
+ echo " ------ kill | bash=$XBAR_PLUGIN param1=killContainer param2=$name param3=$container terminal=false refresh=true"
161
+ echo " ------ pause | bash=$XBAR_PLUGIN param1=pauseContainer param2=$name param3=$container terminal=false refresh=true"
162
+ echo " ------ unpause | bash=$XBAR_PLUGIN param1=unpauseContainer param2=$name param3=$container terminal=false refresh=true"
163
+ done
164
+
153
165
echo " -- Images"
154
166
for image in $( vmImages)
155
167
do
@@ -168,6 +180,22 @@ function printMenu() {
168
180
limactl --version
169
181
}
170
182
183
+ function vmContainers() {
184
+ # default VM doesn't need to be specified
185
+ if [[ " $VM " != ' default' ]]; then
186
+ export LIMA_INSTANCE=" $VM "
187
+ fi
188
+ # shellcheck disable=SC2001,SC2046,SC2005
189
+ containerList=" [$( echo $( lima nerdctl ps --format ' {{json .}},' ) | sed ' s/,$//' ) ]"
190
+ # Can have spaces in our data, deal by using base64 (ugly)
191
+ for row in $( echo " ${containerList} " | jq -r ' .[] | @base64' ) ; do
192
+ _jq () {
193
+ echo " ${row} " | base64 --decode | jq -r " ${1} "
194
+ }
195
+ _jq ' .Names'
196
+ done
197
+ }
198
+
171
199
function vmImages() {
172
200
# default VM doesn't need to be specified
173
201
if [[ " $VM " != ' default' ]]; then
@@ -220,6 +248,78 @@ function rmImage() {
220
248
fi
221
249
}
222
250
251
+ function stopContainer() {
252
+ # arg1 = container
253
+ # arg2 = VM
254
+ local containerName
255
+ local VM
256
+ containerName=" $1 "
257
+ VM=" $2 "
258
+ if [[ " $VM " != ' default' ]]; then
259
+ export LIMA_INSTANCE=" $VM "
260
+ fi
261
+ displayNotification lima " Stopping ${containerName} on ${VM} ..."
262
+ if lima nerdctl container stop " ${containerName} " ; then
263
+ displayNotification Lima " Stopped ${containerName} "
264
+ else
265
+ displayAlert Lima " Failed to stop ${containerName} on ${VM} "
266
+ fi
267
+ }
268
+
269
+ function killContainer() {
270
+ # arg1 = container
271
+ # arg2 = VM
272
+ local containerName
273
+ local VM
274
+ containerName=" $1 "
275
+ VM=" $2 "
276
+ if [[ " $VM " != ' default' ]]; then
277
+ export LIMA_INSTANCE=" $VM "
278
+ fi
279
+ displayNotification lima " Killing ${containerName} on ${VM} ..."
280
+ if lima nerdctl container kill " ${containerName} " ; then
281
+ displayNotification Lima " Killed ${containerName} "
282
+ else
283
+ displayAlert Lima " Failed to kill ${containerName} on ${VM} "
284
+ fi
285
+ }
286
+
287
+ function pauseContainer() {
288
+ # arg1 = container
289
+ # arg2 = VM
290
+ local containerName
291
+ local VM
292
+ containerName=" $1 "
293
+ VM=" $2 "
294
+ if [[ " $VM " != ' default' ]]; then
295
+ export LIMA_INSTANCE=" $VM "
296
+ fi
297
+ displayNotification lima " Pausing ${containerName} on ${VM} ..."
298
+ if lima nerdctl container pause " ${containerName} " ; then
299
+ displayNotification Lima " Paused ${containerName} "
300
+ else
301
+ displayAlert Lima " Failed to pause ${containerName} on ${VM} "
302
+ fi
303
+ }
304
+
305
+ function unpauseContainer() {
306
+ # arg1 = container
307
+ # arg2 = VM
308
+ local containerName
309
+ local VM
310
+ containerName=" $1 "
311
+ VM=" $2 "
312
+ if [[ " $VM " != ' default' ]]; then
313
+ export LIMA_INSTANCE=" $VM "
314
+ fi
315
+ displayNotification lima " Unpausing ${containerName} on ${VM} ..."
316
+ if lima nerdctl container unpause " ${containerName} " ; then
317
+ displayNotification Lima " Unpaused ${containerName} "
318
+ else
319
+ displayAlert Lima " Failed to unpause ${containerName} on ${VM} "
320
+ fi
321
+ }
322
+
223
323
function processMenuCommand() {
224
324
case " $1 " in
225
325
images)
@@ -228,6 +328,18 @@ function processMenuCommand() {
228
328
pull)
229
329
pullImage " $2 " " $3 " # pull imagename vmname
230
330
;;
331
+ stopContainer)
332
+ stopContainer " $3 " " $2 " # stopContainer containerName VMname
333
+ ;;
334
+ killContainer)
335
+ killContainer " $3 " " $2 " # killContainer containerName VMname
336
+ ;;
337
+ pauseContainer)
338
+ pauseContainer " $3 " " $2 " # pauseContainer containerName VMname
339
+ ;;
340
+ unpauseContainer)
341
+ unpauseContainer " $3 " " $2 " # unpauseContainer containerName VMname
342
+ ;;
231
343
rmImage)
232
344
rmImage " $2 " " $3 " # pull imagename vmname
233
345
;;
0 commit comments