From e080999804d81c59a8e4b1a75cb7154d44d1cc97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81bastien=20HOUZE=CC=81?= Date: Wed, 20 Mar 2013 16:09:15 +0100 Subject: [PATCH] GPG_AGENT_HANDLE_SSH option added to specify if gpg-agent must replace ssh-agent or not. --- plugins/gpg-agent/gpg-agent.plugin.zsh | 33 ++++++++++++++++++-------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/plugins/gpg-agent/gpg-agent.plugin.zsh b/plugins/gpg-agent/gpg-agent.plugin.zsh index 8cc71fd57..87652fd09 100644 --- a/plugins/gpg-agent/gpg-agent.plugin.zsh +++ b/plugins/gpg-agent/gpg-agent.plugin.zsh @@ -3,24 +3,37 @@ local GPG_ENV=$HOME/.gnupg/gpg-agent.env function start_agent { - /usr/bin/env gpg-agent --daemon --enable-ssh-support --write-env-file ${GPG_ENV} > /dev/null - chmod 600 ${GPG_ENV} - . ${GPG_ENV} > /dev/null + if [ -n "${GPG_AGENT_HANDLE_SSH}" ] ; then + /usr/bin/env gpg-agent --daemon --enable-ssh-support --write-env-file ${GPG_ENV} > /dev/null + chmod 600 ${GPG_ENV} + else + /usr/bin/env gpg-agent --daemon --write-env-file ${GPG_ENV} > /dev/null + chmod 600 ${GPG_ENV} + fi + . ${GPG_ENV} > /dev/null } # Source GPG agent settings, if applicable if [ -f "${GPG_ENV}" ]; then - . ${GPG_ENV} > /dev/null - ps -ef | grep ${SSH_AGENT_PID} | grep gpg-agent > /dev/null || { - start_agent; - } + . ${GPG_ENV} > /dev/null + if [ -n "${GPG_AGENT_HANDLE_SSH}" ] ; then + if [ $(ps -ef | grep ${SSH_AGENT_PID} | grep -c gpg-agent) -eq 0 ] ; then + start_agent; + fi + else + if [ $(ps -ef | grep gpg-agent | grep -c daemon) -eq 0 ] ; then + start_agent; + fi + fi else - start_agent; + start_agent; fi export GPG_AGENT_INFO -export SSH_AUTH_SOCK -export SSH_AGENT_PID +if [ -n "${GPG_AGENT_HANDLE_SSH}" ] ; then + export SSH_AUTH_SOCK + export SSH_AGENT_PID +fi GPG_TTY=$(tty) export GPG_TTY