summaryrefslogtreecommitdiff
path: root/plugins/gpg-agent
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2021-10-23 18:01:40 -0600
committerTuowen Zhao <ztuowen@gmail.com>2021-10-23 18:01:40 -0600
commitfad92c603be0ff36825cc53bf8c485d4b95c7869 (patch)
tree407fe826be62a3543b6feab4f3552f58575234de /plugins/gpg-agent
parentc674485e6b4abe313469900997d893d2940ee843 (diff)
parentf1dd97bb2a9df55fae9b1ca26c829b9f8b290667 (diff)
downloadzsh-fad92c603be0ff36825cc53bf8c485d4b95c7869.tar.gz
zsh-fad92c603be0ff36825cc53bf8c485d4b95c7869.tar.bz2
zsh-fad92c603be0ff36825cc53bf8c485d4b95c7869.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'plugins/gpg-agent')
-rw-r--r--plugins/gpg-agent/README.md2
-rw-r--r--plugins/gpg-agent/gpg-agent.plugin.zsh25
2 files changed, 14 insertions, 13 deletions
diff --git a/plugins/gpg-agent/README.md b/plugins/gpg-agent/README.md
index 9c1e6d2cc..8eeb94f92 100644
--- a/plugins/gpg-agent/README.md
+++ b/plugins/gpg-agent/README.md
@@ -2,7 +2,7 @@
Enables [GPG's gpg-agent](https://www.gnupg.org/documentation/manuals/gnupg/) if it is not running.
-To use it, add gpg-agent to the plugins array of your zshrc file:
+To use it, add `gpg-agent` to the plugins array of your zshrc file:
```zsh
plugins=(... gpg-agent)
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