1

After a command terminates in shell-mode, I want to execute an additional command conditional on stdout. How can this be automated?

1
  • 1
    Could you give a minimal example of output and command?
    – wasamasa
    Commented Dec 11, 2014 at 19:17

1 Answer 1

1

Add a hook to comint-output-filter-functions. In the example below, ls is sent to the shell if the output from a command matches "foo".

(defun my-hook (str)
  (when (string-match "foo" str)
    (insert "ls")
    (comint-send-input)))

(add-hook 'shell-mode-hook
          (lambda ()
            (make-local-variable 'comint-output-filter-functions)
            (add-hook 'comint-output-filter-functions #'my-hook)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.