diff --git a/.zshrc b/.zshrc index d321760..3c0dc34 100644 --- a/.zshrc +++ b/.zshrc @@ -114,9 +114,11 @@ genpass() { ?@[\]^_`{|}~' | head -c 15 ; echo } -# Activate GPG agent and cache the password after first use -# See: https://github.com/axtl/gpg-agent.zsh -source ~/src/git/dotfiles/gpg-agent.plugin.zsh +# set GPG TTY +export GPG_TTY=$(tty) +# +# Refresh gpg-agent tty in case user switches into an X Session +gpg-connect-agent updatestartuptty /bye >/dev/null export PATH export MANPATH diff --git a/gpg-agent.plugin.zsh b/gpg-agent.plugin.zsh deleted file mode 100644 index 8446150..0000000 --- a/gpg-agent.plugin.zsh +++ /dev/null @@ -1,58 +0,0 @@ -local GPG_DIR="${HOME}/.gnupg" -local GPG_ENV="${GPG_DIR}/gpg-agent.env" -local SSH_SOCK="" -local GPG_SOCK="" - -if [[ ! -z "${SSH_AUTH_SOCK}" ]] -then - SSH_SOCK="${GPG_DIR}/$(basename ${SSH_AUTH_SOCK})" -fi - -if [[ ! -z "${GPG_AGENT_INFO}" ]] -then - GPG_SOCK="${GPG_DIR}/$(basename ${GPG_AGENT_INFO} | cut -d : -f1)" -fi - -function _gpg_agent_start() { - emulate -L zsh - if [[ ! ( -f "${GPG_ENV}" && -S "${SSH_SOCK}" && -S "${GPG_SOCK}" ) ]]; then - _gpg_agent_clean - # start and source the script - eval "$(/usr/bin/env gpg-agent \ - --quiet \ - --daemon \ - --enable-ssh-support \ - --use-standard-socket \ - --write-env-file ${GPG_ENV} \ - 2> /dev/null)" - chmod 600 "${GPG_ENV}" - fi - - source "${GPG_ENV}" 2> /dev/null - - export GPG_AGENT_INFO - export SSH_AUTH_SOCK - export SSH_AGENT_PID - - GPG_TTY=$(tty) - export GPG_TTY -} - -function _gpg_agent_reset() { - emulate -L zsh - _gpg_agent_clean - _gpg_agent_start -} - -function _gpg_agent_clean () { - emulate -L zsh - # clear possibly stale things - rm "${SSH_SOCK}" 2> /dev/null - rm "${GPG_SOCK}" 2> /dev/null - rm "${GPG_ENV}" 2> /dev/null - killall -9 gpg-agent 2> /dev/null - killall -9 ssh-agent 2> /dev/null -} - - -_gpg_agent_start