I am trying to get shell-command
and async-shell-command
to integrate seamlessly with a couple of programs in my .bashrc
file, specifically direnv in this example.
I found that if I customized shell-command-switch
, I could get shell processes to load my profile as if it were a regular interactive login shell:
(setq shell-command-switch (purecopy "-ic")) (setq explicit-bash-args '("-ic" "export EMACS=; stty echo; bash"))
I am also using exec-path-from-shell.
Say I have a ~/.bashrc
file with:
... eval "$(direnv hook $0)" echo "foo"
Inside ~/code/foo
I have a .envrc
file with:
export PATH=$PWD/bin:$PATH echo "bar"
If I run M-x shell
with default-directory
set to ~/code/foo
, a bash shell will correctly load my profile and run the direnv hook to add that to my path:
direnv: loading .envrc bar direnv: export ~PATH ~/code/foo $ echo $PATH /Users/username/code/foo/bin:/usr/local/bin:... # rest of $PATH
However if default-directory
is still ~/code/foo
and I run M-! echo $PATH
, it correctly loads my .bashrc but doesn't execute the direnv hook of the current directory:
foo /usr/local/bin:... # rest of $PATH without ./bin
I get the same result if I run M-! cd ~/code/foo && echo $PATH
.
Is there a way I can advise or hook into shell-command
or start-process
to make it behave as if it were being sent from an interactive shell buffer?