Skip to content

Commit

Permalink
Merge pull request #25 from unixorn/add-opt-homebrew-bin-to-PATH
Browse files Browse the repository at this point in the history
Add /opt/homebrew/bin to $PATH when present and a directory
  • Loading branch information
unixorn authored Oct 11, 2021
2 parents 8c393fb + 4eec889 commit 46004dd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
12 changes: 12 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@
- Rewrite in Python for speed and maintainability.
- Now have submenus for container and image operations instead of just start/stop the VM
- We send notifications to the Notification Manager

## 1.2.0

- Add option to pull new image into one of your Lima VMs.

## 1.3.0

- Add option to run an arbitrary `lima` command in a VM.

## 1.3.1

- Add `/opt/homebrew/bin` to the plugin's `$PATH` when it exists and is a directory.
39 changes: 17 additions & 22 deletions lima-plugin
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RUNNING_VM_COLOR = "#29cc00"
# Stopped VM color (default red)
STOPPED_VM_COLOR = "#ff0033"

VERSION = "1.3.0"
VERSION = "1.3.1"


def logSetup(level: str = "INFO"):
Expand Down Expand Up @@ -185,12 +185,7 @@ def listContainers(vm: str = "default"):
:return dict:
"""
containers = {}
if vm != "default":
env = dict(os.environ, LIMA_INSTANCE=vm)
else:
env = dict(os.environ)
newpath = "%s:/usr/local/bin" % env["PATH"]
env["PATH"] = newpath
env = prep_environment_for_lima(vm=vm)

command = [
"lima",
Expand Down Expand Up @@ -223,13 +218,7 @@ def listImages(vm: str = "default"):
:return dict:
"""
images = {}
if vm != "default":
env = dict(os.environ, LIMA_INSTANCE=vm)
else:
env = dict(os.environ)

newpath = "%s:/usr/local/bin" % env["PATH"]
env["PATH"] = newpath
env = prep_environment_for_lima(vm=vm)

command = ["lima", "nerdctl", "images", "--format", "{{json .}}"]
raw = jsonCommand(command=command, env=env)
Expand Down Expand Up @@ -262,9 +251,7 @@ def listVMs():
"""
vmList = {}

env = dict(os.environ)
newpath = "%s:/usr/local/bin" % env["PATH"]
env["PATH"] = newpath
env = prep_environment_for_lima()

vmRaw = subprocess.run(
["limactl", "list", "--json"], env=env, stdout=subprocess.PIPE
Expand All @@ -283,17 +270,24 @@ def prep_environment_for_lima(vm: str = "default", env: dict = dict(os.environ))
"""
Set up an environment dictionary we can use to run a lima command.
Also adds /usr/local/bin to $PATH
Also adds /usr/local/bin, /opt/homebrew/bin and /opt/local/bin to $PATH
if they exist and are directories.
:param str vm: VM to work in
:param dict env: Environment variables to base returned environment on
:return dict: Environment dictionary, with /usr/local/bin added to $PATH
:return dict: Environment dictionary, with extra bindirs added to $PATH
"""
newpath = "%s:/usr/local/bin" % env["PATH"]
env["PATH"] = newpath
extrapaths = ["/usr/local/bin", "/opt/homebrew/bin", "/opt/local/bin"]
for p in extrapaths:
if os.path.isdir(p):
logging.info("Adding %s to $PATH", p)
newpath = "%s:%s" % (env["PATH"], p)
env["PATH"] = newpath
logging.info("New path: %s", env["PATH"])

if vm != "default":
logging.info("Setting LIMA_INSTANCE to %s", vm)
env["LIMA_INSTANCE"] = vm
return env

Expand Down Expand Up @@ -443,8 +437,9 @@ def aboutMenu():
"""
Print details about plugin
"""
env = prep_environment_for_lima()
limaVersion = subprocess.run(
["/usr/local/bin/limactl", "--version"], stdout=subprocess.PIPE
["limactl", "--version"], stdout=subprocess.PIPE, env=env
).stdout.decode("utf-8")

print("About…")
Expand Down

0 comments on commit 46004dd

Please sign in to comment.