;;;; split-site.el ;;; Time-stamp: <2004-11-01 11:48:51 john> ;;; keep some files synchronized (defvar netrc-filename "~/.netrc" "The name of your .netrc file.") (defun my-login-for-host (host) "Find my userid for HOST." (if (file-exists-p netrc-filename) (save-window-excursion (find-file netrc-filename) (save-excursion (goto-char (point-min)) (if (re-search-forward (format "machine %s .*login \\([-a-z_0-9]+\\) " host) (point-max) t) (match-string 1) (error "Login for host %s not found" host)))) (error "No .netrc file"))) (defvar my-external-host "mailhost.cb1.com" "The machine holding my non-work account") (defvar am-on-my-external-host (string= my-external-host (system-name)) "Whether this session is running on my external host.") (defvar my-external-login (if (file-exists-p netrc-filename) (my-login-for-host my-external-host) nil) "My login on the machine holding my non-work account.") (defvar my-external-home-directory "/anon/john" "My home directory on my non-work account.") (defmacro must-be-internal (&rest forms) "Run FORMS but only if not on external host." `(if am-on-my-external-host (error "Should not run this command on external host") (progn ,@forms))) (defvar in-copy-file-to-external nil "Whether we are already in copy-file-to-external. To prevent recursion via hooks.") (defun copy-file-to-external (file) "Copy FILE to my external account." (interactive "fCopy file to external account: ") (must-be-internal (let* ((local-file (expand-file-name file "~")) (already-visiting (find-buffer-visiting local-file))) (when (and already-visiting (not in-copy-file-to-external)) (let ((in-copy-file-to-external t)) (set-buffer already-visiting) (basic-save-buffer))) (copy-file local-file (format "/%s@%s:%s/%s" my-external-login my-external-host my-external-home-directory file) t)))) (defun copy-file-from-external (file &optional show-difference) "Copy FILE from my external account." (interactive "fCopy file from external account: ") (must-be-internal (let* ((local-file (expand-file-name file "~")) (already-visiting (find-buffer-visiting local-file)) (old-local (format "%s-%s" local-file system-name))) (copy-file local-file old-local t) (copy-file (format "/%s@%s:%s/%s" my-external-login my-external-host my-external-home-directory file) local-file t) (when already-visiting (find-file local-file)) (when show-difference (shell-command (format "diff -c %s %s" local-file old-local)))))) (defun diary-to-external () "Copy my diary file to my CB1 account." (interactive) (copy-file-to-external "diary")) (defun diary-from-external () "Copy my diary file from my CB1 account." (interactive) (copy-file-from-external "diary")) (defun mailrc-to-external () "Copy my mailrc file to my CB1 account." (interactive) (copy-file-to-external ".mailrc")) (defun mailrc-from-external () "Copy my mailrc file from my CB1 account." (interactive) (copy-file-from-external ".mailrc" t)) (defun bbdb-to-external () "Copy my bbdb file to my CB1 account." (interactive) (copy-file-to-external ".bbdb")) (defun bbdb-from-external () "Copy my bbdb file from my CB1 account." (interactive) (copy-file-from-external ".bbdb")) ;;; end of split-site.el