scripts: improve himz ux

This commit is contained in:
Dmitriy Pleshevskiy 2022-09-03 22:49:49 +03:00
parent c52de0c9ca
commit 47e9554029
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215

View file

@ -1,6 +1,9 @@
#! /usr/bin/env bash #! /usr/bin/env bash
function __him_accounts() { IFS=
w3m_opts=("-T" "text/html" "-o" "display_link_number=1" "-dump")
function accounts() {
himalaya accounts | \ himalaya accounts | \
awk '/imap/ { print $1 }' | \ awk '/imap/ { print $1 }' | \
sort | \ sort | \
@ -10,26 +13,43 @@ function __him_accounts() {
--preview-window=right,80% --preview-window=right,80%
} }
function __him_emails() { function emails() {
if [ "$#" != "0" ]; then if [ "$#" != "0" ]; then
local w3m_opts="-T text/html -o display_link_number=1 -dump"
local acc=$1 local acc=$1
local size=${2-50} local size=${2-50}
local HIM_CMD="himalaya -a $acc list -s $size -w 150"
local selected=$( local selected=$(
himalaya -a $acc list -s $size | grep '│' | \ FZF_DEFAULT_COMMAND="$HIM_CMD | grep '│'" \
fzf --exit-0 --ansi --layout=reverse \ fzf --exit-0 --ansi --layout=reverse \
--header-lines=1 \ --header-lines=1 \
--header="Account: ${acc}" \ --header="Account: ${acc}" \
--preview="himalaya -a ${acc} read -t html {1} | w3m $w3m_opts" \ --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% \ --preview-window=down,70% \
--bind="ctrl-r:reload(himalaya -a $acc list -s $size | grep '│')" --bind="ctrl-r:reload(eval $FZF_DEFAULT_COMMAND)"
) )
local eid=$(echo $selected | awk '{ print $1 }') echo $selected | awk '{ print $1 }'
if [ "$eid" != "" ]; then
himalaya -a $acc read -t html $eid | w3m $w3m_opts
fi
fi fi
} }
__him_emails `__him_accounts` $@ 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