Add -o option to 'doom env'

Now you can output envvar files where ever you like.
This commit is contained in:
Henrik Lissner 2019-09-05 14:20:50 -04:00
parent 9f08d11908
commit f6b8807e83
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 90 additions and 87 deletions

View file

@ -98,7 +98,6 @@
(print! (error "No command detected.\n")))
(usage))
((require 'core-cli)
(let ((default-directory user-emacs-directory))
(setq argv nil)
(condition-case e
(doom-dispatch (car args) (cdr args))
@ -119,4 +118,4 @@
"Emacs outputs to standard error, so you'll need to redirect stderr to\n"
"stdout to pipe this to a file or clipboard!\n\n"
" e.g. doom -d install 2>&1 | clipboard-program"))
(signal 'doom-error e)))))))))
(signal 'doom-error e))))))))

View file

@ -22,22 +22,24 @@ This file is automatically regenerated when you run this command or 'doom
refresh'. However, 'doom refresh' will only regenerate this file if it exists.
Use the -c or --clear switch to delete your envvar file."
(let ((default-directory doom-emacs-dir))
(when (member "clear" args) ; DEPRECATED
(message "'doom env clear' is deprecated. Use 'doom env -c' or 'doom env --clear' instead")
(push "-c" args))
(let ((env-file (or (cadr (member "-o" args))
doom-env-file)))
(cond ((or (member "-c" args)
(member "--clear" args))
(unless (file-exists-p doom-env-file)
(unless (file-exists-p env-file)
(user-error! "%S does not exist to be cleared"
(relpath doom-env-file)))
(delete-file doom-env-file)
(relpath env-file)))
(delete-file env-file)
(print! (success "Successfully deleted %S")
(relpath doom-env-file)))
(relpath env-file)))
((null args)
(doom-reload-env-file 'force))
((or (null args)
(member "-o" args))
(doom-reload-env-file 'force env-file))
((user-error "I don't understand 'doom env %s'"
(string-join args " "))))))
@ -79,21 +81,23 @@ It is rare that you'll need to change this.")
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.")
;; Borrows heavily from Spacemacs' `spacemacs//init-spacemacs-env'.
(defun doom-reload-env-file (&optional force-p)
(defun doom-reload-env-file (&optional force-p env-file)
"Generates `doom-env-file', if it doesn't exist (or if FORCE-P).
This scrapes the variables from your shell environment by running
`doom-env-executable' through `shell-file-name' with `doom-env-switches'. By
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)))
(with-temp-file doom-env-file
(let ((env-file (if env-file
(expand-file-name env-file)
doom-env-file)))
(when (or force-p (not (file-exists-p env-file)))
(with-temp-file env-file
(print! (start "%s envvars file at %S")
(if (file-exists-p doom-env-file)
(if (file-exists-p env-file)
"Regenerating"
"Generating")
(relpath doom-env-file doom-emacs-dir))
(relpath env-file doom-emacs-dir))
(let ((process-environment doom--initial-process-environment))
(let ((shell-command-switch doom-env-switches)
(error-buffer (get-buffer-create "*env errors*")))
@ -138,5 +142,5 @@ default, on Linux, this is '$SHELL -ic /usr/bin/env'. Variables in
(print! (info "Ignoring %s") var)
(delete-region (match-beginning 0) (1- valend)))))))
(print! (success "Successfully generated %S")
(relpath doom-env-file doom-emacs-dir))
t)))))
(relpath env-file doom-emacs-dir))
t))))))