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

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

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")

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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