summaryrefslogtreecommitdiff
path: root/plugins/gpg-agent/gpg-agent.plugin.zsh
diff options
context:
space:
mode:
authorDapeng Gao <31944689+dpgao@users.noreply.github.com>2021-10-05 19:54:53 +0800
committerGitHub <noreply@github.com>2021-10-05 13:54:53 +0200
commite5b9b80008a2fd71b441ef39fe620ed47dad82e5 (patch)
tree10065dc53851dd4677d478487ed94e94a69d6c9f /plugins/gpg-agent/gpg-agent.plugin.zsh
parent49bc55f966d91b2a407c883cf1d0f21d0cdd9f4a (diff)
downloadzsh-e5b9b80008a2fd71b441ef39fe620ed47dad82e5.tar.gz
zsh-e5b9b80008a2fd71b441ef39fe620ed47dad82e5.tar.bz2
zsh-e5b9b80008a2fd71b441ef39fe620ed47dad82e5.zip
fix(gpg-agent): correctly overwrite `$SSH_AUTH_SOCK` and other improvements (#7059)
Diffstat (limited to 'plugins/gpg-agent/gpg-agent.plugin.zsh')
-rw-r--r--plugins/gpg-agent/gpg-agent.plugin.zsh25
1 files changed, 13 insertions, 12 deletions
diff --git a/plugins/gpg-agent/gpg-agent.plugin.zsh b/plugins/gpg-agent/gpg-agent.plugin.zsh
index 3e24c2527..0adc8de5d 100644
--- a/plugins/gpg-agent/gpg-agent.plugin.zsh
+++ b/plugins/gpg-agent/gpg-agent.plugin.zsh
@@ -1,16 +1,17 @@
-# Enable gpg-agent if it is not running-
-# --use-standard-socket will work from version 2 upwards
-
-AGENT_SOCK=$(gpgconf --list-dirs | grep agent-socket | cut -d : -f 2)
-
-if [[ ! -S $AGENT_SOCK ]]; then
- gpg-agent --daemon --use-standard-socket &>/dev/null
-fi
export GPG_TTY=$TTY
-# Set SSH to use gpg-agent if it's enabled
-GNUPGCONFIG="${GNUPGHOME:-"$HOME/.gnupg"}/gpg-agent.conf"
-if [[ -r $GNUPGCONFIG ]] && command grep -q enable-ssh-support "$GNUPGCONFIG"; then
- export SSH_AUTH_SOCK="$AGENT_SOCK.ssh"
+# Fix for passphrase prompt on the correct tty
+# See https://www.gnupg.org/documentation/manuals/gnupg/Agent-Options.html#option-_002d_002denable_002dssh_002dsupport
+function _gpg-agent_update-tty_preexec {
+ gpg-connect-agent updatestartuptty /bye &>/dev/null
+}
+autoload -U add-zsh-hook
+add-zsh-hook preexec _gpg-agent_update-tty_preexec
+
+# If enable-ssh-support is set, fix ssh agent integration
+if [[ $(gpgconf --list-options gpg-agent | awk -F: '$1=="enable-ssh-support" {print $10}') = 1 ]]; then
unset SSH_AGENT_PID
+ if [[ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]]; then
+ export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
+ fi
fi