mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-01 12:17:25 -05:00
cli/env: remove ignored vars retroactively
doom-env-ignored-vars is now treated as a list of regexps. Also updates docstrings and announces ignored variables.
This commit is contained in:
@ -53,7 +53,10 @@ needs to be run once).")
|
|||||||
"INSECURE"
|
"INSECURE"
|
||||||
"DEBUG"
|
"DEBUG"
|
||||||
"YES")
|
"YES")
|
||||||
"Environment variables to not save in `doom-env-file'.")
|
"Environment variables to not save in `doom-env-file'.
|
||||||
|
|
||||||
|
Each string is a regexp, matched against variable names to omit from
|
||||||
|
`doom-env-file'.")
|
||||||
|
|
||||||
(defvar doom-env-executable
|
(defvar doom-env-executable
|
||||||
(if IS-WINDOWS
|
(if IS-WINDOWS
|
||||||
@ -72,11 +75,12 @@ This is a list of strings. Each entry is run separately and in sequence with
|
|||||||
|
|
||||||
;; Borrows heavily from Spacemacs' `spacemacs//init-spacemacs-env'.
|
;; Borrows heavily from Spacemacs' `spacemacs//init-spacemacs-env'.
|
||||||
(defun doom-reload-env-file (&optional force-p)
|
(defun doom-reload-env-file (&optional force-p)
|
||||||
"Generates `doom-env-file', if it doesn't exist (or FORCE-P is non-nil).
|
"Generates `doom-env-file', if it doesn't exist (or if FORCE-P).
|
||||||
|
|
||||||
Runs `doom-env-executable' X times, where X = length of `doom-env-switches', to
|
This scrapes the variables from your shell environment by running
|
||||||
scrape the variables from your shell environment. Duplicates are removed. The
|
`doom-env-executable' through `shell-file-name' with `doom-env-switches'. By
|
||||||
order of `doom-env-switches' determines priority."
|
default, on Linux, this is '$SHELL -ic /usr/bin/env'. Variables in
|
||||||
|
`doom-env-ignored-vars' are removed."
|
||||||
(when (or force-p (not (file-exists-p doom-env-file)))
|
(when (or force-p (not (file-exists-p doom-env-file)))
|
||||||
(with-temp-file doom-env-file
|
(with-temp-file doom-env-file
|
||||||
(message "%s envvars file at %S"
|
(message "%s envvars file at %S"
|
||||||
@ -104,12 +108,23 @@ order of `doom-env-switches' determines priority."
|
|||||||
"# To auto-regenerate this file when `doom reload` is run, use `doom env auto' or\n"
|
"# To auto-regenerate this file when `doom reload` is run, use `doom env auto' or\n"
|
||||||
"# set DOOMENV=1 in your shell environment/config.\n"
|
"# set DOOMENV=1 in your shell environment/config.\n"
|
||||||
"# ---------------------------------------------------------------------------\n\n"))
|
"# ---------------------------------------------------------------------------\n\n"))
|
||||||
;; temporarily unset ignored environment variables
|
|
||||||
(dolist (var doom-env-ignored-vars)
|
|
||||||
(setenv var nil))
|
|
||||||
(let ((shell-command-switch doom-env-switches))
|
(let ((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)))))))
|
(save-excursion
|
||||||
|
(insert (shell-command-to-string doom-env-executable)))
|
||||||
|
;; Remove undesireable variables
|
||||||
|
(dolist (regexp doom-env-ignored-vars)
|
||||||
|
(save-excursion
|
||||||
|
(when (re-search-forward (format "\n\\(%s+\\)=" regexp) nil t)
|
||||||
|
(let ((var (match-string 1)))
|
||||||
|
(message "Ignoring %s" var)
|
||||||
|
(delete-region
|
||||||
|
(match-beginning 0)
|
||||||
|
(1- (or (save-excursion
|
||||||
|
(when (re-search-forward "^\\([^= ]+\\)=" nil t)
|
||||||
|
(line-beginning-position)))
|
||||||
|
(point-max))))))))
|
||||||
|
(print! (green "Envvar successfully generated")))))))
|
||||||
|
Reference in New Issue
Block a user