Skip to content

Instantly share code, notes, and snippets.

@kenmanheimer
Created April 17, 2015 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenmanheimer/bc03f06dbe06a4c9fd28 to your computer and use it in GitHub Desktop.
Save kenmanheimer/bc03f06dbe06a4c9fd28 to your computer and use it in GitHub Desktop.
(defun my-get-agent ()
"Establish my registered ssh agent in this emacs shell *and* emacs session."
(interactive)
(let ((process (get-buffer-process (current-buffer)))
beg end start-point)
(if (not process)
(error "Non-shell buffer")
(goto-char (process-mark process))
(insert "eval $(ga); echo SSH_AUTH_SOCK::$SSH_AUTH_SOCK::")
(comint-send-input)
(setq start-point (point))
(let ((tries 0)
got)
(while (not got)
(sleep-for .25)
(goto-char (point-max))
(setq tries (1+ tries))
(if (> tries 40)
(error "Failed to find agent socket id after 10 seconds"))
(when (re-search-backward "SSH_AUTH_SOCK::\\(.*\\)::" start-point t)
(setq got (buffer-substring (match-beginning 1) (match-end 1)))
(setenv "SSH_AUTH_SOCK" got)
(goto-char (process-mark process))
(message "SSH_AUTH_SOCK: %s" (getenv "SSH_AUTH_SOCK"))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment