gpg-agent.plugin.zsh 736 Bytes
Newer Older
Florian Walch's avatar
Florian Walch committed
1
2
local GPG_ENV=$HOME/.gnupg/gpg-agent.env

3
function start_agent_nossh {
4
5
    eval $(/usr/bin/env gpg-agent --quiet --daemon --write-env-file ${GPG_ENV} 2> /dev/null)
    chmod 600 ${GPG_ENV}
6
7
8
9
    export GPG_AGENT_INFO
}

function start_agent_withssh {
10
11
    eval $(/usr/bin/env gpg-agent --quiet --daemon --enable-ssh-support --write-env-file ${GPG_ENV} 2> /dev/null)
    chmod 600 ${GPG_ENV}
12
13
14
    export GPG_AGENT_INFO
    export SSH_AUTH_SOCK
    export SSH_AGENT_PID
Florian Walch's avatar
Florian Walch committed
15
16
}

17
# source settings of old agent, if applicable
Florian Walch's avatar
Florian Walch committed
18
19
20
21
if [ -f "${GPG_ENV}" ]; then
  . ${GPG_ENV} > /dev/null
fi

22
23
24
25
26
27
# check for existing ssh-agent
if ssh-add -l > /dev/null 2> /dev/null; then
    start_agent_nossh;
else
    start_agent_withssh;
fi
Florian Walch's avatar
Florian Walch committed
28
29
30

GPG_TTY=$(tty)
export GPG_TTY