aboutsummaryrefslogtreecommitdiffstats
path: root/modules/communication/neomutt/neomutt-sync-daemon.sh
diff options
context:
space:
mode:
authorArpit Chakladar <arpit@chakladar.me>2026-09-30 03:06:49 +0530
committerArpit Chakladar <arpit@chakladar.me>2026-09-30 03:08:51 +0530
commitfe64e34d2451e33623632c4a4ee216101d18dcc5 (patch)
treee98daa1e2aa2cbc7f5a2008bb4151bf2839f0ee5 /modules/communication/neomutt/neomutt-sync-daemon.sh
parentb7391ff5f0254c9bbfd43b8952f31fd147a2ffdc (diff)
downloadhome-manager-config-fe64e34d2451e33623632c4a4ee216101d18dcc5.tar.gz
home-manager-config-fe64e34d2451e33623632c4a4ee216101d18dcc5.zip
chore(communication/neomutt): simplified the sync and sync daemon scripts
Diffstat (limited to 'modules/communication/neomutt/neomutt-sync-daemon.sh')
-rw-r--r--modules/communication/neomutt/neomutt-sync-daemon.sh42
1 files changed, 24 insertions, 18 deletions
diff --git a/modules/communication/neomutt/neomutt-sync-daemon.sh b/modules/communication/neomutt/neomutt-sync-daemon.sh
index 301eb98..d5eea63 100644
--- a/modules/communication/neomutt/neomutt-sync-daemon.sh
+++ b/modules/communication/neomutt/neomutt-sync-daemon.sh
@@ -1,22 +1,27 @@
#!/usr/bin/env bash
-# systemd daemon: sync quick channels on first run, then full channels every 10 minutes
-# while neomutt is open. Started/stopped by the wrapped neomutt launcher.
+# systemd daemon: sync quick groups on first run, then full groups every 5
+# minutes while neomutt is open. Started/stopped by the wrapped neomutt
+# launcher.
set -uo pipefail
-INTERVAL="$((10 * 60))"
-MBSYNCRC="${MBSYNCRC:-$HOME/.config/mbsync/.mbsyncrc}"
+# Comma-separated group names, substituted at build time
+QUICK_GROUPS="@@QUICK_GROUPS@@"
+FULL_GROUPS="@@FULL_GROUPS@@"
-QUICK_CHANNELS_STR="@@QUICK_CHANNELS@@"
-FULL_CHANNELS_STR="@@FULL_CHANNELS@@"
+INTERVAL="$((5 * 60))"
-IFS=',' read -ra QUICK_CHANNELS <<<"$QUICK_CHANNELS_STR"
-IFS=',' read -ra FULL_CHANNELS <<<"$FULL_CHANNELS_STR"
+IFS=',' read -ra QUICK <<<"$QUICK_GROUPS"
+IFS=',' read -ra FULL <<<"$FULL_GROUPS"
-sync_once() {
- echo "Syncing: $*"
+# sync_groups <group>...: sync the given mbsync groups, then index
+sync_groups() {
+ if (($# == 0)); then
+ return 0
+ fi
- mbsync -c "$MBSYNCRC" "$@"
+ echo "Syncing: $*"
+ mbsync "$@"
local status=$?
if ((status != 0)); then
echo "mbsync failed (status $status) for: $*" >&2
@@ -24,19 +29,20 @@ sync_once() {
fi
echo "Indexing new mail with notmuch..."
- notmuch new --quiet
+ notmuch new
}
-first_run=true
+first=true
while true; do
- if [[ $first_run == true ]]; then
- sync_once "${QUICK_CHANNELS[@]}"
- first_run=false
- else
- sync_once "${FULL_CHANNELS[@]}"
+ if $first; then
+ # Quick pass first so new mail shows up before the slower full sync
+ sync_groups "${QUICK[@]}"
+ first=false
fi
+ sync_groups "${FULL[@]}"
+
# Safety net: the launcher stops this service when neomutt exits; if that
# didn't happen (hard kill), bail out once neomutt is gone.
if ! pgrep -x neomutt-launche >/dev/null; then