2012-02-01 04:37:51 +00:00
|
|
|
#
|
|
|
|
# Provides for an easier use of gpg-agent.
|
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Florian Walch <florian.walch@gmx.at>
|
|
|
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
2013-01-22 01:35:59 +00:00
|
|
|
# neersighted <neersighted@myopera.com>
|
2012-02-01 04:37:51 +00:00
|
|
|
#
|
2010-10-15 14:50:39 +00:00
|
|
|
|
2012-07-23 19:00:44 +00:00
|
|
|
# Return if requirements are not found.
|
2011-08-31 03:16:15 +00:00
|
|
|
if (( ! $+commands[gpg-agent] )); then
|
2012-03-28 16:19:53 +00:00
|
|
|
return 1
|
2011-08-31 03:16:15 +00:00
|
|
|
fi
|
|
|
|
|
2013-01-22 01:35:59 +00:00
|
|
|
# Make sure to use the $GNUPGHOME first.
|
|
|
|
_gpg_env="${GNUPGHOME:-$HOME/.gnupg}/gpg-agent.env"
|
2012-03-09 02:51:42 +00:00
|
|
|
|
2012-03-23 18:57:51 +00:00
|
|
|
function _gpg-agent-start {
|
2012-09-30 21:19:34 +00:00
|
|
|
local ssh_support
|
|
|
|
|
|
|
|
zstyle -b ':prezto:module:gpg-agent' ssh-support 'ssh_support' \
|
|
|
|
|| ssh_support=''
|
|
|
|
|
|
|
|
gpg-agent \
|
2013-01-22 01:35:59 +00:00
|
|
|
--daemon \
|
|
|
|
${ssh_support:+'--enable-ssh-support'} \
|
2012-09-30 21:19:34 +00:00
|
|
|
--write-env-file "${_gpg_env}" > /dev/null
|
|
|
|
|
2012-03-07 17:01:05 +00:00
|
|
|
chmod 600 "${_gpg_env}"
|
2012-03-07 23:05:01 +00:00
|
|
|
source "${_gpg_env}" > /dev/null
|
2010-10-15 14:50:39 +00:00
|
|
|
}
|
|
|
|
|
2011-08-31 03:16:15 +00:00
|
|
|
# Source GPG agent settings, if applicable.
|
2012-04-16 18:21:29 +00:00
|
|
|
if [[ -s "${_gpg_env}" ]]; then
|
2012-03-07 23:05:01 +00:00
|
|
|
source "${_gpg_env}" > /dev/null
|
2012-03-07 17:01:05 +00:00
|
|
|
ps -ef | grep "${SSH_AGENT_PID}" | grep -q 'gpg-agent' || {
|
2012-02-01 04:42:01 +00:00
|
|
|
_gpg-agent-start
|
2010-10-15 14:50:39 +00:00
|
|
|
}
|
|
|
|
else
|
2012-02-01 04:42:01 +00:00
|
|
|
_gpg-agent-start
|
2010-10-15 14:50:39 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
export GPG_AGENT_INFO
|
|
|
|
export SSH_AUTH_SOCK
|
|
|
|
export SSH_AGENT_PID
|
2012-02-01 04:42:01 +00:00
|
|
|
export GPG_TTY="$(tty)"
|