From f1371526ad4510505f372b377a993e1c4f6badd3 Mon Sep 17 00:00:00 2001 From: neersighted Date: Mon, 21 Jan 2013 17:35:59 -0800 Subject: [PATCH] Use $GNUPGHOME in GPG agent startup 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. --- modules/gpg-agent/init.zsh | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 modules/gpg-agent/init.zsh diff --git a/modules/gpg-agent/init.zsh b/modules/gpg-agent/init.zsh new file mode 100644 index 0000000000..82bd9a2ec4 --- /dev/null +++ b/modules/gpg-agent/init.zsh @@ -0,0 +1,46 @@ +# +# Provides for an easier use of gpg-agent. +# +# Authors: +# Florian Walch +# Sorin Ionescu +# neersighted +# + +# 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)"