ohmyzsh/plugins/gpg-agent/gpg-agent.plugin.zsh
G'lek Tarssza fc2fc9a28c
Fixed gpg-agent plugin not doing what the README says it does.
It now launches the `gpg-agent` executable (via `gpgconf --launch`) when
Zsh first starts up.

Also updated the README to explain what issues it fixes when the plugin
is enabled for better transparency about what the plugin actually does.

Signed-off-by: G'lek Tarssza <glek@glektarssza.com>
2025-09-04 11:25:51 -06:00

19 lines
753 B
Bash

# Launch gpg-agent ahead of time
gpgconf --launch gpg-agent
# 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 {
export GPG_TTY="${TTY}"
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 2>/dev/null | 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