diff options
| author | Arpit Chakladar <arpitchakladar@gmail.com> | 2026-09-27 04:16:50 +0530 |
|---|---|---|
| committer | Arpit Chakladar <arpitchakladar@gmail.com> | 2026-09-27 04:16:50 +0530 |
| commit | 0981b6c089b483b4ecddceeffe89ed3f38561fb2 (patch) | |
| tree | 9b947b3a6840d26d7a95a5fbee46afaf488a505a | |
| parent | 80c2906ed127b9f5024d7c8b8f8aa663a5eb4c31 (diff) | |
| download | home-manager-config-0981b6c089b483b4ecddceeffe89ed3f38561fb2.tar.gz home-manager-config-0981b6c089b483b4ecddceeffe89ed3f38561fb2.zip | |
feat(communication/neomutt): the first sync after opening neomutt is quick
| -rw-r--r-- | modules/communication/neomutt/default.nix | 18 | ||||
| -rw-r--r-- | modules/communication/neomutt/neomutt-sync-daemon.sh | 22 |
2 files changed, 31 insertions, 9 deletions
diff --git a/modules/communication/neomutt/default.nix b/modules/communication/neomutt/default.nix index 6c11b03..e8915d9 100644 --- a/modules/communication/neomutt/default.nix +++ b/modules/communication/neomutt/default.nix @@ -15,6 +15,10 @@ let lib.filterAttrs (name: account: account.enable) cfg.accounts ); + quickSyncChannels = lib.mapAttrsToList (name: account: (mbsyncNamesFromName name).channels.quick) ( + lib.filterAttrs (name: account: account.enable) cfg.accounts + ); + neomuttSyncScript = pkgs.writeShellApplication { name = "neomutt-sync"; runtimeInputs = [ @@ -39,7 +43,17 @@ let config.programs.mbsync.package config.programs.notmuch.package ]; - text = builtins.readFile ./neomutt-sync-daemon.sh; + text = + builtins.replaceStrings + [ + "@@QUICK_CHANNELS@@" + "@@FULL_CHANNELS@@" + ] + [ + (lib.concatStringsSep "," quickSyncChannels) + (lib.concatStringsSep "," fullSyncChannels) + ] + (builtins.readFile ./neomutt-sync-daemon.sh); }; neomuttLauncher = pkgs.writeShellApplication { @@ -136,7 +150,7 @@ in }; Service = { Type = "simple"; - ExecStart = "${lib.getExe neomuttSyncDaemon} ${lib.concatStringsSep " " fullSyncChannels}"; + ExecStart = lib.getExe neomuttSyncDaemon; }; }; }) diff --git a/modules/communication/neomutt/neomutt-sync-daemon.sh b/modules/communication/neomutt/neomutt-sync-daemon.sh index d148567..301eb98 100644 --- a/modules/communication/neomutt/neomutt-sync-daemon.sh +++ b/modules/communication/neomutt/neomutt-sync-daemon.sh @@ -1,16 +1,17 @@ #!/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. +# 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. 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 +QUICK_CHANNELS_STR="@@QUICK_CHANNELS@@" +FULL_CHANNELS_STR="@@FULL_CHANNELS@@" + +IFS=',' read -ra QUICK_CHANNELS <<<"$QUICK_CHANNELS_STR" +IFS=',' read -ra FULL_CHANNELS <<<"$FULL_CHANNELS_STR" sync_once() { echo "Syncing: $*" @@ -26,8 +27,15 @@ sync_once() { notmuch new --quiet } +first_run=true + while true; do - sync_once "$@" + if [[ $first_run == true ]]; then + sync_once "${QUICK_CHANNELS[@]}" + first_run=false + else + sync_once "${FULL_CHANNELS[@]}" + fi # Safety net: the launcher stops this service when neomutt exits; if that # didn't happen (hard kill), bail out once neomutt is gone. |
