diff options
author | Aaron LI <aly@aaronly.me> | 2018-01-13 11:22:20 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2018-01-13 11:22:20 +0800 |
commit | 2ab350b4c38f89605cc401728be27e3e27efdcb1 (patch) | |
tree | 37ae022b0e3b8c7d3cace6ef87a998202cab5104 | |
parent | fb1a24bb8c0d8afde367cfa8b536510c1eb0f132 (diff) | |
download | dotfiles-2ab350b4c38f89605cc401728be27e3e27efdcb1.tar.bz2 |
zsh: improve ssh-agent support by gpg-agent
-rw-r--r-- | _zsh/80-gpg.zsh | 33 |
1 files changed, 32 insertions, 1 deletions
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: # |