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

Not working on MacOS #88

Closed AlexDrBanana closed 4 years ago

AlexDrBanana commented 5 years ago

Hi, I used your .emacs.d, but the exec-path-from-shell part is not working as expected, when I start from GUI, the path doesn't inherit from login shell

In emacs: M-! echo $PATH outputs usr/bin:/bin:/usr/sbin:/sbin:/Applications/Emacs.app/Contents/MacOS/bin-x86_64-10_10:/Applications/Emacs.app/Contents/MacOS/libexec-x86_64-10_10 M-! bash -l -c 'echo $PATH' outputs /Library/Developer/Toolchains/swift-latest/usr/bin:~/Sources/My Source Code/Scripts:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS M-x exec-path-from-shell M-! echo $PATH outputs usr/bin:/bin:/usr/sbin:/sbin:/Applications/Emacs.app/Contents/MacOS/bin-x86_64-10_10:/Applications/Emacs.app/Contents/MacOS/libexec-x86_64-10_10

basically it didn't work

I don't know what's wrong, I've ruled out .bash_profile and init-local.el. I also tried reinstalling, didn't work either.

purcell commented 5 years ago

Thanks, but this isn't a complete bug report so I can't offer much help without more info. Please let me know what your configuration is: elisp config, shell type, platform, which files you've put your shell settings in. (Also, you mention init-local.el -- are you using my .emacs.d perhaps?)

AlexDrBanana commented 5 years ago

Yes, as mentioned, I did use your .emacs.d. In fact, I deleted my own init-local.el, but the problem still exists. Other than that, my config is supposed to be exactly the same with your emacs.d. my shell is /bin/bash, platform macOS mojave, I used .bash_profile to config my shell, but I cleared it and only left a line export PATH=/usr/local/bin, but it seems emacs didn't read it at all. Right now I can use emacs & && disown -ha to start from terminal to make the PATH right, but it's still annoying that I can't start directly from GUI.

purcell commented 5 years ago

In my emacs.d I set exec-path-from-shell-arguments to nil, which means that the shell is not invoked in interactive mode. This is the recommended (strict) approach noted in the exec-path-from-shell README, but often people's shell startup files aren't set correctly. You'd need to put your shell settings in a file that is executed when you run bash, rather than bash -i. It might be that your ~/.bash_profile is sourced by your ~/.bashrc, and that latter file wouldn't be loaded.

purcell commented 5 years ago

(Sorry I missed your note about using my emacs.d.)

AlexDrBanana commented 5 years ago

But I don't have a ~/.bashrc, and I don't have any file sourcing my ~/.bash_profile. In fact, the big problem is not my shell settings anymore. /usr/local/bin is in my /etc/paths which is the default paths set in /etc/profile along with /usr/sbin, /sbin and stuff, but as you can see in GUI, only /usr/local/bin is missing, so what happened here? Does emacs specifically unset it or it uses different default paths?

purcell commented 5 years ago

Unsure how things are set up on your system, but Emacs will have its own environment which the invocation of bash will inherit: that's why I make this recommendation in the exec-path-from-shell README.

You might consider setting exec-path-from-shell-debug to t, and then you'll be able to see exactly what command is being run by exec-path-from-shell, which might help debug things. Alternatively, you can edit init-exec-path to remove my override of exec-path-from-shell-arguments to see if the defaults work for you.