As a workaround, the following can be used (Linux, Bash):
- First run
printenv -0 > env.txt
from the Bash terminal window,
- Then from within Emacs, run
(defun my-update-env ()
(interactive)
(let ((str
(with-temp-buffer
(insert-file-contents "env.txt")
(buffer-string))) lst)
(setq lst (split-string str "\000"))
(while lst
(setq cur (car lst))
(when (string-match "^\\(.*?\\)=\\(.*\\)" cur)
(setq var (match-string 1 cur))
(setq value (match-string 2 cur))
(setenv var value))
(setq lst (cdr lst)))))
Update
I turns out that this can be done more elegantly using the --eval
option of the emacsclient
command: Define a Bash script update_emacs_env
:
#! /bin/bash
fn=tempfile
printenv -0 > "$fn"
emacsclient -s server_name -e '(my-update-env "'"$fn"'")' >/dev/null
where server_name
is your Emacs server name, and my-update-env
is a function defined by your ~/.emacs
file:
(defun my-update-env (fn)
(let ((str
(with-temp-buffer
(insert-file-contents fn)
(buffer-string))) lst)
(setq lst (split-string str "\000"))
(while lst
(setq cur (car lst))
(when (string-match "^\\(.*?\\)=\\(.*\\)" cur)
(setq var (match-string 1 cur))
(setq value (match-string 2 cur))
(setenv var value))
(setq lst (cdr lst)))))
Now you can simply type update_emacs_env
from the shell command line to update the Emacs environment variables..