From a7ec0d3b3e49837c52051de489b118b650bb2bf0 Mon Sep 17 00:00:00 2001
From: Sam Chudnick <sam@chudnick.com>
Date: Wed, 5 Jan 2022 18:01:25 -0500
Subject: Prompt for KeePassXC password until correct one is given.

---
 .local/bin/id-init | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

(limited to '.local/bin/id-init')

diff --git a/.local/bin/id-init b/.local/bin/id-init
index d51660a..11221c3 100755
--- a/.local/bin/id-init
+++ b/.local/bin/id-init
@@ -12,9 +12,17 @@
 # gpg-preset-passphrase respects gpg-agent's --max-cache-ttl option which defaults to 2 hours
 # you may want to increase that if you want the password to be cached for the whole session
 
+get_pass() {
+	continue=1
+	while [ $continue -eq 1 ]
+	do
+		keepassxc-cli show $XDG_CONFIG_HOME/keepassxc/Passwords.kdbx -a Password GPG
+		continue=$?
+	done
+}
+
 KEYGRIP="$(gpg -K --with-keygrip --with-colons | grep grp | tail -n 1 | cut -d':' -f10)"
-/usr/lib/gnupg/gpg-preset-passphrase --preset $KEYGRIP \
-		<<< "$(keepassxc-cli show $XDG_CONFIG_HOME/keepassxc/Passwords.kdbx -a Password GPG)"
+/usr/lib/gnupg/gpg-preset-passphrase --preset $KEYGRIP <<< "$(get_pass)"
 
 # Open graphical KeePassXC with password stored in pass, now that pass can be accessed
 # without entering credentials for the GPG key
-- 
cgit v1.2.3