branch: elpa/exec-path-from-shell
commit 4223b12cf9cec9d5f5ad9a429ab7c081df77bec6
Author: Sebastian Wiesner <[email protected]>
Commit: Sebastian Wiesner <[email protected]>
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 e0f3fd72c3..f68251cfc3 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)