;;; Time-stamp: <2005-11-03 10:10:41 john> ;;; originated 95/11/09? ;; Start shells on various machines and in various directories. ;; This program is free software; you can redistribute it and/or modify it ;; under the terms of the GNU General Public License as published by the ;; Free Software Foundation; either version 2 of the License, or (at your ;; option) any later version. ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License along ;; with this program; if not, write to the Free Software Foundation, Inc., ;; 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (provide 'multiple-shells) (defvar shell-types '((sh . ?/) (csh . ?/) (dos . ?\\) (bash . ?/)) "Alist of shell types to the directory separators they use.") (defun filename-in-shell-format (filename &optional shell-type) "Return FILENAME in the format for shells of optonal SHELL-TYPE, which defaults to the native kind of shell for the system this emacs is running on. See shell-types for possible values." (if (null shell-type) (setq shell-type (if (eq system-type 'windows-nt) 'dos 'sh))) (let ((separator (cdr (assoc shell-type shell-types))) (newname (copy-sequence filename)) (place nil)) (while (setq place (string-match "[/\\]" newname place)) ;; (message "%s" place) (aset newname place separator) (incf place)) ; in case the replacement is the same newname)) (defun make-named-shell (name &optional directory) "Make a shell called NAME, optionally cd it to DIRECTORY." (interactive "sShell name: DDirectory to start %s in: ") (if (not (get-buffer name)) (progn (sleep-for 2) (let ((new-shell-buffer (shell))) (rename-buffer name) (if directory (let ((full-dir (expand-file-name directory))) (process-send-string (get-buffer-process new-shell-buffer) (format "cd %s\n" (filename-in-shell-format full-dir))) (cd full-dir)))))) (switch-to-buffer (get-buffer name))) (defun make-shell-for-directory-if-present (directory &optional name) "Make a shell for DIRECTORY, called NAME, if DIRECTORY exists." (if (file-directory-p directory) (make-named-shell (if name name (format "-%s-" (file-name-nondirectory directory))) directory))) ;; Put this outside the startup directory, since I haven't been able ;; to get load-directory not to load ~ files, and I'm going to have to ;; keep editing this. (require 'shells-to-start) (if (not (eq system-type 'windows-nt)) (start-shells)) ;;; end of startup/shell.el