Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Created June 22, 2022 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ormaaj/292a0616d275c6db3ace265202f69f0d to your computer and use it in GitHub Desktop.
Save ormaaj/292a0616d275c6db3ace265202f69f0d to your computer and use it in GitHub Desktop.
run gpg-agent
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