; -*- sawfish-mode -*- ; vim:ft=lisp ;; crunchy/remote-terminal.jl -- helper for opening remote ;; terminals. The function remote-terminal displays a selection list ;; of hosts where to open a remote terminal (supports completion). ;; version 0.2.2 ;; Copyright (C) ;; 2001 Thomas Buntrock ;; 2002, 2003, 2004 Andreas BÜsching ;; this 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, or (at your option) ;; any later version. ;; this 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 sawfish; see the file COPYING. If not, write to ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. ;; Installation (e.g.): ;; - copy this file to ~/.sawfish/lisp/crunchy ;; (this path without /crunchy need to be in your load-path) ;; - add (require 'crunchy.remote-terminal) to your ~/.sawfishrc (define-structure crunchy.remote-terminal (export crunchy/remote-terminal ) (open rep rep.system rep.regexp sawfish.wm.events sawfish.wm.custom sawfish.wm.misc ) (defgroup remote-terminal "Remote Terminal" :group misc) (defcustom remote-terminal-host-list '("localhost") nil :type* `(list string ,(_ "Selectable Hosts")) :widget-flags (expand-vertically framed) :user-level novice :group (misc remote-terminal)) (defcustom remote-terminal-exec-cmd "rxvt -title \"SSH to %s\" -e ssh %s &" "Command" :type string :widget-flags (expand-horizontally framed) :user-level expert :group (misc remote-terminal)) (defun remote-terminal-read-event () (throw 'remote-terminal-read (event-name (current-event)))) (defun remote-terminal-window-line (w) (format nil "%s\n" w)) (defun remote-terminal-display-format (input wlist) (concat "HOST: " input "_\n\n" (apply concat (mapcar remote-terminal-window-line wlist)))) (defun remote-terminal-rotate-from (elem lst) (if elem (append (memq elem lst) (reverse (cdr (memq elem (reverse lst))))) lst)) (defun remote-terminal-rotate-to-next-match (input wlist #!optional previous) (setq wlist (remote-terminal-rotate-from (catch 'remote-terminal-found (mapc (lambda (w) (when (string-match input w 0 t) (throw 'remote-terminal-found w))) (if previous (reverse (cdr wlist)) (cdr wlist)))) wlist))) (defun remote-terminal-update-match (input wlist) (filter (lambda (w) (string-match input w 0 t)) wlist)) (defun remote-terminal-get-host () (when (grab-keyboard) (unwind-protect (let* ((override-keymap '(keymap)) (input "") (key "") (init-wlist remote-terminal-host-list) wlist) (setq wlist init-wlist) (add-hook 'unbound-key-hook remote-terminal-read-event) (catch 'exit-remote-terminal (while t (display-message (remote-terminal-display-format input wlist)) (setq key (catch 'remote-terminal-read (recursive-edit))) (cond ((equal key "ESC") (throw 'exit-remote-terminal nil)) ((equal key "BS") (when (> (length input) 0) (setq input (substring input 0 (1- (length input))))) (setq wlist (remote-terminal-update-match input init-wlist))) ((or (equal key "TAB") (equal key "C-s") (equal key "A-s")) (setq wlist (remote-terminal-rotate-to-next-match input wlist))) ((or (equal key "M-TAB") (equal key "C-r") (equal key "A-r")) (setq wlist (remote-terminal-rotate-to-next-match input wlist t))) ((equal key "RET") (if (car wlist) (throw 'exit-remote-terminal (car wlist)) (throw 'exit-remote-terminal input))) ((equal key "H-t") (throw 'exit-remote-terminal "-a")) ((= 1 (length key)) (setq input (concat input key) wlist (remote-terminal-update-match input wlist))))))) (remove-hook 'unbound-key-hook remote-terminal-read-event) (display-message nil) (ungrab-keyboard)))) (defun crunchy/remote-terminal () "Run system on the variable `remote-terminal-exec-cmd'" (interactive) (let ((hostname (remote-terminal-get-host))) (system (format nil remote-terminal-exec-cmd hostname hostname hostname hostname)))) )