.zshrc: Use simpler GPG agent config

This commit is contained in:
Alan Orth 2017-06-07 12:17:01 +03:00
parent 8b1f4d6c33
commit a2e8eccb00
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9
2 changed files with 5 additions and 61 deletions

8
.zshrc
View File

@ -114,9 +114,11 @@ genpass() {
</dev/urandom tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' | 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

View File

@ -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