From d35846083feb766aaedee507ed939c66fe4ea76f Mon Sep 17 00:00:00 2001 From: Marvin Frommhold Date: Fri, 2 Sep 2016 11:45:58 +0200 Subject: [PATCH] always source settings of old agent, if applicable Fixes the problem that the `GPG_AGENT_INFO` environment variable is only exported, if no `gpg-agent` instance is already running. --- plugins/gpg-agent/gpg-agent.plugin.zsh | 32 ++++++++++++-------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/plugins/gpg-agent/gpg-agent.plugin.zsh b/plugins/gpg-agent/gpg-agent.plugin.zsh index 3e6a34f42..841f8e3cc 100644 --- a/plugins/gpg-agent/gpg-agent.plugin.zsh +++ b/plugins/gpg-agent/gpg-agent.plugin.zsh @@ -14,26 +14,24 @@ function start_agent_withssh { export SSH_AGENT_PID } +# source settings of old agent, if applicable +if [ -f "${GPG_ENV}" ]; then + . ${GPG_ENV} > /dev/null + export GPG_AGENT_INFO + export SSH_AUTH_SOCK + export SSH_AGENT_PID +fi + # check if another agent is running if ! gpg-connect-agent --quiet /bye > /dev/null 2> /dev/null; then - # source settings of old agent, if applicable - if [ -f "${GPG_ENV}" ]; then - . ${GPG_ENV} > /dev/null - export GPG_AGENT_INFO - export SSH_AUTH_SOCK - export SSH_AGENT_PID - fi - # check again if another agent is running using the newly sourced settings - if ! gpg-connect-agent --quiet /bye > /dev/null 2> /dev/null; then - # check for existing ssh-agent - if ssh-add -l > /dev/null 2> /dev/null; then - # ssh-agent running, start gpg-agent without ssh support - start_agent_nossh; - else - # otherwise start gpg-agent with ssh support - start_agent_withssh; - fi + # check for existing ssh-agent + if ssh-add -l > /dev/null 2> /dev/null; then + # ssh-agent running, start gpg-agent without ssh support + start_agent_nossh; + else + # otherwise start gpg-agent with ssh support + start_agent_withssh; fi fi