purcell / exec-path-from-shell

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

Add `exec-path-from-shell-rc-file-path` to source rc file correctly #79

Closed kenoss closed 6 years ago

kenoss commented 6 years ago

Hi.

Problem

I use Emacs.app on OSX. The application is launched without my normal shell environment. So I have to use correctly this package; launch shell in emacs and get variable.

I have separated bash/zsh configuration files and one of them ~/.zsh.d/foobar/path.sh is about exporting environment variable PATH. So I thought that correct way to tell exec-path-from-shell to use this file is the below setting:

(require 'exec-path-from-shell)
(setq exec-path-from-shell-shell-name "bash"
      exec-path-from-shell-arguments '("--rcfile" "~/.zsh.d/hoge/path.sh"))
(exec-path-from-shell-initialize)

Althogh it does not work. AFAIK, reading man bash and examined as below, --rcfile option is not available in non-interactive mode, and there's no way to source before executing command (of -c option).

$ echo $SHELL
/usr/local/bin/zsh
$ echo 'echo hoge' > rc.sh
$ bash --rcfile rc.sh -c 'printf foobar'
foobar% 
$ bash --login --rcfile rc.sh -c 'printf foobar'
foobar% 
# Here, % is zsh's output for non correctly terminated lines.

Solution

Use explicit source before target command.

$ bash -c "source $PWD/rc.sh; printf foobar"
hoge
foobar% 

This is archived by this PR. I added new variable exec-path-from-shell-rc-file-path for the sourced file path string, because the existing variable exec-path-from-shell-arguments is not sufficient for it.

I tested with below setting and it works correctly:

(setq exec-path-from-shell-shell-name "bash"
      exec-path-from-shell-arguments '()
      exec-path-from-shell-rc-file-path "~/.zsh.d/hoge/path.sh")

What do you think?

purcell commented 6 years ago

Thanks for taking the time to submit this, but I'm going to decline it: firstly, the purpose of exec-path-from-shell is to duplicate the environment variables you would see if you ran a regular terminal, and so that places this addition out of scope.

But more pertinently, you could likely achieve this simply by setting exec-path-from-shell-shell-name to the path of a script which runs bash however you like.

kenoss commented 6 years ago

It's OK. I see your decision.