Created
June 22, 2022 14:58
-
-
Save ormaaj/292a0616d275c6db3ace265202f69f0d to your computer and use it in GitHub Desktop.
run gpg-agent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setupGpgAgent { | |
# gpg-agent uses .gnupg but will not create the directory itself for new users. | |
if ! { [[ -d ~/.gnupg ]] || mkdir -p -- ~/.gnupg; }; then | |
printf 'bashrc: %s\n' 'No ~/.gnupg directory exists and failed to create it.' >&2 | |
return 0 | |
fi | |
if [[ -t 0 ]] && { GPG_TTY=$(readlink -sne /dev/fd/0) || GPG_TTY=$(tty); }; then | |
export GPG_TTY | |
else | |
unset -v GPG_TTY | |
fi | |
if shopt -q login_shell && gpg-connect-agent /bye 2>/dev/null; then | |
unset -v SSH_AGENT_PID | |
if [[ -d $XDG_RUNTIME_DIR && -S ${XDG_RUNTIME_DIR}/gnupg/S.gpg-agent ]]; then | |
typeset sock=${XDG_RUNTIME_DIR}/gnupg/S.gpg-agent.ssh | |
else | |
typeset sock=~/.gnupg/S.gpg-agent.ssh | |
fi | |
[[ ${BASHPID:-$$} != "${gnupg_SSH_AUTH_SOCK_by}" && -S $sock ]] && | |
typeset -gx SSH_AUTH_SOCK=$sock | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment