4

Within emacs, I want to have multiple shells open, type a command once, and have it run in each shell -- similar to the way multixterm ( http://freecode.com/projects/multixterm ) does.

Ishpeck
  • 1,973
  • 1
  • 18
  • 20

1 Answers1

7

With some minimal testing, this will do:

(defun send-to-all-shells ()
  (interactive)
  (let ((command (read-from-minibuffer "Command: ")))
    (mapcar #'(lambda (x) (comint-send-string x (concat "\n" command "\n")))
            (remove-if-not
             #'(lambda (x) 
                 (string= "/bin/bash" 
                          (car (process-command x))))
             (process-list)))))

To run, just M-x send-to-all-shells, enter the command you want, and it will be sent to all open shells. This assumes your shell is found in /bin/bash. If not, change that bit accordingly.

If you do this a lot, you'll want to bind that to your favourite key combo. It would be possible to borrow and modify the code in comint-send-input such that you could just enter the command you want at the prompt of one shell, hit your key and have that command send to all shells simultaneously. I'm short on time, so I'll leave that as an exercise for the reader.

Tyler
  • 9,474
  • 1
  • 31
  • 54