From 0dfdbd471c548e974701e5211162a5ef513fea70 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 27 Jul 2019 00:02:38 +0200 Subject: [PATCH] Ensure envvars at top of envvar file are checked The regexp expects there to be at least one newline at the top of the file, otherwise the very first envvar is skipped. --- core/cli/env.el | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/core/cli/env.el b/core/cli/env.el index 4751a4888..d144f63c4 100644 --- a/core/cli/env.el +++ b/core/cli/env.el @@ -108,6 +108,26 @@ default, on Linux, this is '$SHELL -ic /usr/bin/env'. Variables in (unless (string-empty-p errors) (print! (info "Error output:\n\n%s") (indent 4 errors)))) ;; Remove undesireable variables + (insert + (concat + "# -*- mode: dotenv -*-\n" + (format "# Generated with: %s %s %s\n" + shell-file-name + doom-env-switches + doom-env-executable) + "# ---------------------------------------------------------------------------\n" + "# This file was auto-generated by `doom env refresh'. It contains a list of\n" + "# environment variables scraped from your default shell (excluding variables\n" + "# blacklisted in doom-env-ignored-vars).\n" + "#\n" + "# It is NOT safe to edit this file. Changes will be overwritten next time that\n" + "# `doom env refresh` is executed. Alternatively, create your own env file and\n" + "# load it with `(doom-load-envvars-file FILE)`.\n" + "#\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" + "# ---------------------------------------------------------------------------\n\n")) + (goto-char (point-min)) (while (re-search-forward "\n\\([^= \n]+\\)=" nil t) (save-excursion (let* ((valend (or (save-match-data @@ -120,26 +140,6 @@ default, on Linux, this is '$SHELL -ic /usr/bin/env'. Variables in return t) (print! (info "Ignoring %s") var) (delete-region (match-beginning 0) (1- valend))))))) - (goto-char (point-min)) - (insert - (concat - "# -*- mode: dotenv -*-\n" - (format "# Generated with: %s %s %s\n" - shell-file-name - doom-env-switches - doom-env-executable) - "# ---------------------------------------------------------------------------\n" - "# This file was auto-generated by `doom env refresh'. It contains a list of\n" - "# environment variables scraped from your default shell (excluding variables\n" - "# blacklisted in doom-env-ignored-vars).\n" - "#\n" - "# It is NOT safe to edit this file. Changes will be overwritten next time that\n" - "# `doom env refresh` is executed. Alternatively, create your own env file and\n" - "# load it with `(doom-load-envvars-file FILE)`.\n" - "#\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" - "# ---------------------------------------------------------------------------\n\n")) (print! (success "Successfully generated %S") (relpath doom-env-file doom-emacs-dir)) t)))))