Add function to load env vars from a shell script
This commit is contained in:
parent
88510aa4f2
commit
0489d73a0a
@ -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/<persisted-vars-file> as a plist of (variable-name variable-value).
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user