Skip to content

Instantly share code, notes, and snippets.

@bradwright
Created March 15, 2012 20:13
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradwright/2046593 to your computer and use it in GitHub Desktop.
Save bradwright/2046593 to your computer and use it in GitHub Desktop.
Set Emacs exec-path by shell $PATH
;; This sets the Emacs "PATH" environment variable and the `exec-path`
;; variable to the same value your login shell sees. The reason this
;; is necessary is because of this:
;;
;; http://developer.apple.com/library/mac/#qa/qa1067/_index.html
;;
;; Basically apps launched from Finder inherit their environment from
;; a .plist file rather than the shell environment.
(defun set-exec-path-from-shell-PATH ()
"Sets the exec-path to the same value used by the user shell"
(let ((path-from-shell
(replace-regexp-in-string
"[[:space:]\n]*$" ""
(shell-command-to-string "$SHELL -l -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
;; call function now
(set-exec-path-from-shell-PATH)
@drorata
Copy link

drorata commented Dec 3, 2014

Great stuff! Thank you!

@bradyt
Copy link

bradyt commented Aug 11, 2015

Yes, I like how short and sweet this is! Thank you!

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