cli/env: refactor

This commit is contained in:
Henrik Lissner 2019-05-17 21:34:21 -04:00
parent f8b359516f
commit 5ec0c5ba3f
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -64,10 +64,8 @@ It is rare that you'll need to change this.")
(defvar doom-env-switches (defvar doom-env-switches
(if IS-WINDOWS (if IS-WINDOWS
'("-c") "-c"
;; Execute twice, once in a non-interactive login shell and once in an "-ic") ; Execute in an interactive shell
;; interactive shell in order to capture all the init files possible.
'("-ic"))
"The `shell-command-switch'es to use on `doom-env-executable'. "The `shell-command-switch'es to use on `doom-env-executable'.
This is a list of strings. Each entry is run separately and in sequence with This is a list of strings. Each entry is run separately and in sequence with
`doom-env-executable' to scrape envvars from your shell environment.") `doom-env-executable' to scrape envvars from your shell environment.")
@ -93,11 +91,10 @@ order of `doom-env-switches' determines priority."
"# ---------------------------------------------------------------------------\n" "# ---------------------------------------------------------------------------\n"
"# This file was auto-generated by Doom by running:\n" "# This file was auto-generated by Doom by running:\n"
"#\n" "#\n"
(cl-loop for switch in doom-env-switches (format "# %s %s %s\n"
concat (format "# %s %s %s\n" shell-file-name
shell-file-name doom-env-switches
switch doom-env-executable)
doom-env-executable))
"#\n" "#\n"
"# It contains all environment variables scraped from your default shell\n" "# It contains all environment variables scraped from your default shell\n"
"# (excluding variables blacklisted in doom-env-ignored-vars).\n" "# (excluding variables blacklisted in doom-env-ignored-vars).\n"
@ -109,13 +106,12 @@ order of `doom-env-switches' determines priority."
"# To auto-regenerate this file when `doom reload` is run, use `doom env auto'\n" "# To auto-regenerate this file when `doom reload` is run, use `doom env auto'\n"
"# or set DOOMENV=1 in your shell environment/config.\n" "# or set DOOMENV=1 in your shell environment/config.\n"
"# ---------------------------------------------------------------------------\n\n")) "# ---------------------------------------------------------------------------\n\n"))
(let ((env-point (point))) ;; temporarily unset ignored environment variables
;; temporarily unset ignored environment variables (dolist (var doom-env-ignored-vars)
(dolist (var doom-env-ignored-vars) (setenv var nil))
(setenv var nil)) (let ((shell-command-switch doom-env-switches))
(dolist (shell-command-switch doom-env-switches) (message "Scraping env from '%s %s %s'"
(message "Scraping env from '%s %s %s'" shell-file-name
shell-file-name shell-command-switch
shell-command-switch doom-env-executable)
doom-env-executable) (insert (shell-command-to-string doom-env-executable)))))))
(insert (shell-command-to-string doom-env-executable))))))))