Marginally refactor function to add SSH keys to current agent
Does this improve readability?
This commit is contained in:
parent
1ec3dd24e6
commit
53a9ede65c
|
@ -851,31 +851,37 @@ running ssh-agent and waits for the process to finish."
|
||||||
(user-error "SSH key %s does not exist, aborting" key-file))
|
(user-error "SSH key %s does not exist, aborting" key-file))
|
||||||
|
|
||||||
(with-environment-variables (("SSH_ASKPASS_REQUIRE" "never"))
|
(with-environment-variables (("SSH_ASKPASS_REQUIRE" "never"))
|
||||||
(let ((proc (make-process :name "ssh-add"
|
|
||||||
:buffer nil
|
(let* ((ssh-add-handle-output #'(lambda (process output)
|
||||||
:command (list "ssh-add" key-file)
|
(cond
|
||||||
:filter #'(lambda (process output)
|
((string= (format "Enter passphrase for %s: "
|
||||||
(cond
|
key-file)
|
||||||
((string= (format "Enter passphrase for %s: "
|
output)
|
||||||
key-file)
|
(process-send-string process (funcall password-fn))
|
||||||
output)
|
(process-send-string process "\n"))
|
||||||
(process-send-string process (funcall password-fn))
|
((or (save-match-data
|
||||||
(process-send-string process "\n"))
|
(string-match (format "^Identity added: %s" key-file)
|
||||||
((or (save-match-data
|
output))
|
||||||
(string-match (format "^Identity added: %s" key-file)
|
(string= output "\n"))
|
||||||
output))
|
;; Ignore harmless output
|
||||||
(string= output "\n"))
|
t)
|
||||||
;; Ignore harmless output
|
(t (message "Unknown output received from ssh-agent: %s" output)))))
|
||||||
t)
|
|
||||||
(t (message "Unknown output received from ssh-agent: %s" output))))
|
(ssh-add-handle-event-change #'(lambda (_ event)
|
||||||
:sentinel #'(lambda (_ event)
|
|
||||||
(cond
|
(cond
|
||||||
((string= event "finished\n")
|
((string= event "finished\n")
|
||||||
(message "Successfully added %s to local SSH agent"
|
(message "Successfully added %s to local SSH agent"
|
||||||
key-file))
|
key-file))
|
||||||
(t (message "Adding SSH key %s failed, ssh-add process reached state %s"
|
(t (message "Adding SSH key %s failed, ssh-add process reached state %s"
|
||||||
key-file
|
key-file
|
||||||
event)))))))
|
event)))))
|
||||||
|
|
||||||
|
(proc (make-process :name "ssh-add"
|
||||||
|
:buffer nil
|
||||||
|
:command (list "ssh-add" key-file)
|
||||||
|
:filter ssh-add-handle-output
|
||||||
|
:sentinel ssh-add-handle-event-change)))
|
||||||
|
|
||||||
;; We are waiting for the process to finish, to not let its output
|
;; We are waiting for the process to finish, to not let its output
|
||||||
;; intermingle with others. XXX: is there a more standard way to wait for
|
;; intermingle with others. XXX: is there a more standard way to wait for
|
||||||
;; a process to finish?
|
;; a process to finish?
|
||||||
|
|
Loading…
Reference in New Issue