commit b6f4daaa4784e65978ee39f6260810d5d46a3593
parent a9375e7f0f20b44edab6cb1295cf4a95d7b720c0
Author: Matthew Carlson <matt@mcarlson.xyz>
Date: Mon, 10 Jan 2022 18:01:23 -0500
kill gpg agent when fetching mail if key is not cached
Diffstat:
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/.local/bin/bar/mail.sh b/.local/bin/bar/mail.sh
@@ -18,13 +18,19 @@ get_mail() {
printf '%s\n' "${GET_ICON}" > "${TMP}"
mbsync -c "${ISYNCRC}" -aq
rm -f "${TMP}"
+
+ # check if gpg key is cached
+ cached=$(gpg-connect-agent 'keyinfo --list' /bye 2>/dev/null | awk 'BEGIN { CACHED=0 } /^S/ { if ($7==1) { CACHED=1 } } END { if ($0 != "") { print CACHED } else { print "none" } }')
+
+ # kill gpg agent if not cached; else user wont be able to enter key later
+ [ "${cached}" -eq 0 ] && gpgconf --kill gpg-agent
}
open() {
wd="$(pwd)"
- cd "${DOWNLOADS_DIR}";
+ cd "${DOWNLOADS_DIR}" || return 1
"${TERMINAL}" -c "${MAIL_CLIENT}" -e "${MAIL_CLIENT}"
- cd "${wd}"
+ cd "${wd}" || return 1
get_mail &
}
@@ -38,6 +44,7 @@ bar() {
[ -f "${TMP}" ] && printf '%s\n' "${GET_ICON}" && return
# if mail open show just mail icon
+ #shellcheck disable=SC2009
if ps -ef | grep -i "\<${MAIL_CLIENT}\>" | grep -iqv '\<grep\>'; then printf '%s\n' "${ICON}"
# otherwise print both icon and count
else printf '%s\n' "${ICON} ${total_mail_count}"