kleinpa
kleinpa

Reputation: 117

Emacs shell-specific environment variables

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.

Upvotes: 2

Views: 1176

Answers (2)

Davor Cubranic
Davor Cubranic

Reputation: 1120

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

Upvotes: 1

phils
phils

Reputation: 73236

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

Upvotes: 3

Related Questions