@@ -34,7 +34,7 @@ RUNNING_VM_COLOR = "#29cc00"
3434# Stopped VM color (default red)
3535STOPPED_VM_COLOR = "#ff0033"
3636
37- VERSION = "1.2 .0"
37+ VERSION = "1.3 .0"
3838
3939
4040def logSetup (level : str = "INFO" ):
@@ -90,7 +90,7 @@ def parseCLI():
9090 parser .add_argument ("--pull-new-image" , action = "store_true" )
9191 parser .add_argument (
9292 "--vm-action" ,
93- choices = ["start" , "stop" ],
93+ choices = ["start" , "stop" , "lima" ],
9494 help = "Action to perform on vm" ,
9595 )
9696 cliArgs = parser .parse_args ()
@@ -348,6 +348,28 @@ def imageOps(action: str, image: str, vm: str = "default"):
348348 displayNotification (title = "Task complete" , message = " " .join (command ))
349349
350350
351+ def limaCommand (vm : str ):
352+ """
353+ Run an arbitrary command with lima
354+
355+ :param str vm: Which vm to run the command in
356+ """
357+ env = prep_environment_for_lima (vm = vm )
358+ user_command = inputDialog (
359+ user_prompt = f"What lima command do you want to run in the { vm } VM?"
360+ )
361+
362+ if user_command != "" :
363+ lima_command = ["lima" ] + user_command .split ()
364+ displayNotification (
365+ title = f"Running '{ user_command } '" , message = " " .join (lima_command )
366+ )
367+ runCommand (command = lima_command , env = env )
368+ displayNotification (title = f"Ran '{ user_command } ' in { vm } " , message = "Completed" )
369+ else :
370+ displayAlert (title = "Error!" , message = "No nerdctl command specified" )
371+
372+
351373def vmOps (action : str , vm : str = "default" ):
352374 """
353375 Handle VM operations
@@ -361,13 +383,19 @@ def vmOps(action: str, vm: str = "default"):
361383
362384 env = prep_environment_for_lima (vm = vm )
363385
364- command = ["limactl" , action , vm ]
365- logging .warning ("command: %s" , command )
366- displayNotification (title = "Lima VM" , message = " " .join (command ))
367- output = runCommand (command = command , env = env )
368- logging .debug (output )
369- logging .warning ("%s complete" , action )
370- displayNotification (title = "Task completed" , message = " " .join (command ))
386+ if action == "lima" :
387+ limaCommand (vm = vm )
388+
389+ if action in ["start" , "stop" ]:
390+ command = ["limactl" , action , vm ]
391+ logging .info ("command: %s" , command )
392+
393+ displayNotification (title = "Lima VM" , message = " " .join (command ))
394+ output = runCommand (command = command , env = env )
395+ logging .debug (output )
396+
397+ logging .info ("%s complete" , action )
398+ displayNotification (title = "Task completed" , message = " " .join (command ))
371399
372400
373401def pullNewImage (vm : str = "default" ):
@@ -401,7 +429,7 @@ def xbar_icon(vms: dict = {}):
401429
402430 :param dict vms: Data about Lima VMs
403431 """
404- menuBarIcon = f"π β | color={ STOPPED_VM_COLOR } "
432+ menuBarIcon = f"πβ | color={ STOPPED_VM_COLOR } "
405433 for vm in vms :
406434 logging .debug ("vm: %s" , vm )
407435 if vms [vm ]["status" ] == "Running" :
@@ -432,7 +460,6 @@ def vmContainerSubMenu(vm: str = "default"):
432460
433461 :param str vm:
434462 """
435- # plugin_f = __file__.replace(" ", "\ ")
436463 plugin_f = __file__
437464 containers = listContainers (vm = vm )
438465
@@ -505,12 +532,15 @@ def vmMenu(vmData: dict = {}):
505532 if vmData [vm ]["status" ] != "Running" :
506533 print ("%s VM is stopped | color=%s" % (vm , STOPPED_VM_COLOR ))
507534 print (
508- f"""-- β Start { vm } VM | shell=\" { plugin_f } \" param1='--vm=default ' param2='--vm-action=start' terminal=false refresh=true"""
535+ f"""-- βΆοΈ Start { vm } VM | shell=\" { plugin_f } \" param1='--vm={ vm } ' param2='--vm-action=start' terminal=false refresh=true"""
509536 )
510537 else :
511538 print (f"{ vm } VM (running) | color={ RUNNING_VM_COLOR } " )
512539 print (
513- f"""-- β Stop { vm } VM | color={ STOPPED_VM_COLOR } bash="{ __file__ } " shell=\" { plugin_f } \" param1='--vm=default' param2='--vm-action=stop' terminal=false refresh=true"""
540+ f"""-- β Stop { vm } VM | color={ STOPPED_VM_COLOR } shell=\" { plugin_f } \" param1='--vm={ vm } ' param2='--vm-action=stop' terminal=false refresh=true"""
541+ )
542+ print (
543+ f"""-- π Run lima command | shell=\" { plugin_f } \" param1='--vm={ vm } ' param2='--vm-action=lima' terminal=false refresh=true"""
514544 )
515545 vmContainerSubMenu (vm = vm )
516546 vmImageSubMenu (vm = vm )
0 commit comments