Skip to content

Instantly share code, notes, and snippets.

@spacebat
Forked from intinig/system.el
Last active August 29, 2015 14:06
Show Gist options
  • Save spacebat/cb601a06f75966438bea to your computer and use it in GitHub Desktop.
Save spacebat/cb601a06f75966438bea to your computer and use it in GitHub Desktop.
(defun source-env-get (script &rest vars)
"Source script in shell, then look for vars in the resulting subshell environment"
(loop for line in (split-string (shell-command-to-string (concat "source " script " && set")) "[\n]" t)
with result
if (string-match "^\\([[:alpha:]]+\\)=\\(.*\\)$" line)
do (let ((var (match-string 1 line))
(val (match-string 2 line)))
(when (or (not vars) (member var vars))
(push (cons var val) result)))
finally return result))
(defun env-set-alist (alist)
"Take an alist of string pairs, call setenv with them and return a list of strings by way of logging"
(loop for (var . val) in alist
do (setenv var val)
collect (concat var " = " val)))
(unless (getenv "TERM_PROGRAM")
(env-set-alist (source-env-get "~/.bash_profile" "PATH" "RIOT_GAMES_API_KEY" "RIOT_GAMES_NEW_KEY")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment