From 2ab350b4c38f89605cc401728be27e3e27efdcb1 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 13 Jan 2018 11:22:20 +0800 Subject: zsh: improve ssh-agent support by gpg-agent --- _zsh/80-gpg.zsh | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to '_zsh') diff --git a/_zsh/80-gpg.zsh b/_zsh/80-gpg.zsh index 80d1ecc..d72b699 100644 --- a/_zsh/80-gpg.zsh +++ b/_zsh/80-gpg.zsh @@ -15,6 +15,8 @@ if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)" fi +# Let pinentry know which console to display in for `ssh-agent'. +# # Since the 'ssh-agent' protocol does not contain a mechanism for telling # the agent on which terminal/display it is running, gpg-agent's # ssh-support can just use the TTY or X display when `gpg-agent' has been @@ -31,7 +33,36 @@ fi # https://www.gnupg.org/documentation/manuals/gnupg/Common-Problems.html # * `gpg-agent(1)': option `--enable-ssh-support' # -gpg-connect-agent updatestartuptty /bye >/dev/null +update-gpg-tty() { + gpg-connect-agent updatestartuptty /bye >/dev/null +} + +update-pinentry-app() { + echo "term" > ${XDG_RUNTIME_DIR}/pinentry-app +} + +# Hook the above functions to be exec'ed before every command execuation +# +# Credit: http://blog.mrloop.com/workflow/2017/02/09/pin-entry.html +# +autoload -U add-zsh-hook +zsh-preexec() { + update-gpg-tty + update-pinentry-app +} +add-zsh-hook preexec zsh-preexec + + +# Delete all identities from the `gpg-agent', which is similar to +# `ssh-add -D`. +# +# Credit: http://blog.mrloop.com/workflow/2017/02/09/pin-entry.html +# +ssh-delete() { + grep -o '^[A-Z0-9]*' ${HOME}/.gnupg/sshcontrol | \ + xargs -I'%' rm ${HOME}/.gnupg/private-keys-v1.d/'%'.key + echo "" > ${HOME}/.gnupg/sshcontrol +} # vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # -- cgit v1.2.2