Skip to content

Instantly share code, notes, and snippets.

@ichizok
Created December 14, 2023 07:07
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 ichizok/5f78a8bfe5bb4b7306ec06a1ef729910 to your computer and use it in GitHub Desktop.
Save ichizok/5f78a8bfe5bb4b7306ec06a1ef729910 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -eo pipefail
#
# Git invokes the following command with commit-data for code-signing.
#
# gpg --status-fd 2 -bsau {signing_key}
#
while getopts :u:-: OPT; do
# Skip long options.
[[ ${OPT} = - ]] \
&& ! [[ ${OPTARG} =~ = ]] \
&& ! [[ ${!OPTIND} =~ ^- ]] \
&& shift
[[ ${OPT} = u ]] && SIGNING_KEY=${OPTARG}
done
if [[ -z "${SIGNING_KEY}" ]]; then
# Probably to verify a signed commit.
exec gpg "$@"
exit 127
fi
exec 3<<<"$(pass show "gpg/${SIGNING_KEY%!}")"
exec gpg --batch --pinentry-mode loopback --passphrase-fd 3 "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment