From 6e0343afab6eef47a25df774bffd1f29226ad2c0 Mon Sep 17 00:00:00 2001 From: Chris Fleming Date: Thu, 26 Apr 2018 17:16:51 +0100 Subject: [PATCH 1/3] z-style configuration for enabling ssh --- plugins/gpg-agent/gpg-agent.plugin.zsh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/gpg-agent/gpg-agent.plugin.zsh b/plugins/gpg-agent/gpg-agent.plugin.zsh index 6a94f598f..5a2b9acef 100644 --- a/plugins/gpg-agent/gpg-agent.plugin.zsh +++ b/plugins/gpg-agent/gpg-agent.plugin.zsh @@ -1,5 +1,6 @@ # Enable gpg-agent if it is not running- # --use-standard-socket will work from version 2 upwards +typeset _gpg_ssh_socket AGENT_SOCK=`gpgconf --list-dirs | grep agent-socket | cut -d : -f 2` @@ -8,9 +9,12 @@ if [ ! -S ${AGENT_SOCK} ]; then fi export GPG_TTY=$(tty) -# Set SSH to use gpg-agent if it's enabled -if [ -S "${AGENT_SOCK}.ssh" ]; then +# Set SSH to use gpg-agent if it's enabled, and we've set config +zstyle -b :omz:plugins:gpg-agent ssh-socket _gpg_ssh_socket + +if [[ $_gpg_ssh_socket == "yes" && -S "${AGENT_SOCK}.ssh" ]]; then export SSH_AUTH_SOCK="${AGENT_SOCK}.ssh" unset SSH_AGENT_PID fi +unset _gpg_ssh_socket From 39c230e9d160958c829dcfc9acb8b36c68d4398b Mon Sep 17 00:00:00 2001 From: Chris Fleming Date: Thu, 26 Apr 2018 17:20:26 +0100 Subject: [PATCH 2/3] Don't set SSH_AUTH_SOCK if the ssh-agent plugin is enabled --- plugins/gpg-agent/gpg-agent.plugin.zsh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/plugins/gpg-agent/gpg-agent.plugin.zsh b/plugins/gpg-agent/gpg-agent.plugin.zsh index 5a2b9acef..245a87c0d 100644 --- a/plugins/gpg-agent/gpg-agent.plugin.zsh +++ b/plugins/gpg-agent/gpg-agent.plugin.zsh @@ -1,7 +1,5 @@ # Enable gpg-agent if it is not running- # --use-standard-socket will work from version 2 upwards -typeset _gpg_ssh_socket - AGENT_SOCK=`gpgconf --list-dirs | grep agent-socket | cut -d : -f 2` if [ ! -S ${AGENT_SOCK} ]; then @@ -9,12 +7,10 @@ if [ ! -S ${AGENT_SOCK} ]; then fi export GPG_TTY=$(tty) -# Set SSH to use gpg-agent if it's enabled, and we've set config -zstyle -b :omz:plugins:gpg-agent ssh-socket _gpg_ssh_socket - -if [[ $_gpg_ssh_socket == "yes" && -S "${AGENT_SOCK}.ssh" ]]; then +# Set SSH to use gpg-agent if it's enabled, and we're not using the ssh-agent plugin +echo "$plugins" | fgrep -q "ssh-agent" +if [[ $? -eq 1 && -S "${AGENT_SOCK}.ssh" ]]; then export SSH_AUTH_SOCK="${AGENT_SOCK}.ssh" unset SSH_AGENT_PID fi -unset _gpg_ssh_socket From 61497a3dfda96ef33958cda9749be8b622d27cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 27 Apr 2018 17:02:29 +0200 Subject: [PATCH 3/3] Use idiomatic zsh and fix general style --- plugins/gpg-agent/gpg-agent.plugin.zsh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins/gpg-agent/gpg-agent.plugin.zsh b/plugins/gpg-agent/gpg-agent.plugin.zsh index 245a87c0d..093a546ce 100644 --- a/plugins/gpg-agent/gpg-agent.plugin.zsh +++ b/plugins/gpg-agent/gpg-agent.plugin.zsh @@ -1,16 +1,14 @@ # Enable gpg-agent if it is not running- # --use-standard-socket will work from version 2 upwards -AGENT_SOCK=`gpgconf --list-dirs | grep agent-socket | cut -d : -f 2` +AGENT_SOCK=$(gpgconf --list-dirs | grep agent-socket | cut -d : -f 2) -if [ ! -S ${AGENT_SOCK} ]; then - gpg-agent --daemon --use-standard-socket >/dev/null 2>&1 +if [[ ! -S "$AGENT_SOCK" }]; then + gpg-agent --daemon --use-standard-socket &>/dev/null fi -export GPG_TTY=$(tty) +export GPG_TTY=$TTY # Set SSH to use gpg-agent if it's enabled, and we're not using the ssh-agent plugin -echo "$plugins" | fgrep -q "ssh-agent" -if [[ $? -eq 1 && -S "${AGENT_SOCK}.ssh" ]]; then - export SSH_AUTH_SOCK="${AGENT_SOCK}.ssh" +if [[ ${+plugins[(r)ssh-agent} -ne 0 && -S "$AGENT_SOCK.ssh" ]]; then + export SSH_AUTH_SOCK="$AGENT_SOCK.ssh" unset SSH_AGENT_PID fi -