matryer / xbar

Put the output from any script or program into your macOS Menu Bar (the BitBar reboot)
https://xbarapp.com
MIT License
17.55k stars 643 forks source link

Anyway to update the default PATH? #793

Open andymckay opened 2 years ago

andymckay commented 2 years ago

Locally I've got 4 (there's probably more) ways of running xbar:

You might get a different path from doing those. I wrote a quick plugin like this to discover all the paths that you get.

#!/bin/bash
echo Environment variables
echo ---
for e in `env`; do
  echo "$e"
done

And I can see that in some cases I'll get /usr/bin/local in there, depending upon how its run, sometimes I won't.

This is a similar issue to:

Where people are finding that the PATH is different.

Would it make sense to try injecting /usr/bin/local into the environment? Or is there another way to avoid this problem? Currently I'm asking all the users of xbar to run it from the terminal.

matryer commented 2 years ago

Thanks @andymckay - this is a great issue.

@leaanthony This seems like something we can address, what do you think it best practice here?

leaanthony commented 2 years ago

Have paths in config and add them to the env on startup.

andymckay commented 2 years ago

In the end I found it pretty easy to drop in a bash file, that adds in /usr/local/bin to the $PATH and then that calls the JS file. That's worked so far for every way I've been able to launch xbar and for all the users of my plugins.

alexrussell commented 1 year ago

I've just posted a technique at https://github.com/matryer/xbar/issues/856#issuecomment-1445501343 that may also be useful to mitigate this issue from the plugin side without needing a plugin file to first run some shell commands and then call your actual executable.