system/scripts/himz

56 lines
1.4 KiB
Bash
Executable file

#! /usr/bin/env bash
IFS=
w3m_opts=("-T" "text/html" "-o" "display_link_number=1" "-dump")
function 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 emails() {
if [ "$#" != "0" ]; then
local acc=$1
local size=${2-50}
local HIM_CMD="himalaya -a $acc list -s $size -w 150"
local selected=$(
FZF_DEFAULT_COMMAND="$HIM_CMD | grep '│'" \
fzf --exit-0 --ansi --layout=reverse \
--header-lines=1 \
--header="Account: ${acc}" \
--preview="
res=\$(himalaya -a $acc read -t html {1});
echo \$res | head -n 2;
echo -e "\\\\n\===============================================================================\\\\n";
echo \$res | tail -n +3 | w3m ${w3m_opts}
" \
--preview-window=down,70% \
--bind="ctrl-r:reload(eval $FZF_DEFAULT_COMMAND)"
)
echo $selected | awk '{ print $1 }'
fi
}
while :
do
acc=$(accounts)
if [ "$acc" == "" ]; then
break
fi
eid=$(emails $acc $@)
if [ "$eid" != "" ]; then
res=$(himalaya -a $acc read -t html $eid)
echo $res | head -n 2
echo -e "\n===============================================================================\n"
echo $res | tail -n +3 | w3m ${w3m_opts[@]}
break
fi
done