Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (33 sloc) 1.49 KB
;;; config-environment.el --- Apply shell environment to Emacs.
(require 'cl)
(defun env-line-to-cons (env-line)
"Convert a string of the form \"VAR=VAL\" to a
cons cell containing (\"VAR\" . \"VAL\")."
(if (string-match "\\([^=]+\\)=\\(.*\\)" env-line)
(cons (match-string 1 env-line) (match-string 2 env-line))))
(defun interactive-env-alist (&optional shell-cmd env-cmd)
"Launch /usr/bin/env or the equivalent from a login
shell, parsing and returning the environment as an alist."
(let ((cmd (concat (or shell-cmd "$SHELL -lc")
" "
(or env-cmd "/usr/bin/env"))))
(mapcar 'env-line-to-cons
(lambda (str)
(string-equal str ""))
(split-string (shell-command-to-string cmd) "[\r\n]")))))
(defun setenv-from-cons (var-val)
"Set an environment variable from a cons cell containing
two strings, where the car is the variable name and cdr is
the value, e.g. (\"VAR\" . \"VAL\")"
(setenv (car var-val) (cdr var-val)))
(defun setenv-from-shell-environment (&optional shell-cmd env-cmd)
"Apply the environment reported by `/usr/bin/env' (or env-cmd)
as launched by `$SHELL -lc' (or shell-cmd) to the current
(mapc 'setenv-from-cons (interactive-env-alist shell-cmd env-cmd)))
(setq exec-path (split-string (getenv "PATH") path-separator))
(provide 'config-environment)
;;; config-environment.el ends here