Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only parse the stdout from direnv export json #42

Merged
merged 3 commits into from
May 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions direnv.el
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,29 @@ In these modes, direnv will use `default-directory' instead of
(unless direnv--installed
(user-error "Could not find the direnv executable. Is exec-path correct?"))
(let ((environment process-environment)
;; call-process can only output stderr to file
(stderr-tempfile (make-temp-file "direnv-stderr")))

(stderr-tempfile (make-temp-file "direnv-stderr"))) ;; call-process needs a file for stderr output
(unwind-protect
(with-current-buffer (get-buffer-create direnv--output-buffer-name)
(erase-buffer)
(let* ((default-directory directory)
(process-environment environment)
(exit-code (call-process "direnv" nil `(t ,stderr-tempfile) nil "export" "json")))
(unless (zerop exit-code)
; write the stderr messages to the end of our output buffer
(insert-file-contents stderr-tempfile)
; then fill a temp buffer with the message and display in status bar
(exit-code (call-process "direnv" nil `(t ,stderr-tempfile) nil "export" "json"))
(json-key-type 'string))
(prog1
(unless (zerop (buffer-size))
(goto-char (point-max))
(re-search-backward "^{")
(json-read-object))
(unless (zerop (file-attribute-size (file-attributes stderr-tempfile)))
(goto-char (point-max))
(unless (zerop (buffer-size))
(insert "\n\n"))
(insert-file-contents stderr-tempfile))
(with-temp-buffer
(insert-file-contents stderr-tempfile)
(message "direnv exited %s:\n%s\nOpen hidden buffer \"%s\" for full output"
exit-code (buffer-string) direnv--output-buffer-name)))
(unless (zerop (buffer-size))
(goto-char (point-max))
(re-search-backward "^{")
(let ((json-key-type 'string))
(json-read-object)))))

(unless (zerop exit-code)
(insert-file-contents stderr-tempfile)
(warn "Error running direnv (exit code %d):\n%s\nOpen buffer ‘%s’ for full output."
exit-code (buffer-string) direnv--output-buffer-name))))))
(delete-file stderr-tempfile))))

(defun direnv--enable ()
Expand Down