(defcustom eshell-subcommand-bindings
'((eshell-in-subcommand-p t)
+ (eshell-in-pipeline-p nil)
(default-directory default-directory)
(process-environment (eshell-copy-environment)))
"A list of `let' bindings for subcommand environments."
(defmacro eshell-command-to-value (object)
"Run OBJECT synchronously, returning its result as a string.
Returns a string comprising the output from the command."
- `(let ((value (make-symbol "eshell-temp")))
+ `(let ((value (make-symbol "eshell-temp"))
+ (eshell-in-pipeline-p nil))
(eshell-do-command-to-value ,object)))
;;;_* Iterative evaluation
(eshell-command-result-p "echo ${*echo hi | *cat} | *cat"
"hi")))
+(ert-deftest eshell-test/subcommand-reset-in-pipeline ()
+ "Check that subcommands reset `eshell-in-pipeline-p'."
+ (skip-unless (executable-find "cat"))
+ (dolist (template '("echo {%s} | *cat"
+ "echo ${%s} | *cat"
+ "*cat $<%s> | *cat"))
+ (should (equal (eshell-test-command-result
+ (format template "echo $eshell-in-pipeline-p"))
+ nil))
+ (should (equal (eshell-test-command-result
+ (format template "echo | echo $eshell-in-pipeline-p"))
+ "last"))
+ (should (equal (eshell-test-command-result
+ (format template "echo $eshell-in-pipeline-p | echo"))
+ "first"))
+ (should (equal (eshell-test-command-result
+ (format template
+ "echo | echo $eshell-in-pipeline-p | echo"))
+ "t"))))
+
+(ert-deftest eshell-test/lisp-reset-in-pipeline ()
+ "Check that interpolated Lisp forms reset `eshell-in-pipeline-p'."
+ (skip-unless (executable-find "cat"))
+ (dolist (template '("echo (%s) | *cat"
+ "echo $(%s) | *cat"))
+ (should (equal (eshell-test-command-result
+ (format template "format \"%s\" eshell-in-pipeline-p"))
+ "nil"))))
+
(ert-deftest eshell-test/redirect-buffer ()
"Check that piping to a buffer works"
(with-temp-buffer