diff options
| -rw-r--r-- | modules/communication/neomutt/neomutt.nix | 8 | ||||
| -rw-r--r-- | modules/scripts/default.nix | 14 | ||||
| -rw-r--r-- | modules/scripts/neomutt-sync.sh | 62 |
3 files changed, 80 insertions, 4 deletions
diff --git a/modules/communication/neomutt/neomutt.nix b/modules/communication/neomutt/neomutt.nix index 30e9229..16d4b37 100644 --- a/modules/communication/neomutt/neomutt.nix +++ b/modules/communication/neomutt/neomutt.nix @@ -26,9 +26,9 @@ in "x-scheme-handler/mailto" = "neomutt.desktop"; }; - home.packages = [ - pkgs.urlscan - pkgs.w3m + home.packages = with pkgs; [ + urlscan + w3m neomuttDesktopItem ]; @@ -393,7 +393,7 @@ in "pager" ]; key = "O"; - action = "<sync-mailbox><shell-escape>mbsync -a && notmuch new<enter><sync-mailbox>"; + action = "<enter-command>set my_wait_key=$wait_key wait_key=no<enter><sync-mailbox><shell-escape>${lib.getExe config.scripts.neomutt-sync.package}<enter><sync-mailbox><enter-command>set wait_key=$my_wait_key<enter>"; } { # gx: extract links from the current message and open one, vim-netrw style diff --git a/modules/scripts/default.nix b/modules/scripts/default.nix index a05aaed..8ad27a3 100644 --- a/modules/scripts/default.nix +++ b/modules/scripts/default.nix @@ -195,6 +195,20 @@ let } ]; }; + neomutt-sync = { + path = ./neomutt-sync.sh; + deps = [ + pkgs.dialog + config.programs.mbsync.package + config.programs.notmuch.package + ]; + conditions = [ + { + option = "communication.neomutt.enable"; + value = true; + } + ]; + }; }; # Check whether all conditions for a script are satisfied diff --git a/modules/scripts/neomutt-sync.sh b/modules/scripts/neomutt-sync.sh new file mode 100644 index 0000000..a28152c --- /dev/null +++ b/modules/scripts/neomutt-sync.sh @@ -0,0 +1,62 @@ +# 1. Create temporary files for the dark theme and notmuch logs +export DIALOGRC=$(mktemp) +NOTMUCH_LOG=$(mktemp) +TITLE="[SYNCING MAIL]" +BACK_TITLE= +trap 'rm -f "$DIALOGRC" "$NOTMUCH_LOG"' EXIT # Clean up everything on exit + +cat << 'EOF' > "$DIALOGRC" +use_shadow = OFF +use_colors = ON +screen_color = (WHITE,BLACK,OFF) +dialog_color = (WHITE,BLACK,OFF) +title_color = (CYAN,BLACK,ON) +gauge_color = (WHITE,BLACK,ON) +border_color = (WHITE,BLACK,OFF) +border2_color = (WHITE,BLACK,OFF) +shadow_color = (BLACK,BLACK,OFF) + +# Active buttons: Blue text and border with no background +button_active_color = (BLUE,BLACK,ON) +button_key_active_color = (BLUE,BLACK,ON) +button_label_active_color = (BLUE,BLACK,ON) + +# Inactive buttons: Yellow text and border with no background +button_inactive_color = (YELLOW,BLACK,OFF) +button_key_inactive_color = (YELLOW,BLACK,OFF) +button_label_inactive_color = (YELLOW,BLACK,OFF) +EOF + +# 2. Run the sync and indexing progress bar +( + # --- PHASE 1: mbsync --- + script -q -e -c "mbsync -a" /dev/null | awk -v RS='\r' ' + { + c_str = "" + b_str = "" + for(i=1; i<=NF; i++) { + if ($i == "C:") c_str = $(i+1) + if ($i == "B:") b_str = $(i+1) + } + if (b_str != "") { + split(b_str, arr, "/") + if (arr[2] > 0) { + percent = int((arr[1] / arr[2]) * 100) + printf "XXX\n%d\nSyncing | Channel: %s | Mailbox: %s\nXXX\n", percent, c_str, b_str + } + } + fflush() + }' + + # --- PHASE 2: notmuch --- + printf "XXX\n100\nIndexing new mail with notmuch...\nXXX\n" + notmuch new > "$NOTMUCH_LOG" 2>&1 +) | dialog --title $TITLE --gauge "Initializing..." 8 80 0 + +# 3. Format the captured notmuch output into a single clean line +CLEAN_OUT=$(tr '\n' ' ' < "$NOTMUCH_LOG" | sed 's/ */ /g') + +# 4. Display final results and wait for user input (Enter/Esc) to dismiss +dialog --title $TITLE --msgbox "Done!\n$CLEAN_OUT" 8 80 + +clear |
