diff options
| author | Arpit Chakladar <arpit@chakladar.me> | 2026-09-30 03:06:49 +0530 |
|---|---|---|
| committer | Arpit Chakladar <arpit@chakladar.me> | 2026-09-30 03:08:51 +0530 |
| commit | fe64e34d2451e33623632c4a4ee216101d18dcc5 (patch) | |
| tree | e98daa1e2aa2cbc7f5a2008bb4151bf2839f0ee5 | |
| parent | b7391ff5f0254c9bbfd43b8952f31fd147a2ffdc (diff) | |
| download | home-manager-config-fe64e34d2451e33623632c4a4ee216101d18dcc5.tar.gz home-manager-config-fe64e34d2451e33623632c4a4ee216101d18dcc5.zip | |
chore(communication/neomutt): simplified the sync and sync daemon scripts
| -rw-r--r-- | modules/communication/neomutt/default.nix | 10 | ||||
| -rw-r--r-- | modules/communication/neomutt/neomutt-launcher.sh | 2 | ||||
| -rw-r--r-- | modules/communication/neomutt/neomutt-sync-daemon.sh | 42 | ||||
| -rw-r--r-- | modules/communication/neomutt/neomutt-sync.sh | 102 |
4 files changed, 29 insertions, 127 deletions
diff --git a/modules/communication/neomutt/default.nix b/modules/communication/neomutt/default.nix index e8915d9..6189b23 100644 --- a/modules/communication/neomutt/default.nix +++ b/modules/communication/neomutt/default.nix @@ -64,15 +64,7 @@ let pkgs.neomutt pkgs.urlscan ]; - text = - builtins.replaceStrings - [ - "@@NEOMUTT_BIN@@" - ] - [ - (lib.getExe pkgs.neomutt) - ] - (builtins.readFile ./neomutt-launcher.sh); + text = builtins.readFile ./neomutt-launcher.sh; }; neomuttSyncCompletion = diff --git a/modules/communication/neomutt/neomutt-launcher.sh b/modules/communication/neomutt/neomutt-launcher.sh index c13677f..dfc7672 100644 --- a/modules/communication/neomutt/neomutt-launcher.sh +++ b/modules/communication/neomutt/neomutt-launcher.sh @@ -4,4 +4,4 @@ set -uo pipefail systemctl --user start neomutt-sync.service || true -"@@NEOMUTT_BIN@@" "$@" +neomutt "$@" 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 diff --git a/modules/communication/neomutt/neomutt-sync.sh b/modules/communication/neomutt/neomutt-sync.sh index 6ecb14e..f41f0e7 100644 --- a/modules/communication/neomutt/neomutt-sync.sh +++ b/modules/communication/neomutt/neomutt-sync.sh @@ -3,103 +3,7 @@ set -uo pipefail -MBSYNCRC="${MBSYNCRC:-$HOME/.config/mbsync/.mbsyncrc}" -TITLE="[ SYNCING MAIL]" +CHANNEL_GROUP="$1" -DIALOGRC=$(mktemp) -MBSYNC_LOG=$(mktemp) -NOTMUCH_LOG=$(mktemp) - -export DIALOGRC - -trap 'rm -f "$DIALOGRC" "$MBSYNC_LOG" "$NOTMUCH_LOG"' EXIT - -if [[ $# -ne 1 ]]; then - echo "Usage: $0 <mbsync-channel>" - echo - echo "Example:" - echo " $0 arpitchakladar-gmail_com-quick" - echo " $0 arpitchakladar-gmail_com-full" - exit 2 -fi - -CHANNEL="$1" - -cat <<'EOF' >"$DIALOGRC" -use_shadow = ON -use_colors = ON -screen_color = (WHITE,BLACK,OFF) -dialog_color = (WHITE,BLACK,ON) -title_color = (YELLOW,BLACK,ON) -gauge_color = (GREEN,BLACK,ON) -border_color = (CYAN,BLACK,ON) -border2_color = (BLUE,BLACK,ON) -shadow_color = (BLACK,BLACK,ON) - -button_active_color = (MAGENTA,BLACK,ON) -button_key_active_color = (MAGENTA,BLACK,ON) -button_label_active_color = (MAGENTA,BLACK,ON) - -button_inactive_color = (CYAN,BLACK,OFF) -button_key_inactive_color = (CYAN,BLACK,OFF) -button_label_inactive_color = (CYAN,BLACK,OFF) -EOF - -( - printf "XXX\n0\nSyncing: %s...\nXXX\n" "$CHANNEL" - - mbsync -c "$MBSYNCRC" "$CHANNEL" >"$MBSYNC_LOG" 2>&1 & - PID=$! - - # Keep the gauge alive while mbsync runs. - while kill -0 "$PID" 2>/dev/null; do - printf "XXX\n50\nSyncing: %s...\nXXX\n" "$CHANNEL" - sleep 0.5 - done - - wait "$PID" - MBSYNC_STATUS=$? - - if ((MBSYNC_STATUS != 0)); then - printf "XXX\n100\nSync failed: %s\nXXX\n" "$CHANNEL" - exit "$MBSYNC_STATUS" - fi - - printf "XXX\n90\nIndexing new mail with notmuch...\nXXX\n" - - notmuch new --quiet >"$NOTMUCH_LOG" 2>&1 - NOTMUCH_STATUS=$? - - printf "XXX\n100\nDone.\nXXX\n" - - if ((NOTMUCH_STATUS != 0)); then - exit "$NOTMUCH_STATUS" - fi -) | dialog --title "$TITLE" --gauge "Initializing..." 8 80 0 - -STATUS=${PIPESTATUS[0]} - -MBSYNC_OUT=$( - tr '\n' ' ' <"$MBSYNC_LOG" | - sed 's/ */ /g' -) - -NOTMUCH_OUT=$( - tr '\n' ' ' <"$NOTMUCH_LOG" | - sed 's/ */ /g' -) - -if ((STATUS == 0)); then - dialog \ - --title "$TITLE" \ - --msgbox "Done!\n\nChannel: $CHANNEL\n\nmbsync: ${MBSYNC_OUT:-OK}\n\nnotmuch: ${NOTMUCH_OUT:-OK}" \ - 12 80 -else - dialog \ - --title "$TITLE" \ - --msgbox "Sync failed!\n\nChannel: $CHANNEL\n\nmbsync: ${MBSYNC_OUT:-no output}\n\nnotmuch: ${NOTMUCH_OUT:-not run}" \ - 12 80 -fi - -clear -exit "$STATUS" +mbsync "$CHANNEL_GROUP" +notmuch new |
