From 2ad7b06ced0ffa39d20e6be41466e5bd834ee956 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Thu, 23 Jul 2026 00:56:24 +0530 Subject: feat(w3m): add module with desktop entry + integrate into neomutt - modules/web/w3m: enable/package options, desktop entry via kitty, assertion - modules/web/w3m: delegate to programs.w3m under the hood - modules/web/w3m: default package to programs.w3m.finalPackage - modules/desktop/xdg: add portal config with common.default = "*" - neomutt/nix: use lib.getExe' config.web.w3m.package for w3m refs - neomutt/assertions: add w3m dependency assertion - users/arpit: enable web.w3m --- modules/communication/neomutt/.neomuttrc | 1 + modules/communication/neomutt/assertions.nix | 9 +++++++- modules/communication/neomutt/keybindings.nix | 6 +++++ modules/communication/neomutt/macros.nix | 24 ++++++++++++++++--- modules/communication/neomutt/neomutt.nix | 33 +++++++++------------------ 5 files changed, 47 insertions(+), 26 deletions(-) (limited to 'modules/communication/neomutt') diff --git a/modules/communication/neomutt/.neomuttrc b/modules/communication/neomutt/.neomuttrc index 829951a..877e265 100644 --- a/modules/communication/neomutt/.neomuttrc +++ b/modules/communication/neomutt/.neomuttrc @@ -4,6 +4,7 @@ # Each column in the index receives a distinct color to keep the UI organized. set menu_scroll = yes +set pager_stop = yes # cancel any prompt/command-line entry with Esc, vim-style set abort_key = "" diff --git a/modules/communication/neomutt/assertions.nix b/modules/communication/neomutt/assertions.nix index dea9d41..c4ce62a 100644 --- a/modules/communication/neomutt/assertions.nix +++ b/modules/communication/neomutt/assertions.nix @@ -1,4 +1,4 @@ -# Assertions - Validates neomutt dependencies (less, bat, kitty) are enabled +# Assertions - Validates neomutt dependencies (less, bat, kitty, w3m) are enabled { config, ... }: { assertions = [ @@ -23,5 +23,12 @@ neomutt's desktop entry requires kitty as the terminal launcher. Please enable terminal.kitty. ''; } + { + assertion = !config.communication.neomutt.enable || config.web.w3m.enable; + message = '' + communication.neomutt is enabled but web.w3m.enable is not. + neomutt uses w3m for HTML email rendering. Please enable web.w3m. + ''; + } ]; } diff --git a/modules/communication/neomutt/keybindings.nix b/modules/communication/neomutt/keybindings.nix index b84386c..929d3e2 100644 --- a/modules/communication/neomutt/keybindings.nix +++ b/modules/communication/neomutt/keybindings.nix @@ -304,5 +304,11 @@ key = "g?"; action = "help"; } + + { + map = [ "pager" ]; + key = "H"; + action = "display-toggle-weed"; + } ]; } diff --git a/modules/communication/neomutt/macros.nix b/modules/communication/neomutt/macros.nix index 0548a0f..87c05d1 100644 --- a/modules/communication/neomutt/macros.nix +++ b/modules/communication/neomutt/macros.nix @@ -11,13 +11,31 @@ action = "set my_wait_key=$wait_key wait_key=no${lib.getExe config.scripts.neomutt-sync.package}set wait_key=$my_wait_key"; } { - # gx: extract links from the current message and open one, vim-netrw style + # gx: open the message body in interactive w3m -- real vim-style + # cursor navigation (hjkl, Tab/Shift-Tab between links, Enter to + # follow, B back, q to return to neomutt). Replaces the old + # urlscan-based link picker. map = [ "index" "pager" ]; key = "gx"; - action = "urlscan"; + action = "urlscan"; + } + { + # Ctrl-B in the pager: same interactive w3m view as gx, kept as + # a second binding since Ctrl-B is a common muscle-memory key + # for "open this in a browser-like view". + map = [ "pager" ]; + key = "\\Cb"; + action = "set my_pipe_decode=$pipe_decode pipe_decode=yes${lib.getExe' config.web.w3m.package "w3m"} -T text/htmlset pipe_decode=$my_pipe_decode"; + } + { + # Ctrl-B on a specific attachment (not just the top-level + # message): pipe-entry sends the selected attachment instead. + map = [ "attach" ]; + key = "\\Cb"; + action = "${lib.getExe' config.web.w3m.package "w3m"} -cols 100 -T text/html"; } { map = [ @@ -32,7 +50,7 @@ # the counterpart to gf (interactive limit prompt) in binds.nix map = [ "index" ]; key = "gF"; - action = "~A"; + action = "all"; } { # ZZ: save and quit, vim-style (sync mailbox, then quit) diff --git a/modules/communication/neomutt/neomutt.nix b/modules/communication/neomutt/neomutt.nix index f6c7f8e..6cabf98 100644 --- a/modules/communication/neomutt/neomutt.nix +++ b/modules/communication/neomutt/neomutt.nix @@ -9,7 +9,7 @@ let neomuttDesktopItem = pkgs.makeDesktopItem { name = "neomutt"; desktopName = "NeoMutt"; - exec = "${lib.getExe config.programs.kitty.package} -e ${lib.getExe config.programs.neomutt.package}"; + exec = "${lib.getExe config.terminal.kitty.package} -e ${lib.getExe config.programs.neomutt.package}"; icon = "kitty"; categories = [ "Network" @@ -25,27 +25,21 @@ in xdg.mimeApps.defaultApplications = { "x-scheme-handler/mailto" = "neomutt.desktop"; }; - home.packages = with pkgs; [ urlscan - w3m neomuttDesktopItem ]; - xdg.configFile."neomutt/mailcap".text = '' - text/html; w3m -dump -T text/html '%s'; copiousoutput; nametemplate=%s.html - text/html; $BROWSER '%s'; nametemplate=%s.html + text/html; ${lib.getExe' config.web.w3m.package "w3m"} -dump -cols 100 -T text/html '%s'; copiousoutput; nametemplate=%s.html image/*; xdg-open '%s' & application/pdf; xdg-open '%s'; nametemplate=%s.pdf video/*; xdg-open '%s' & audio/*; xdg-open '%s' & application/*; xdg-open '%s' & ''; - xdg.configFile."neomutt/flag_legend.txt".text = '' NeoMutt Index Flags =================== - Message state ($flag_chars) -- unchanged defaults N New - unread, arrived since you last checked O Old - unread, but seen in a previous session @@ -55,25 +49,21 @@ in * Tagged - selected for a bulk operation (toggle with t) r Replied - you've replied to this message (blank) - read, nothing else notable - Cryptography ($crypt_chars) -  Verified - signed, and the signature checks out -  Encrypted - PGP/SMIME encrypted -  Signed - PGP/SMIME signed (unverified) -  PGP key - message contains a PGP public key + Verified - signed, and the signature checks out + Encrypted - PGP/SMIME encrypted + Signed - PGP/SMIME signed (unverified) + PGP key - message contains a PGP public key (blank) - no cryptography info - Addressing ($to_chars) -  To you only - sent to you and only you -  To (with others) - you're in the To: list, among others -  Cc only - you're only in the Cc: list -  From you - sent by you -  Mailing list - sent to a list you're subscribed to + To you only - sent to you and only you + To (with others) - you're in the To: list, among others + Cc only - you're only in the Cc: list + From you - sent by you + Mailing list - sent to a list you're subscribed to (blank) - not in To/Cc (e.g. Bcc, unlisted) - Press q to close. ''; - programs.neomutt = { enable = true; sidebar.enable = true; @@ -81,7 +71,6 @@ in vimKeys = true; unmailboxes = true; checkStatsInterval = 20; - extraConfig = builtins.readFile ./.neomuttrc; }; }; -- cgit v1.2.3