diff options
Diffstat (limited to 'plugins/gpg-agent')
-rw-r--r-- | plugins/gpg-agent/README.md | 8 | ||||
-rw-r--r-- | plugins/gpg-agent/gpg-agent.plugin.zsh | 20 |
2 files changed, 19 insertions, 9 deletions
diff --git a/plugins/gpg-agent/README.md b/plugins/gpg-agent/README.md new file mode 100644 index 000000000..a9711f923 --- /dev/null +++ b/plugins/gpg-agent/README.md @@ -0,0 +1,8 @@ +# gpg-agent + +Enables [GPG's gpg-agent](https://www.gnupg.org/documentation/manuals/gnupg/) if it is not running. + +To use it, add gpg-agent to the plugins array of your zshrc file: +``` +plugins=(... gpg-agent) +``` diff --git a/plugins/gpg-agent/gpg-agent.plugin.zsh b/plugins/gpg-agent/gpg-agent.plugin.zsh index 69e239ccf..3e24c2527 100644 --- a/plugins/gpg-agent/gpg-agent.plugin.zsh +++ b/plugins/gpg-agent/gpg-agent.plugin.zsh @@ -1,14 +1,16 @@ -# Enable gpg-agent if it is not running -GPG_AGENT_SOCKET="${XDG_RUNTIME_DIR}/gnupg/S.gpg-agent.ssh" -if [ ! -S $GPG_AGENT_SOCKET ]; then - gpg-agent --daemon >/dev/null 2>&1 - export GPG_TTY=$(tty) +# 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) + +if [[ ! -S $AGENT_SOCK ]]; then + gpg-agent --daemon --use-standard-socket &>/dev/null fi +export GPG_TTY=$TTY -# Set SSH to use gpg-agent if it is configured to do so +# Set SSH to use gpg-agent if it's enabled GNUPGCONFIG="${GNUPGHOME:-"$HOME/.gnupg"}/gpg-agent.conf" -if [ -r "$GNUPGCONFIG" ] && grep -q enable-ssh-support "$GNUPGCONFIG"; then +if [[ -r $GNUPGCONFIG ]] && command grep -q enable-ssh-support "$GNUPGCONFIG"; then + export SSH_AUTH_SOCK="$AGENT_SOCK.ssh" unset SSH_AGENT_PID - export SSH_AUTH_SOCK=$GPG_AGENT_SOCKET fi - |