diff options
| author | Arpit Chakladar <arpitchakladar@gmail.com> | 2026-09-24 05:06:49 +0530 |
|---|---|---|
| committer | Arpit Chakladar <arpitchakladar@gmail.com> | 2026-09-24 05:06:49 +0530 |
| commit | a0213d48a3fea3b2209c36390331de101fb7575f (patch) | |
| tree | 57f31b37ec4f2d0b4a109c53db61393d05d9cb1a /modules/communication/neomutt/neomutt-sync-daemon.sh | |
| parent | 3a6e45ad18c519b21c9cadb2d374148647886b05 (diff) | |
| parent | c37c4a69fc895099109fc5211bf9449592ebc518 (diff) | |
| download | home-manager-config-a0213d48a3fea3b2209c36390331de101fb7575f.tar.gz home-manager-config-a0213d48a3fea3b2209c36390331de101fb7575f.zip | |
Merge branch 'neomutt-autosyncing-daemon'
Diffstat (limited to 'modules/communication/neomutt/neomutt-sync-daemon.sh')
| -rw-r--r-- | modules/communication/neomutt/neomutt-sync-daemon.sh | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/modules/communication/neomutt/neomutt-sync-daemon.sh b/modules/communication/neomutt/neomutt-sync-daemon.sh new file mode 100644 index 0000000..a78ef5f --- /dev/null +++ b/modules/communication/neomutt/neomutt-sync-daemon.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# systemd daemon: full-sync the -full channels every 10 minutes while +# neomutt is open. Started/stopped by the wrapped neomutt launcher. + +set -uo pipefail + +INTERVAL="$((10 * 60))" +MBSYNCRC="${MBSYNCRC:-$HOME/.config/mbsync/.mbsyncrc}" + +if [[ $# -eq 0 ]]; then + echo "Usage: $0 <mbsync-channel> [channel...]" >&2 + exit 2 +fi + +sync_once() { + echo "Syncing: $*" + + mbsync -c "$MBSYNCRC" "$@" + local status=$? + if ((status != 0)); then + echo "mbsync failed (status $status) for: $*" >&2 + return "$status" + fi + + echo "Indexing new mail with notmuch..." + notmuch new --quiet +} + +while true; do + sync_once "$@" + sleep "$INTERVAL" + + # 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 >/dev/null; then + echo "neomutt is not running; stopping sync daemon" >&2 + exit 0 + fi +done |
