Emacs shell: enter once, run everywhere

In emacs, I want to open several shells, type the command once and run it in each shell - just like a multiscreen ( http://freecode.com/projects/multixterm ).

+4
source share
1 answer

With 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 start, just Mx send-to-all-shells , enter the desired command and it will be sent to all open shells. This assumes your shell is in /bin/bash . If not, change this bit accordingly.

If you do this a lot, you will want to associate it with your favorite key combo. It would be possible to borrow and modify the code in comint-send-input , so that you can simply enter the desired command on the command line of one shell, press your key and send this command to all the commands at the same time. I am short on time, so I will leave this as an exercise for the reader.

+7
source

Source: https://habr.com/ru/post/1398127/


All Articles