Skip to content

Instantly share code, notes, and snippets.

@sebasmagri
Last active November 12, 2015 12:54
Show Gist options
  • Save sebasmagri/9727631 to your computer and use it in GitHub Desktop.
Save sebasmagri/9727631 to your computer and use it in GitHub Desktop.
Set Emacs executables PATH to the one used by interactive shells
;;; Put this in your .emacs file.
;;; PATH used by default in emacs is not that used in interactive shells. Thus, it would miss
;;; paths set in the shell's rc file.
;;; The login shell could print warnings or errors on initialization, so we isolate the PATH and
;;; use a simple regexp to get the real value
(let ((interactive-shell-path (shell-command-to-string "$SHELL -l -i -c 'echo \"***\n$PATH\n***\"'")))
(string-match ".*\\*\\*\\*\\\n\\(.*\\)\n\\*\\*\\*.*" interactive-shell-path)
(let ((clean-shell-path (match-string 1 interactive-shell-path)))
(setenv "PATH" clean-shell-path) ;;; normal PATH
(setq eshell-path-env clean-shell-path) ;;; PATH in eshell
(setq exec-path (split-string clean-shell-path path-separator)) ;;; exec-path
)
)
@sebasmagri
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment