Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Execute In Multiple Shells?

2 views
Skip to first unread message

gamename

unread,
Nov 23, 2009, 6:03:47 PM11/23/09
to

Hi,

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?

Thanks,
-T

Pascal J. Bourguignon

unread,
Nov 23, 2009, 7:13:48 PM11/23/09
to

(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__

Peter Dyballa

unread,
Nov 24, 2009, 4:24:44 AM11/24/09
to gamename, help-gn...@gnu.org


The latter can easily be put into ~/.emacs_bash...

--
Greetings

Pete

I love deadlines. I love the whooshing noise they make as they go by.
– Douglas Adams

Dmitry Dzhus

unread,
Nov 24, 2009, 2:32:51 PM11/24/09
to
Pascal J. Bourguignon wrote:

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

How is this different from `get-buffer`?
--
Happy Hacking.

http://sphinx.net.ru

Pascal J. Bourguignon

unread,
Nov 24, 2009, 2:56:46 PM11/24/09
to
Dmitry Dzhus <di...@sphinx.net.ru> writes:

It uses truename, which I forgot to adjoin:


(defun truename (filespec)
"
RETURN: The absolute path name corresponding to fielspec.
"
(car (file-expand-wildcards (shell-quote-argument filespec) t)))

--
__Pascal Bourguignon__

gamename

unread,
Jan 21, 2010, 11:27:50 AM1/21/10
to
On Nov 24 2009, 11:56 am, p...@informatimago.com (Pascal J.
Bourguignon) wrote:

Thanks guys!
-T

0 new messages