Home / Emacs / Emacs / Initialization (init.el)
Paths
Copy the $PATH, $MANPATH, and LC_ALL variables from the interactive login
shell to Emacs. This is necessary on macOS, as its GUI starts programs within
a minimal environment.
In practice, this fixes various problems, such as the *compilation* buffer
not finding emacs, fortune not finding strfile, geiser-mode not finding
guile, emacs not finding gcc for native compilation, as well as, spurious
locale warnings.
(dolist (line (process-lines "bash" "-l" "-c" "export"))
(when (string-match "^.* \\(.*?\\)=\\\"\\(.*\\)\\\"$" line)
(let ((name (match-string 1 line))
(value (match-string 2 line)))
(setenv name value)
(when (string= name "PATH")
(setopt exec-path (split-string value path-separator))))))
(There is package on MELPA for this, but it is unnecessarily complex, and we need to run this before the package system is initialized.)
[I published this code for the wider Emacs community at StackOverflow.]