Skip to content

Commit 59631fc

Browse files
authored
Merge pull request #125 from Gastove/redirect-nushell-stderr-to-buffer
Redirect Nushell stederr to a buffer
2 parents 4896a79 + 1d1ca66 commit 59631fc

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

exec-path-from-shell.el

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,23 +197,34 @@ shell-escaped, so they may contain $ etc."
197197
"Use nushell to get the value of env vars with the given NAMES.
198198
199199
Execute the shell according to `exec-path-from-shell-arguments'.
200-
The result is a list of (NAME . VALUE) pairs."
200+
The result is a list of (NAME . VALUE) pairs.
201+
202+
Nushell sometimes produces output like e.g. flag deprecation warnings.
203+
These messages are written to an error buffer (*exec-path-from-shell:
204+
nushell errors*); unless Nushell produces a non-zero exit code, this
205+
buffer is left undisplayed."
201206
(let* ((shell (exec-path-from-shell--shell))
202207
(expr (format "[ %s ] | to json"
203208
(string-join
204209
(mapcar (lambda (name)
205210
(format "$env.%s?" (exec-path-from-shell--double-quote name)))
206211
names)
207212
", ")))
208-
(shell-args (append exec-path-from-shell-arguments (list "-c" expr))))
213+
(shell-args (append exec-path-from-shell-arguments (list "-c" expr)))
214+
(err-buff-name "*exec-path-from-shell: nushell errors*")
215+
(err-file (make-temp-file err-buff-name)))
209216
(with-temp-buffer
217+
(kill-buffer err-buff-name)
210218
(exec-path-from-shell--debug "Invoking shell %s with args %S" shell shell-args)
211219
(let ((exit-code (exec-path-from-shell--warn-duration
212-
(apply #'call-process shell nil t nil shell-args))))
220+
(apply #'call-process shell nil '(t err-file) nil shell-args)))
221+
(err-buff (generate-new-buffer err-buff-name)))
213222
(exec-path-from-shell--debug "Shell printed: %S" (buffer-string))
223+
(with-current-buffer err-buff (insert-file-contents err-file))
214224
(unless (zerop exit-code)
215225
(error "Non-zero exit code from shell %s invoked with args %S. Output was:\n%S"
216-
shell shell-args (buffer-string))))
226+
shell shell-args (buffer-string))
227+
(display-buffer err-buff)))
217228
(goto-char (point-min))
218229
(let ((json-array-type 'list)
219230
(json-null :null))

0 commit comments

Comments
 (0)