diff --git a/modules/gpg/init.zsh b/modules/gpg/init.zsh index cb78495..a99f7cb 100644 --- a/modules/gpg/init.zsh +++ b/modules/gpg/init.zsh @@ -15,11 +15,14 @@ _gpg_agent_conf="$HOME/.gnupg/gpg-agent.conf" _gpg_agent_env="${TMPDIR:-/tmp}/gpg-agent.env" # Start gpg-agent if not started. -if ! ps -U "$USER" -o pid,ucomm | grep -q -- "${GPG_AGENT_PID:--1} gpg-agent"; then - eval "$(gpg-agent --daemon | tee "$_gpg_agent_env")" -else +if [[ -z "$GPG_AGENT_INFO" ]]; then # Export environment variables. source "$_gpg_agent_env" 2> /dev/null + + # Start gpg-agent if not started. + if ! ps -U "$USER" -o pid,ucomm | grep -q -- "${${${(s.:.)GPG_AGENT_INFO}[2]}:--1} gpg-agent"; then + eval "$(gpg-agent --daemon | tee "$_gpg_agent_env")" + fi fi # Inform gpg-agent of the current TTY for user prompts.