From 407ad0473f2a8d21784dd98d597883558a466891 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 24 Sep 2020 10:00:47 +0200 Subject: [PATCH] mail: Fix mail-check hooks Fixed running the hooks for `mail-check`. Command (or variable?) substition prevented the hooks from running completely beforehand, so I moved them to a separate function with the option remaining to call a custom script for them through environment variables. Ideally the env vars (`MBSYNC_PRE` and `MBSYNC_POST`) should only point to a single script each, as more involved commands will presumably fail to execute correctly when whitespace substition is involved. See more explanation here: https://unix.stackexchange.com/a/444949 --- mail/.local/bin/mail-check | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/mail/.local/bin/mail-check b/mail/.local/bin/mail-check index fc90d16..abea83b 100755 --- a/mail/.local/bin/mail-check +++ b/mail/.local/bin/mail-check @@ -12,8 +12,23 @@ # https://sourceforge.net/p/isync/feature-requests/8/ MBSYNC_MAX_TRIES=3 -MBSYNC_PRE="imapfilter -c /home/marty/.config/imapfilter/config.lua" -MBSYNC_POST="notmuch new && afew --tag --new" + +prehook() { + if [ -n "$MBSYNC_PRE" ]; then + eval "$MBSYNC_PRE" + return 0 + fi + imapfilter -c "${XDG_CONFIG_HOME:-/home/marty/.config}/imapfilter/config.lua" +} + +posthook() { + if [ -n "$MBSYNC_POST" ]; then + eval "$MBSYNC_POST" + return 0 + fi + notmuch new --quiet 2>/dev/null + afew --tag --new +} # fail the routine and optionally send a message why fail() { @@ -41,7 +56,7 @@ if [ "$1" = "raw" ]; then fi main() { - $MBSYNC_PRE + prehook tries=0 while true; do @@ -56,7 +71,7 @@ main() { done unset tries - $MBSYNC_POST + posthook } notmuch_foldertags() {