From d28990537fca5266095e442e3806bcb2edb7f32e Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Fri, 15 Jun 2018 02:40:44 -0400 Subject: [PATCH] Add new variable dotspacemacs-import-env-vars-shell-file-name Used to fetch the environment variables. This allows to keep shell-file-name untouched. --- core/core-dotspacemacs.el | 7 +++++++ core/templates/.spacemacs.template | 9 +++++++++ doc/DOCUMENTATION.org | 9 +++++---- .../spacemacs-bootstrap/funcs.el | 19 +++++++++++++++---- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/core/core-dotspacemacs.el b/core/core-dotspacemacs.el index 0d01957f8..71e729d83 100644 --- a/core/core-dotspacemacs.el +++ b/core/core-dotspacemacs.el @@ -62,6 +62,13 @@ or `spacemacs'.") from your default shell on startup. This is enabled by default for macOS users and X11 users.") +(defvar dotspacemacs-import-env-vars-shell-file-name nil + "If nil then use the default shell is used to fetch the environment variables. +Set this variable to a different shell executable path to import the environment +variables from this shell. Note that `file-shell-name' is preserved and always +points to the default shell. For instance to use your fish shell environment +variables set this variable to `/usr/local/bin/fish'.") + (defvar dotspacemacs-enable-emacs-pdumper nil "If non-nil then enable support for the portable dumper. You'll need to compile Emacs 27 from source following the instructions in file diff --git a/core/templates/.spacemacs.template b/core/templates/.spacemacs.template index ebb4bc486..200cc9706 100644 --- a/core/templates/.spacemacs.template +++ b/core/templates/.spacemacs.template @@ -162,6 +162,15 @@ It should only modify the values of Spacemacs settings." (or (eq system-type 'darwin) (eq window-system 'x))) + ;; If nil then use the default shell is used to fetch the environment + ;; variables. Set this variable to a different shell executable path to + ;; import the environment variables from this shell. Note that + ;; `file-shell-name' is preserved and always points to the default shell. For + ;; instance to use your fish shell environment variables set this variable to + ;; `/usr/local/bin/fish'. + ;; (default nil) + dotspacemacs-import-env-vars-shell-file-name nil + ;; Specify the startup banner. Default value is `official', it displays ;; the official spacemacs logo. An integer value is the index of text ;; banner, `random' chooses a random text banner in `core/banners' diff --git a/doc/DOCUMENTATION.org b/doc/DOCUMENTATION.org index 4e683c6ae..3a6c3bf98 100644 --- a/doc/DOCUMENTATION.org +++ b/doc/DOCUMENTATION.org @@ -1733,12 +1733,13 @@ build of Emacs. At anytime you can import the environment variables by calling the function =spacemacs/loadenv=. -You can define a different shell than the default shell by setting the variable -=shell-file-name= in the =dotspacemacs/user-init= function of your dotfile. +You can define a different shell than the default shell to look for environment +variables by setting the variable =dotspacemacs-import-env-vars-shell-file-name= +in your dotfile. Note that =shell-file-name= is not modified by this value. #+BEGIN_EXAMPLE emacs-lisp -(defun dotspacemacs/user-init () - (setq shell-file-name "/usr/local/bin/fish")) +(defun dotspacemacs/init () + (setq dotspacemacs-import-env-vars-shell-file-name "/usr/local/bin/fish")) #+END_EXAMPLE * Commands diff --git a/layers/+distributions/spacemacs-bootstrap/funcs.el b/layers/+distributions/spacemacs-bootstrap/funcs.el index 12450c806..e04e570d9 100644 --- a/layers/+distributions/spacemacs-bootstrap/funcs.el +++ b/layers/+distributions/spacemacs-bootstrap/funcs.el @@ -18,8 +18,13 @@ (require 'async nil t) (async-start `(lambda () - ,(async-inject-variables "\\`shell-file-name\\'") - (split-string (shell-command-to-string "env") "\n")) + ,(async-inject-variables + "\\`dotspacemacs-import-env-vars-shell-file-name\\'") + (if dotspacemacs-import-env-vars-shell-file-name + (let ((shell-file-name + dotspacemacs-import-env-vars-shell-file-name)) + (split-string (shell-command-to-string "env") "\n")) + (split-string (shell-command-to-string "env") "\n"))) (lambda (envvars) (spacemacs-buffer/message "Imported environment variables:") (dolist (env envvars) @@ -29,8 +34,14 @@ (v (cadr var))) (spacemacs-buffer/message " - %s=%s" k v) (if (string-equal "PATH" k) - (setq exec-path (split-string v path-separator)) - (setenv k v)))))))) + (let ((paths (split-string v path-separator))) + (dolist (p paths) + (add-to-list 'exec-path p))) + (setenv k v))))) + ;; be sure we keep the default shell in this Emacs session + ;; this is to prevent potential issues with packages which could + ;; expect a default shell + (setenv "SHELL" shell-file-name))))