home/himalaya: create script for interactive mode

This commit is contained in:
Dmitriy Pleshevskiy 2022-08-31 00:34:26 +03:00
parent 4226c71445
commit aa9aaf0e7c
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
3 changed files with 53 additions and 48 deletions

View file

@ -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";
};
};
}

View file

@ -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

35
scripts/himz Executable file
View file

@ -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` $@