3

If I start GUI emacs in OSX (not from the terminal) it does not know about my user environment variables.

The exec-path-from-shell package mostly solves this, but while you can explicitly initialize specific environment variables, I can't see a way to initialize all environment variables.

I use environment variables to supply secrets to my applications, so I tend to have a lot of them and would prefer not to have to add and remove them from my init.el.

Dean
  • 203
  • 1
  • 9

2 Answers2

1

Here's what I could come up with:

(defun source-file-and-get-envs (filename)
  (let* ((cmd (concat ". " filename "; env"))
         (env-str (shell-command-to-string cmd))
         (env-lines (split-string env-str "\n"))
         (envs (mapcar (lambda (s) (replace-regexp-in-string "=.*$" "" s)) env-lines)))
    (delete "" envs)))

(exec-path-from-shell-copy-envs (source-file-and-get-envs "~/.profile")))

It sources the given file, then gets just the environment variable names from env.

Dean
  • 203
  • 1
  • 9
0

I can't see a way to initialize all environment variables.

(let ((bim (shell-command-to-string ". ~/.bashrc; echo -n $BIM")))
  (setenv "BIM" bim))

Something like this should do the trick. You'll probably want to add a loop.

Nsukami _
  • 6,341
  • 2
  • 22
  • 35
  • This looks like I'd still need to list out all of the environment variables I want. I have roughly 50 custom variables set, and want to use _all_ of them without having to name each one. – Dean Mar 01 '16 at 00:14
  • The command `env` will list out all environment variables and their values. – verdammelt Mar 01 '16 at 02:12