From 3ed54e191bc7db1b8adf46915601f322a0d364e5 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 17 May 2019 20:19:35 -0400 Subject: [PATCH] Fix #1322: replace load-env-vars w/ custom loader I've replaced load-env-var with our own custom parser. load-env-var expects a well-formatted env file, which neither env nor set produces, which is what doom env uses to dump the shell environment. This should fix issues that arise when envvars (like PATH) contain arbitrary whitespace. --- core/cli/env.el | 14 +++++--------- core/core-packages.el | 2 +- core/core.el | 22 +++++++++++++++++++--- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/core/cli/env.el b/core/cli/env.el index c4eb077cb..7e6021c8b 100644 --- a/core/cli/env.el +++ b/core/cli/env.el @@ -67,7 +67,7 @@ It is rare that you'll need to change this.") '("-c") ;; Execute twice, once in a non-interactive login shell and once in an ;; interactive shell in order to capture all the init files possible. - '("-lc" "-ic")) + '("-ic")) "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 `doom-env-executable' to scrape envvars from your shell environment.") @@ -110,16 +110,12 @@ order of `doom-env-switches' determines priority." "# or set DOOMENV=1 in your shell environment/config.\n" "# ---------------------------------------------------------------------------\n\n")) (let ((env-point (point))) + ;; temporarily unset ignored environment variables + (dolist (var doom-env-ignored-vars) + (setenv var nil)) (dolist (shell-command-switch doom-env-switches) (message "Scraping env from '%s %s %s'" shell-file-name shell-command-switch doom-env-executable) - (insert (shell-command-to-string doom-env-executable))) - ;; sort the environment variables - (sort-lines nil env-point (point-max)) - ;; remove adjacent duplicated lines - (delete-duplicate-lines env-point (point-max) nil t) - ;; remove ignored environment variables - (dolist (var doom-env-ignored-vars) - (flush-lines (concat "^" var "=") env-point (point-max)))))))) + (insert (shell-command-to-string doom-env-executable)))))))) diff --git a/core/core-packages.el b/core/core-packages.el index afb48a873..3188bfb97 100644 --- a/core/core-packages.el +++ b/core/core-packages.el @@ -38,7 +38,7 @@ package's name as a symbol, and whose CDR is the plist supplied to its `package!' declaration. Set by `doom-initialize-packages'.") (defvar doom-core-packages - '(persistent-soft use-package quelpa async load-env-vars) + '(persistent-soft use-package quelpa async) "A list of packages that must be installed (and will be auto-installed if missing) and shouldn't be deleted.") diff --git a/core/core.el b/core/core.el index bd6cff878..6cc28a06f 100644 --- a/core/core.el +++ b/core/core.el @@ -427,6 +427,23 @@ in interactive sessions, nil otherwise (but logs a warning)." (message "Autoload file warning: %s -> %s" (car e) (error-message-string e)) (signal 'doom-autoload-error (list (file-name-nondirectory file) e)))))) +(defun doom-load-env-vars (file) + "Read and set envvars in FILE." + (let (vars) + (with-temp-buffer + (insert-file-contents file) + (re-search-forward "\n\n" nil t) + (while (re-search-forward "\n\\([^= \n]+\\)=" nil t) + (save-excursion + (let ((var (match-string 1)) + (value (buffer-substring-no-properties + (point) + (1- (or (when (re-search-forward "^\\([^= ]+\\)=" nil t) + (line-beginning-position)) + (point-max)))))) + (setenv var value))))) + vars)) + (defun doom-initialize (&optional force-p) "Bootstrap Doom, if it hasn't already (or if FORCE-P is non-nil). @@ -491,9 +508,8 @@ to least)." ;; Load shell environment (when (and (not noninteractive) - (file-readable-p doom-env-file) - (require 'load-env-vars nil t)) - (load-env-vars doom-env-file) + (file-readable-p doom-env-file)) + (doom-load-env-vars doom-env-file) (setq exec-path (append (split-string (getenv "PATH") ":") (list exec-directory)) shell-file-name (or (getenv "SHELL")