de1f803de92af360cf3ad7a984845d60eb9908c6
Author Robby Russell <robby@planetargon.com> Committer Robby Russell <robby@planetargon.com> Date 2013-04-24 03:37 UTC
Message Merge pull request #1620 from hreese/gpg-agent_with_sensible_ssh-agent
Disable ssh-agent support in gpg-agent-plugin if another ssh-agent is already available.
Diff 1 diff --git a/plugins/gpg-agent/gpg-agent.plugin.zsh b/plugins/gpg-agent/gpg-agent.plugin.zsh
2 index 8cc71fd57692de243e8a497786d1e1f8eb0b2bba..109af44c8d5d6be7d4ec47fdc6fe1e40cd8aeb58 100644
3 --- a/plugins/gpg-agent/gpg-agent.plugin.zsh
4 +++ b/plugins/gpg-agent/gpg-agent.plugin.zsh
5 @@ -1,26 +1,30 @@
6 -# Based on ssh-agent code
7 -
8 local GPG_ENV=$HOME/.gnupg/gpg-agent.env
9
10 -function start_agent {
11 - /usr/bin/env gpg-agent --daemon --enable-ssh-support --write-env-file ${GPG_ENV} > /dev/null
12 - chmod 600 ${GPG_ENV}
13 - . ${GPG_ENV} > /dev/null
14 +function start_agent_nossh {
15 + eval $(/usr/bin/env gpg-agent --quiet --daemon --write-env-file ${GPG_ENV} 2> /dev/null)
16 + chmod 600 ${GPG_ENV}
17 + export GPG_AGENT_INFO
18 +}
19 +
20 +function start_agent_withssh {
21 + eval $(/usr/bin/env gpg-agent --quiet --daemon --enable-ssh-support --write-env-file ${GPG_ENV} 2> /dev/null)
22 + chmod 600 ${GPG_ENV}
23 + export GPG_AGENT_INFO
24 + export SSH_AUTH_SOCK
25 + export SSH_AGENT_PID
26 }
27
28 -# Source GPG agent settings, if applicable
29 +# source settings of old agent, if applicable
30 if [ -f "${GPG_ENV}" ]; then
31 . ${GPG_ENV} > /dev/null
32 - ps -ef | grep ${SSH_AGENT_PID} | grep gpg-agent > /dev/null || {
33 - start_agent;
34 - }
35 -else
36 - start_agent;
37 fi
38
39 -export GPG_AGENT_INFO
40 -export SSH_AUTH_SOCK
41 -export SSH_AGENT_PID
42 +# check for existing ssh-agent
43 +if ssh-add -l > /dev/null 2> /dev/null; then
44 + start_agent_nossh;
45 +else
46 + start_agent_withssh;
47 +fi
48
49 GPG_TTY=$(tty)
50 export GPG_TTY