purcell / envrc

Emacs support for direnv which operates buffer-locally
378 stars 35 forks source link

Default environment when launch outside shell #18

Closed failable closed 3 years ago

failable commented 3 years ago

Note really an issue.

I like the default Emacs environment way as stated in the Design Notes.

I use asdf-direnv and envrc for managing my environment. I have a default .envrc in my $HOME to manage the global tool versions. When I start Emacs in non terminal way (double click the App in macOS), that global .envrc is not being taken care by envrc (of course). I'd like to achieve that when I start Emacs outside a shell, it takes care of that default global environment in $HOME. Maybe I can solve this by using exec-path-from-shell, is there an envrc way to solve this (=select a default environment for Emacs when starting in GUI) ? Thanks!

I also tried these two ways:

  1. Run /usr/local/opt/emacs-mac/Emacs.app/Contents/MacOS/Emacs to start the GUI Emacs in my terminal, this way works the same as running a non GUI version of Emacs. envrc works perfectly but I have to keep a foreground shell command.
  2. Run /usr/local/opt/emacs-mac/Emacs.app/Contents/MacOS/Emacs & in my terminal, this way has an issue that the background process is run in a subshell by bash and my .profile is sourced again. Since my asdf and direnv setup is put in .bashrc (which is not sourced when the background process is launched), lots of PATH will be inserted before the PATH of parent shell and the default Emacs environment will get duplicate and unexpected PATH.
purcell commented 3 years ago

I use exec-path-for-shell to set up the global environment. I would guess it would work for you based on the info above. I think modifying the global environment is out of scope for envrc.el.

failable commented 3 years ago

That makes sense. Thank you!