Skip to content

Commit

Permalink
Use $GNUPGHOME in GPG agent startup
Browse files Browse the repository at this point in the history
Use the value of $GNUPGHOME, to facilitate moving GPG's home.

This lets users who keep their GPG keyring on external devices or alternate
folders use the gpg-agent autostarting, even if $HOME/.gnupg does not exist.
  • Loading branch information
neersighted authored and Adam Walz committed Jul 2, 2013
1 parent b7f0853 commit f137152
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions modules/gpg-agent/init.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Provides for an easier use of gpg-agent.
#
# Authors:
# Florian Walch <[email protected]>
# Sorin Ionescu <[email protected]>
# neersighted <[email protected]>
#

# Return if requirements are not found.
if (( ! $+commands[gpg-agent] )); then
return 1
fi

# Make sure to use the $GNUPGHOME first.
_gpg_env="${GNUPGHOME:-$HOME/.gnupg}/gpg-agent.env"

function _gpg-agent-start {
local ssh_support

zstyle -b ':prezto:module:gpg-agent' ssh-support 'ssh_support' \
|| ssh_support=''

gpg-agent \
--daemon \
${ssh_support:+'--enable-ssh-support'} \
--write-env-file "${_gpg_env}" > /dev/null

chmod 600 "${_gpg_env}"
source "${_gpg_env}" > /dev/null
}

# Source GPG agent settings, if applicable.
if [[ -s "${_gpg_env}" ]]; then
source "${_gpg_env}" > /dev/null
ps -ef | grep "${SSH_AGENT_PID}" | grep -q 'gpg-agent' || {
_gpg-agent-start
}
else
_gpg-agent-start
fi

export GPG_AGENT_INFO
export SSH_AUTH_SOCK
export SSH_AGENT_PID
export GPG_TTY="$(tty)"

0 comments on commit f137152

Please sign in to comment.