diff --git a/emacs/init.org b/emacs/init.org index cd9fb0c..89a46a8 100755 --- a/emacs/init.org +++ b/emacs/init.org @@ -286,6 +286,19 @@ Pretty-print JSON: (buffer-substring (point-min) (point-max)))) #+END_SRC +Load environment variables into Emacs from a shell script: +#+BEGIN_SRC emacs-lisp + (defun source-env-file (file) + (interactive "fFile: \n") + (let ((var-re "\\(.+?\\)=\\(.+\\)$")) + (with-temp-buffer + (shell-command (concat "source " file " > /dev/null && env") + (current-buffer)) + (save-match-data + (while (re-search-forward var-re nil t) + (setenv (match-string 1) (match-string 2))))))) +#+END_SRC + ** Persisting variables between session The idea behind this is pretty simple - variables get persisted in ~/.emacs.d/ as a plist of (variable-name variable-value).