From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: Execute In Multiple Shells?
Date: Tue, 24 Nov 2009 01:13:48 +0100 [thread overview]
Message-ID: <87tywkbwzn.fsf@galatea.local> (raw)
In-Reply-To: 62546fac-b9c5-4eaa-a75f-f2d0cedce91f@x5g2000prf.googlegroups.com
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__
next prev parent reply other threads:[~2009-11-24 0:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-23 23:03 Execute In Multiple Shells? gamename
2009-11-24 0:13 ` Pascal J. Bourguignon [this message]
2009-11-24 19:32 ` Dmitry Dzhus
2009-11-24 19:56 ` Pascal J. Bourguignon
2010-01-21 16:27 ` gamename
2009-11-24 9:24 ` Peter Dyballa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87tywkbwzn.fsf@galatea.local \
--to=pjb@informatimago.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).