mac-setup icon indicating copy to clipboard operation
mac-setup copied to clipboard

Setting environmental variables

Open shen-tian opened this issue 7 years ago • 4 comments

I'm Submitting a ...

[ ] Bug report
[x] Tool/language/etc documentation request

Tool/Language/etc

Setting environmental variables (especially ones that gets picked up in non-terminal launched apps) seems to be a bit of a challenge?

Best I can find seem to be the top answer of this SO post using environment.plist.

Other Information

Happy to write this up, just want to check there isn't an obviously better way to do this.

shen-tian avatar Feb 07 '18 09:02 shen-tian

I'm not sure what you mean. Can't you just export them in your bash/zshrc/etc config?

Like this: export GOPATH="$HOME/repos/go"

Could you give an example of such a environment variable?

simeg avatar Feb 07 '18 09:02 simeg

As far as I can tell, the trick is to get access to those variables when launching apps from Spotlight or the Dock, as .bash_profiles etc. are ran when you Terminal.app or iTerm.app etc.

Example:

  • I type export FOO="foo" in iTerm
  • Launch Emacs from the dock
  • Launch eshell, and echo $FOO: this gets nothing.

The SO post I linked to seems to fix this.

shen-tian avatar Feb 07 '18 10:02 shen-tian

Sounds good to me if you want to write it 👍 Be sure to read our contribution docs.

simeg avatar Feb 07 '18 17:02 simeg

I think @shen-tian is right: native Mac apps launched from the Dock or by double-clicking their icons do not get launched via a login or interactive shell, so none of the user shell startup scripts are run in that context. (In fact, I think it skips all shell startup files, so there's nothing you can do at the shell level to set environment variables.) Hackery like that linked SO posts is the way you have to do it.

apjanke avatar May 07 '19 21:05 apjanke