purcell / exec-path-from-shell

Make Emacs use the $PATH set up by the user's shell
Other
1.43k stars 82 forks source link

Need for running exec-path-from-shell-initialize twice to get the PATH variable correctly #85

Closed shackra closed 5 years ago

shackra commented 5 years ago

I use Arch Linux, with the systemd unit for users provided by the Arch maintainer of the Emacs package

exec-path-from-shell-initialize is ran once by the after-init-hook, providing the following value for the PATH copy in Emacs:

/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/jorge/go/bin:/home/jorge/opt/android/tools/:/home/jorge/opt/android/platform-tools/:/home/jorge/.local/bin:/home/jorge/.cargo/bin:/home/jorge/go/bin

The problem is that some paths are missing here. The current value of PATH is the following (from ~/.zshenv):

# this is the exact order in the file
export GOPATH=$HOME/go

export GOBIN=$GOPATH/bin

export PATH=$PATH:$GOBIN

export PATH=$PATH:$HOME/opt/android/tools/:$HOME/opt/android/platform-tools/

export PATH=$PATH:$HOME/opt/prey-node-client/bin

export PATH=$PATH:$HOME/.local/bin

export PATH=$PATH:$HOME/.cargo/bin

export PATH=$HOME/.node_modules/bin:$PATH

export PATH=$PATH:$HOME/.gem/ruby/2.4.0/bin:$(ruby -e 'print Gem.user_dir')/bin

I need to open a frame and run M-x exec-path-from-shell-initialize to get the PATH variable right:

/home/jorge/.node_modules/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/jorge/go/bin:/home/jorge/opt/android/tools/:/home/jorge/opt/android/platform-tools/:/home/jorge/.local/bin:/home/jorge/.cargo/bin:/home/jorge/go/bin:/home/jorge/go/bin:/home/jorge/opt/android/tools/:/home/jorge/opt/android/platform-tools/:/home/jorge/opt/prey-node-client/bin:/home/jorge/.local/bin:/home/jorge/.cargo/bin:/home/jorge/.gem/ruby/2.4.0/bin:/home/jorge/.gem/ruby/2.5.0/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl

Honestly I don't know where the issue is...

purcell commented 5 years ago

Maybe when Emacs runs, its value for $SHELL isn't zsh, so it's not actually running a shell which looks at ~/.zshenv?

You can enable exec-path-from-shell-debug for more info.

shackra commented 5 years ago

I noticed that the variable for debugging was always nil, so I did some changes in my configuration and was a logic error from my part, the following changes in my configuration made everything work as intended:

-  (when (memq window-system '(mac ns x))
+  (unless (memq system-type '(ms-dos windos-nt cygwin))
+    (require 'exec-path-from-shell)
     (exec-path-from-shell-initialize))