Skip to content

Instantly share code, notes, and snippets.

@nawan95
Forked from mrgrain/pinentry-1password.sh
Last active July 1, 2025 07:15
Show Gist options
  • Select an option

  • Save nawan95/772746085df2ec073c20b242eb84a017 to your computer and use it in GitHub Desktop.

Select an option

Save nawan95/772746085df2ec073c20b242eb84a017 to your computer and use it in GitHub Desktop.
1Password CLI pinentry for gpg-agent
#!/bin/sh
get_pin() {
op read "$OP_PIN_ITEM"
}
echo "OK"
while read -r cmd rest; do
echo "cmd=$cmd rest=$rest" >&2
echo "cmd=$cmd rest=$rest" >> /tmp/logs
case "$cmd" in
\#*)
echo "OK"
;;
GETPIN)
# Use modern $(...) syntax which is safer than backticks ``
# This calls the function we defined above.
PASSPHRASE=${PASSPHRASE-$(get_pin)}
echo "D ${PASSPHRASE}"
echo "OK"
;;
BYE)
echo "OK"
exit 0
;;
*)
echo "OK"
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment