[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Execute In Multiple Shells?
From: |
Pascal J. Bourguignon |
Subject: |
Re: Execute In Multiple Shells? |
Date: |
Tue, 24 Nov 2009 01:13:48 +0100 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin) |
gamename <tennis@tripitinc.com> writes:
> How can I send the same command to multiple shell buffers at the same
> time? That is, if I have 5 bash shells running, how can I send
> "source ./.bash" to all of them at once?
(require 'cl)
(defvar buffer-name-map nil)
(defvar buffer-list-cache nil)
(defun buffer-named (name)
"
RETURN: the buffer which has as name `name'.
"
(let ((bl (buffer-list)))
(unless (and buffer-list-cache buffer-name-map
(equal buffer-list-cache bl))
(setf buffer-list-cache (copy-seq bl))
(setf buffer-name-map (make-hash-table :test (function equal)))
(dolist (buffer buffer-list-cache)
(let ((name (buffer-name buffer)))
(when name (setf (gethash name buffer-name-map) buffer)))
(let ((name (buffer-file-name buffer)))
(when name (setf (gethash name buffer-name-map) buffer))))))
(or (gethash name buffer-name-map)
(gethash (truename name) buffer-name-map)))
(defun mapshell (command shell-buffers)
(dolist (shell shell-buffers)
(with-current-buffer (etypecase shell
(string (buffer-named shell))
(buffer shell)
(process (process-buffer shell)))
(if (char= (aref "\n" 0) (aref command (1- (length command))))
(comint-send-string (current-buffer) command)
(comint-send-string (current-buffer) (format "%s\n" command))))))
(mapshell "echo hello\n" (list "0shell" "1shell"))
--
__Pascal Bourguignon__