Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting environmental variables #194

Open
shen-tian opened this issue Feb 7, 2018 · 4 comments
Open

Setting environmental variables #194

shen-tian opened this issue Feb 7, 2018 · 4 comments

Comments

@shen-tian
Copy link
Contributor

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.

@simeg
Copy link
Collaborator

simeg commented Feb 7, 2018

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?

@shen-tian
Copy link
Contributor Author

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.

@simeg
Copy link
Collaborator

simeg commented Feb 7, 2018

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

@apjanke
Copy link
Contributor

apjanke commented May 7, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants