From 4223b12cf9cec9d5f5ad9a429ab7c081df77bec6 Mon Sep 17 00:00:00 2001 From: Sebastian Wiesner Date: Thu, 13 Sep 2012 19:08:38 +0200 Subject: [PATCH] Extract PATH via marker An interactive shell may have additional output depending on the user's shell configuration. Insert a marker and extract the value via this marker to make sure that only the actual "$PATH" content is returned. --- exec-path-from-shell.el | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/exec-path-from-shell.el b/exec-path-from-shell.el index e0f3fd7..f68251c 100644 --- a/exec-path-from-shell.el +++ b/exec-path-from-shell.el @@ -57,9 +57,11 @@ ;;; Code: (defun exec-path-from-shell-getenv (name) - (replace-regexp-in-string - "[ \t\n]*$" "" - (shell-command-to-string (format "$SHELL --login -i -c 'echo $%s'" name)))) + (with-temp-buffer + (call-process (getenv "SHELL") nil (current-buffer) nil + "--login" "-i" "-c" (concat "echo __RESULT=$" name)) + (when (re-search-backward "__RESULT=\\(.*\\)" nil t) + (match-string 1)))) ;;;###autoload (defun exec-path-from-shell-copy-env (name)