From d66a0998d4ff4584b1dd67f5e795e45d5c5fb429 Mon Sep 17 00:00:00 2001 From: Vonfry <3413119+Vonfry@users.noreply.github.com> Date: Sat, 26 Jan 2019 11:00:37 +0800 Subject: [PATCH] Fix gpg module condition Fix gpg module grep regex expression, because of matching failed when `GPG_AGENT_INFO` is empty. And use gpgconf to get socket file instead of `$GNUPGHOME`. fix: sorin-ionescu/prezto#1681 --- modules/gpg/init.zsh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/gpg/init.zsh b/modules/gpg/init.zsh index 7976fd7d..60d59820 100644 --- a/modules/gpg/init.zsh +++ b/modules/gpg/init.zsh @@ -13,14 +13,16 @@ fi # Set the default paths to gpg-agent files. _gpg_agent_conf="${GNUPGHOME:-$HOME/.gnupg}/gpg-agent.conf" _gpg_agent_env="${TMPDIR:-/tmp}/gpg-agent.env.$UID" +_gpg_agent_socket="$(gpgconf --list-dir | grep "agent-socket:.*" | sed "s/agent-socket://")" # Load environment variables from previous run source "$_gpg_agent_env" 2> /dev/null + # Start gpg-agent if not started. -if [[ -z "$GPG_AGENT_INFO" && ! -S "${GNUPGHOME:-$HOME/.gnupg}/S.gpg-agent" ]]; then +if [[ -z "$GPG_AGENT_INFO" && ! -S ${_gpg_agent_socket}" ]]; then # Start gpg-agent if not started. - if ! ps -U "$LOGNAME" -o pid,ucomm | grep -q -- "${${${(s.:.)GPG_AGENT_INFO}[2]}:--1} gpg-agent"; then + if ! ps -U "$LOGNAME" -o pid,ucomm | grep -q -- "^[0-9]* gpg-agent$"; then eval "$(gpg-agent --daemon | tee "$_gpg_agent_env")" fi fi