@@ -96,6 +96,31 @@ def parseCLI():
96
96
return cliArgs
97
97
98
98
99
+ # fun with osascript
100
+
101
+
102
+ def displayAlert (title : str , message : str ):
103
+ """
104
+ Display an alert using osascript. Blocking.
105
+
106
+ :param str title:
107
+ :param str message:
108
+ """
109
+ alertCommand = f'display alert "{ title } " message "{ message } "'
110
+ runCommand (command = ["osascript" , "-e" , alertCommand ])
111
+
112
+
113
+ def displayNotification (title : str , message : str ):
114
+ """
115
+ Publish a notification to the notification manager.
116
+
117
+ :param str title:
118
+ :param str message:
119
+ """
120
+ alertCommand = f'display notification "{ message } " with title "{ title } " '
121
+ runCommand (command = ["osascript" , "-e" , alertCommand ])
122
+
123
+
99
124
def runCommand (command : list , env = dict (os .environ )):
100
125
"""
101
126
Run a command and decode the json output
@@ -237,6 +262,9 @@ def prep_environment_for_lima(vm: str = "default", env: dict = dict(os.environ))
237
262
Also adds /usr/local/bin to $PATH
238
263
239
264
:param str vm: VM to work in
265
+ :param dict env: Environment variables to base returned environment on
266
+
267
+ :return dict: Environment dictionary, with /usr/local/bin added to $PATH
240
268
"""
241
269
newpath = "%s:/usr/local/bin" % env ["PATH" ]
242
270
env ["PATH" ] = newpath
@@ -249,6 +277,10 @@ def prep_environment_for_lima(vm: str = "default", env: dict = dict(os.environ))
249
277
def containerOps (action : str , container : str , vm : str = "default" ):
250
278
"""
251
279
Handle container operations
280
+
281
+ :param str action: What container op to do
282
+ :param str container: What container to do the action on
283
+ :param str vm: Which VM is the container in?
252
284
"""
253
285
logging .warning ("containerOps" )
254
286
logging .debug ("action: %s" % action )
@@ -259,15 +291,21 @@ def containerOps(action: str, container: str, vm: str = "default"):
259
291
260
292
command = ["lima" , "nerdctl" , "container" , action , container ]
261
293
logging .warning ("containerops command: %s" , command )
294
+ displayNotification (title = "Lima VM" , message = " " .join (command ))
262
295
263
296
output = runCommand (command = command , env = env )
264
297
logging .warning (output )
265
298
logging .warning ("%s complete" , action )
299
+ displayNotification (title = "Task complete" , message = " " .join (command ))
266
300
267
301
268
302
def imageOps (action : str , image : str , vm : str = "default" ):
269
303
"""
270
304
Handle VM operations
305
+
306
+ :param str action: What image op to do
307
+ :param str image: What image to do the action on
308
+ :param str vm: Which VM is the image in?
271
309
"""
272
310
logging .critical ("imageOps" )
273
311
logging .info ("action: %s" % action )
@@ -279,14 +317,19 @@ def imageOps(action: str, image: str, vm: str = "default"):
279
317
command = ["lima" , "nerdctl" , "image" , action , image ]
280
318
logging .warning ("command: %s" , command )
281
319
logging .warning ("PATH: %s" , env ["PATH" ])
320
+ displayNotification (title = "Lima VM" , message = " " .join (command ))
282
321
output = runCommand (command = command , env = env )
283
322
logging .debug (output )
284
323
logging .warning ("%s complete" , action )
324
+ displayNotification (title = "Task complete" , message = " " .join (command ))
285
325
286
326
287
327
def vmOps (action : str , vm : str = "default" ):
288
328
"""
289
329
Handle VM operations
330
+
331
+ :param str action: What action to run - should be start or stop
332
+ :param str vm: Name of VM to act on
290
333
"""
291
334
logging .critical ("vmOps" )
292
335
logging .debug ("action: %s" % action )
@@ -296,17 +339,23 @@ def vmOps(action: str, vm: str = "default"):
296
339
297
340
command = ["limactl" , action , vm ]
298
341
logging .warning ("command: %s" , command )
342
+ displayNotification (title = "Lima VM" , message = " " .join (command ))
299
343
output = runCommand (command = command , env = env )
300
344
logging .debug (output )
301
345
logging .warning ("%s complete" , action )
346
+ displayNotification (title = "Task completed" , message = " " .join (command ))
302
347
303
348
304
349
# Actual Xbar-compatible output
305
350
306
351
307
352
def xbar_icon (vms : dict = {}):
308
353
"""
309
- Determine icon to display in menubar
354
+ Determine icon to display in menubar.
355
+
356
+ We display a running menubar icon if at least one VM is running.
357
+
358
+ :param dict vms: Data about Lima VMs
310
359
"""
311
360
menuBarIcon = f"🐋 ⛔ | color={ STOPPED_VM_COLOR } "
312
361
for vm in vms :
0 commit comments