1

In native emacs on windows, how can I specify environment variables for launching my shell inside emacs without modifying emacs' environment? In my specific case I'd like to set HOME to a cygwin-specific value for zsh without modifying where emacs thinks it's config file lives.

I've tried some things like changing my shell to env -u HOME ...\zsh.exe, but that seems to break (shell-command) (it appeared to involve argument order).

If this command existed, it would probably do what I want:

(setq explicit-zsh-environment '("HOME" nil))

I've read a bunch of related questions like (How can I run Cygwin Bash Shell from within Emacs?), but the unusual part for me is that all my config files are cygwin-ln-ed or windows-mklink-ed into a git repo and cygwin and windows take very different and incompatible approaches to symlinks.

Community
  • 1
  • 1
kleinpa
  • 107
  • 1
  • 1
  • 5

2 Answers2

2

Is this about running zsh as a shell inside Emacs (i.e. not about starting Emacs from a zsh shell), and having the environment that the inferior zsh process sees be different to the environment that Emacs has?

If so, you can bind the C-hv process-environment variable when you start a process. e.g.:

(let ((process-environment '("HOME=/tmp")))
  (call-interactively 'shell))
$ echo $HOME
/tmp
phils
  • 71,335
  • 11
  • 153
  • 198
  • This is good, but is there a way to automatically apply it to `shell-command` and M-x `shell`? – kleinpa Sep 19 '14 at 02:35
  • Is it just shell processes you're concerned with? If you want it to affect *every* process you call from Emacs, then you could just modify the variable directly, rather than let-binding it. Then you wouldn't need to do anything else. – phils Sep 19 '14 at 03:56
  • I think I'm getting myself into a weird place here. I just need to accept that until I find something better than having a cygwin-specific home directory I'm going to have to deal with a few inconsistencies. I'm going to try just modifying the variable and see what kind of issues I run into. – kleinpa Sep 19 '14 at 04:20
  • Well the first broken thing I've encountered is that all the bookmark functions try to open .emacs.d in the new HOME directory. Going to have to revert to writing a cygwin-shell function unless there is a way to affect only the "shell" functions. – kleinpa Sep 19 '14 at 14:55
0

From the Emacs manual:

Emacs sends the new shell the contents of the file ~/.emacs_shellname as input, if it exists, where shellname is the name of the file that the shell was loaded from. For example, if you use bash, the file sent to it is ~/.emacs_bash. If this file is not found, Emacs tries with ~/.emacs.d/init_shellname.sh.

So for zsh you would put inside ~/.emacs.d/init_zsh.sh something like:

export HOME=/tmp
Davor Cubranic
  • 1,051
  • 10
  • 16