1

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

Matthew Piziak
  • 6,038
  • 3
  • 31
  • 79

1 Answers1

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)))
Constantine
  • 9,122
  • 1
  • 35
  • 50