#! /usr/bin/env bash himalaya_opts="--color=always" w3m_opts=("-T" "text/html" "-o" "display_link_number=1" "-dump") function accounts() { himalaya ${himalaya_opts[@]} accounts | \ awk '/imap/ { print $1 }' | \ sort | \ fzf --exit-0 --select-1 --ansi --layout=reverse \ --header="Accounts" \ --preview="himalaya $himalaya_opts -a {} list -s 10" \ --preview-window=right,80% } function emails() { if [ "$#" != "0" ]; then local acc=$1 local size=${2-50} local w3m_cmd="w3m ${w3m_opts[@]}" local HIM_CMD="himalaya $himalaya_opts -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 $himalaya_opts -a $acc read -t html {1}); echo \$res | head -n 2; echo -e "\\\\n\===============================================================================\\\\n"; echo \$res | tail -n +3 | ${w3m_cmd} " \ --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 IFS= res=$(himalaya $himalaya_opts -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