6

I'm running a GUI Emacs compiled from the master git branch on MacOS El Capitan. I'm using the package exec-path-from-shell to set several environment variables I have configured in my ~/.zshenv file. However, none of them inherited in Emacs. GOPATH and SHELL are not set and PATH is not the PATH I have configured in my `~/.zshenv Currently I have the package configured with

(use-package exec-path-from-shell
  :ensure t
  :defer f
  :config
  (exec-path-from-shell-copy-env "GOPATH")
  (exec-path-from-shell-copy-env "SHELL")
  (exec-path-from-shell-copy-env "PATH")
  (when (memq window-system '(mac ns x))
    (exec-path-from-shell-initialize)))

After launching Emacs, M-x getenv for PATH returns /usr/bin:/usr/sbin/:/bin/:/sbin

However, executing shell-command via M-! with zsh -l -i -c 'echo $PATHreturns the PATH as I have set it in my ~/.zshenv file.

The ~/.zshenv looks like

export PATH="/Users/idclark/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin:/Applications/Postgres.app/Contents/Versions/9.4/bin:/Users/idclark/Library/Android/sdk/tools:/Users/idclark/Library/Android/sdk/platform-tools"
export JAVA_HOME="$(/usr/libexec/java_home)"
export MANPATH="/usr/local/man:$MANPATH"
export NVM_DIR="~/.nvm"
export GOPATH="/Users/idclark/go/bin"

Is this a problem with my zsh config or how how I'm initializing the exec-path-from-shell package?

1
  • 2
    Apple screwed up the zsh configuration files. /etc/zprofile resets the path, but is called after ~/.zshenv. IIRC this doesn't affect normal login shells. My solution was to rename /etc/zprofile to /etc/zshenv, iirc (I'm not at my Mac just now.)
    – Alan Third
    Commented Feb 3, 2017 at 14:34

1 Answer 1

6

You should remove :defer f, because you don't want exec-path-from-shell to be defer loaded and you are going to use function from it when Emacs starts. Try something like the following

(use-package exec-path-from-shell
  :ensure t
  :if (memq window-system '(mac ns x))
  :config
  (setq exec-path-from-shell-variables '("PATH" "GOPATH"))
  (exec-path-from-shell-initialize))

(I don't know why you need to set SHELL, Emacs sets it automatically and correctly for me, like HOME)

If you are not sure if you are using use-package correctly, expand it via something like emacs-lisp-macroexpand and check the result.

1
  • I also had to (setenv "SHELL" "/usr/local/bin/zsh"), but now all of my env variables are inherited in Emacs correctly.
    – idclark
    Commented Feb 4, 2017 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.