2022-08-31 00:34:26 +03:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
2022-09-04 16:03:13 +03:00
|
|
|
himalaya_opts="--color=always"
|
2022-09-03 22:49:49 +03:00
|
|
|
w3m_opts=("-T" "text/html" "-o" "display_link_number=1" "-dump")
|
|
|
|
|
|
|
|
function accounts() {
|
2022-09-04 16:03:13 +03:00
|
|
|
himalaya ${himalaya_opts[@]} accounts | \
|
2022-08-31 00:34:26 +03:00
|
|
|
awk '/imap/ { print $1 }' | \
|
|
|
|
sort | \
|
|
|
|
fzf --exit-0 --select-1 --ansi --layout=reverse \
|
|
|
|
--header="Accounts" \
|
2022-09-04 16:03:13 +03:00
|
|
|
--preview="himalaya $himalaya_opts -a {} list -s 10" \
|
2022-08-31 00:34:26 +03:00
|
|
|
--preview-window=right,80%
|
|
|
|
}
|
|
|
|
|
2022-09-03 22:49:49 +03:00
|
|
|
function emails() {
|
2022-08-31 00:34:26 +03:00
|
|
|
if [ "$#" != "0" ]; then
|
|
|
|
local acc=$1
|
2022-09-04 22:26:19 +03:00
|
|
|
local W3M_CMD="w3m ${w3m_opts[@]}"
|
|
|
|
local HIM_CMD="himalaya $himalaya_opts -a $acc list -w 150"
|
2022-08-31 00:34:26 +03:00
|
|
|
local selected=$(
|
2022-09-03 22:49:49 +03:00
|
|
|
FZF_DEFAULT_COMMAND="$HIM_CMD | grep '│'" \
|
|
|
|
fzf --exit-0 --ansi --layout=reverse \
|
|
|
|
--header-lines=1 \
|
|
|
|
--header="Account: ${acc}" \
|
|
|
|
--preview="
|
2022-09-04 16:03:13 +03:00
|
|
|
res=\$(himalaya $himalaya_opts -a $acc read -t html {1});
|
2022-09-03 22:49:49 +03:00
|
|
|
echo \$res | head -n 2;
|
|
|
|
echo -e "\\\\n\===============================================================================\\\\n";
|
2022-09-04 22:26:19 +03:00
|
|
|
echo \$res | tail -n +3 | ${W3M_CMD}
|
2022-09-03 22:49:49 +03:00
|
|
|
" \
|
|
|
|
--preview-window=down,70% \
|
2022-09-04 16:03:13 +03:00
|
|
|
--bind='ctrl-r:reload(eval $FZF_DEFAULT_COMMAND)'
|
2022-08-31 00:34:26 +03:00
|
|
|
)
|
2022-09-03 22:49:49 +03:00
|
|
|
echo $selected | awk '{ print $1 }'
|
2022-08-31 00:34:26 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-09-03 22:49:49 +03:00
|
|
|
while :
|
|
|
|
do
|
|
|
|
acc=$(accounts)
|
|
|
|
if [ "$acc" == "" ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
eid=$(emails $acc $@)
|
|
|
|
if [ "$eid" != "" ]; then
|
2022-09-04 16:03:13 +03:00
|
|
|
IFS=
|
|
|
|
res=$(himalaya $himalaya_opts -a $acc read -t html $eid)
|
2022-09-03 22:49:49 +03:00
|
|
|
echo $res | head -n 2
|
|
|
|
echo -e "\n===============================================================================\n"
|
|
|
|
echo $res | tail -n +3 | w3m ${w3m_opts[@]}
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2022-08-31 00:34:26 +03:00
|
|
|
|