This commit is contained in:
Zelong Kuang
2025-12-22 13:38:50 +11:00
parent 241d735750
commit 4a6c56b638

View File

@@ -11,7 +11,21 @@
(defconst my-env-file (concat my-local-dir "env"))
(defun my-load-envvars-file (file &optional noerror)
(defun my/generate-envvars-file ()
"Generate environment variables file at ~/.emacs.d/.local/env."
(interactive)
;; Ensure the directory exists
(unless (file-exists-p my-local-dir)
(make-directory my-local-dir t))
;; Run printenv and redirect output to the env file
(with-temp-buffer
(call-process "printenv" nil t nil)
(write-region (point-min) (point-max) my-env-file nil 'silent))
(message "Environment variables saved to %s" my-env-file))
(defun my/load-envvars-file (file &optional noerror)
"Read and set envvars from FILE.
If NOERROR is non-nil, don't throw an error if the file doesn't exist or is
unreadable. Returns the names of envvars that were changed."