Skip to content

Commit 46004dd

Browse files
authored
Merge pull request #25 from unixorn/add-opt-homebrew-bin-to-PATH
Add /opt/homebrew/bin to $PATH when present and a directory
2 parents 8c393fb + 4eec889 commit 46004dd

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

Diff for: Changelog.md

+12
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@
99
- Rewrite in Python for speed and maintainability.
1010
- Now have submenus for container and image operations instead of just start/stop the VM
1111
- We send notifications to the Notification Manager
12+
13+
## 1.2.0
14+
15+
- Add option to pull new image into one of your Lima VMs.
16+
17+
## 1.3.0
18+
19+
- Add option to run an arbitrary `lima` command in a VM.
20+
21+
## 1.3.1
22+
23+
- Add `/opt/homebrew/bin` to the plugin's `$PATH` when it exists and is a directory.

Diff for: lima-plugin

+17-22
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ RUNNING_VM_COLOR = "#29cc00"
3434
# Stopped VM color (default red)
3535
STOPPED_VM_COLOR = "#ff0033"
3636

37-
VERSION = "1.3.0"
37+
VERSION = "1.3.1"
3838

3939

4040
def logSetup(level: str = "INFO"):
@@ -185,12 +185,7 @@ def listContainers(vm: str = "default"):
185185
:return dict:
186186
"""
187187
containers = {}
188-
if vm != "default":
189-
env = dict(os.environ, LIMA_INSTANCE=vm)
190-
else:
191-
env = dict(os.environ)
192-
newpath = "%s:/usr/local/bin" % env["PATH"]
193-
env["PATH"] = newpath
188+
env = prep_environment_for_lima(vm=vm)
194189

195190
command = [
196191
"lima",
@@ -223,13 +218,7 @@ def listImages(vm: str = "default"):
223218
:return dict:
224219
"""
225220
images = {}
226-
if vm != "default":
227-
env = dict(os.environ, LIMA_INSTANCE=vm)
228-
else:
229-
env = dict(os.environ)
230-
231-
newpath = "%s:/usr/local/bin" % env["PATH"]
232-
env["PATH"] = newpath
221+
env = prep_environment_for_lima(vm=vm)
233222

234223
command = ["lima", "nerdctl", "images", "--format", "{{json .}}"]
235224
raw = jsonCommand(command=command, env=env)
@@ -262,9 +251,7 @@ def listVMs():
262251
"""
263252
vmList = {}
264253

265-
env = dict(os.environ)
266-
newpath = "%s:/usr/local/bin" % env["PATH"]
267-
env["PATH"] = newpath
254+
env = prep_environment_for_lima()
268255

269256
vmRaw = subprocess.run(
270257
["limactl", "list", "--json"], env=env, stdout=subprocess.PIPE
@@ -283,17 +270,24 @@ def prep_environment_for_lima(vm: str = "default", env: dict = dict(os.environ))
283270
"""
284271
Set up an environment dictionary we can use to run a lima command.
285272
286-
Also adds /usr/local/bin to $PATH
273+
Also adds /usr/local/bin, /opt/homebrew/bin and /opt/local/bin to $PATH
274+
if they exist and are directories.
287275
288276
:param str vm: VM to work in
289277
:param dict env: Environment variables to base returned environment on
290278
291-
:return dict: Environment dictionary, with /usr/local/bin added to $PATH
279+
:return dict: Environment dictionary, with extra bindirs added to $PATH
292280
"""
293-
newpath = "%s:/usr/local/bin" % env["PATH"]
294-
env["PATH"] = newpath
281+
extrapaths = ["/usr/local/bin", "/opt/homebrew/bin", "/opt/local/bin"]
282+
for p in extrapaths:
283+
if os.path.isdir(p):
284+
logging.info("Adding %s to $PATH", p)
285+
newpath = "%s:%s" % (env["PATH"], p)
286+
env["PATH"] = newpath
287+
logging.info("New path: %s", env["PATH"])
295288

296289
if vm != "default":
290+
logging.info("Setting LIMA_INSTANCE to %s", vm)
297291
env["LIMA_INSTANCE"] = vm
298292
return env
299293

@@ -443,8 +437,9 @@ def aboutMenu():
443437
"""
444438
Print details about plugin
445439
"""
440+
env = prep_environment_for_lima()
446441
limaVersion = subprocess.run(
447-
["/usr/local/bin/limactl", "--version"], stdout=subprocess.PIPE
442+
["limactl", "--version"], stdout=subprocess.PIPE, env=env
448443
).stdout.decode("utf-8")
449444

450445
print("About…")

0 commit comments

Comments
 (0)