November 15, 2006
Emacsでpsvnを使っていると、ssh越しでチェックアウトしているリポジトリの操作ができません。うちの環境だけという噂もあるけど。ssh-agentが効いてるプロセスから立ち上げたemacsだと問題ないんだけど、たまに忘れてしまうことがあるので、emacsを立ち上げたあとでもssh-agentを起動できたら便利、ということで作ってみました。
(unless (and (getenv "SSH_AUTH_SOCK") (getenv "SSH_AGENT_PID"))
(let ((result (split-string (shell-command-to-string "ssh-agent") ";\n"))
(key (read-passwd "Enter passphrase for /homes/tom/.ssh/id_dsa: ")))
(setenv "SSH_AUTH_SOCK" (caddr (split-string (car result) " ")))
(setenv "SSH_AGENT_PID" (caddr (split-string (cadr result) " ")))
(let* ((buf "*ssh-add*")
(ssh-add (start-process "ssh-add" buf "ssh-add")))
(set-process-filter ssh-add
(lambda (proc string)
(if (string-match "Bad" string)
(process-send-string proc
(concat (read-passwd "ReEnter passphrase for /homes/tom/.ssh/id_dsa: ") "\n"))
(if (string-match "Identity added" string ) (kill-buffer "*ssh-add*")))))
(accept-process-output ssh-add 5 0)
(process-send-string ssh-add (concat key "\n"))
(accept-process-output ssh-add 5 0)))
(add-hook 'kill-emacs-hook
(lambda () (shell-command "ssh-agent -k"))))
あんまり使えねぇか。
