From aa9aaf0e7c36b8ca94a84edfcee8a85a5d68c524 Mon Sep 17 00:00:00 2001 From: janabhumi Date: Wed, 31 Aug 2022 00:34:26 +0300 Subject: [PATCH] home/himalaya: create script for interactive mode --- home/progs/himalaya.nix | 26 ++++++++++++++++++-------- scripts/him.sh | 40 ---------------------------------------- scripts/himz | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 48 deletions(-) delete mode 100755 scripts/him.sh create mode 100755 scripts/himz diff --git a/home/progs/himalaya.nix b/home/progs/himalaya.nix index f3ea8b4..d141c2a 100644 --- a/home/progs/himalaya.nix +++ b/home/progs/himalaya.nix @@ -13,6 +13,23 @@ let }; }); + himz = with pkgs; stdenv.mkDerivation { + name = "himz-0.1"; + src = ../../scripts; + + nativeBuildInputs = [ makeWrapper ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + cp himz $out/bin/himz + wrapProgram "$out/bin/himz" --prefix PATH : "$out/bin:${lib.makeBinPath [ w3m fzf ]}" + + runHook postInstall + ''; + }; + bin = "${devHimalaya}/bin/himalaya"; in { @@ -25,6 +42,7 @@ in }; config = mkIf cfg.enable { + home.packages = [ himz ]; programs.himalaya = { enable = true; package = devHimalaya; @@ -33,13 +51,5 @@ in downloads-dir = "${config.home.homeDirectory}/downloads/email"; }; }; - - programs.zsh.shellAliases = mkIf config.shell.zsh.enable { - him = bin; - himp = "${bin} -a personal"; - himf = "${bin} -a family"; - himw = "${bin} -a work"; - }; }; } - diff --git a/scripts/him.sh b/scripts/him.sh deleted file mode 100755 index c5d27f8..0000000 --- a/scripts/him.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh - -bin="himalaya" - -case $1 in - "" | "list") - for acc in $(NO_COLOR=1 $bin accounts | grep imap | awk '{ print $1 }') - do - echo "account: $acc" - $bin -a "$acc" list -s 10 -w 120 | grep '✷' - echo "---" - done - ;; - - "unread-count") - a=0 - for acc in $(NO_COLOR=1 $bin accounts | grep imap | awk '{ print $1 }') - do - a=$((a+$($bin -a "$acc" search unseen -s 200 | grep '✷' | wc -l))) - done - echo $a - ;; - - "watch") - while true - do - printf '\033[2J' - $0 list - sleep 60 - done - ;; - - "mark-read") - for id in $(NO_COLOR=1 $bin -a $2 search unseen -s 200 | grep '✷'| awk '{ print $1 }') - do - $bin -a $2 flag add $id seen - done -esac - - diff --git a/scripts/himz b/scripts/himz new file mode 100755 index 0000000..6a2baeb --- /dev/null +++ b/scripts/himz @@ -0,0 +1,35 @@ +#! /usr/bin/env bash + +function __him_accounts() { + himalaya accounts | \ + awk '/imap/ { print $1 }' | \ + sort | \ + fzf --exit-0 --select-1 --ansi --layout=reverse \ + --header="Accounts" \ + --preview="himalaya -a {} list -s 10" \ + --preview-window=right,80% +} + +function __him_emails() { + if [ "$#" != "0" ]; then + local w3m_opts="-T text/html -o display_link_number=1 -dump" + local acc=$1 + local size=${2-50} + local selected=$( + himalaya -a $acc list -s $size | grep '│' | \ + fzf --exit-0 --ansi --layout=reverse \ + --header-lines=1 \ + --header="Account: ${acc}" \ + --preview="himalaya -a ${acc} read -t html {1} | w3m $w3m_opts" \ + --preview-window=down,70% \ + --bind="ctrl-r:reload(himalaya -a $acc list -s $size | grep '│')" + ) + local eid=$(echo $selected | awk '{ print $1 }') + if [ "$eid" != "" ]; then + himalaya -a $acc read -t html $eid | w3m $w3m_opts + fi + fi +} + +__him_emails `__him_accounts` $@ +