From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Execute In Multiple Shells? Date: Tue, 24 Nov 2009 01:13:48 +0100 Organization: Informatimago Message-ID: <87tywkbwzn.fsf@galatea.local> References: <62546fac-b9c5-4eaa-a75f-f2d0cedce91f@x5g2000prf.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1259023343 22562 80.91.229.12 (24 Nov 2009 00:42:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 24 Nov 2009 00:42:23 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Nov 24 01:42:16 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NCjTz-0005rZ-SN for geh-help-gnu-emacs@m.gmane.org; Tue, 24 Nov 2009 01:42:16 +0100 Original-Received: from localhost ([127.0.0.1]:48836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NCjTz-0006IZ-9v for geh-help-gnu-emacs@m.gmane.org; Mon, 23 Nov 2009 19:42:15 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 46 Original-X-Trace: individual.net fqwc01O3GJ8xe2i4agFb0w18fb5MMuai93X06Vs9ep6Spos53x Cancel-Lock: sha1:NmZhZDQ5YmE0NmRlYzcxZjIzZDM5MThmZDIxM2Q0MmY2YzU2MmQwYQ== sha1:MVb+2CxUU4MG2vC6shbOKf55xQ4= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin) Original-Xref: news.stanford.edu gnu.emacs.help:174998 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:70069 Archived-At: gamename 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__