scripts/himz: add support of color

This commit is contained in:
Dmitriy Pleshevskiy 2022-09-04 16:03:13 +03:00
parent 1c5b476417
commit 338ed982f2
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215

View file

@ -1,15 +1,15 @@
#! /usr/bin/env bash #! /usr/bin/env bash
IFS= himalaya_opts="--color=always"
w3m_opts=("-T" "text/html" "-o" "display_link_number=1" "-dump") w3m_opts=("-T" "text/html" "-o" "display_link_number=1" "-dump")
function accounts() { function accounts() {
himalaya accounts | \ himalaya ${himalaya_opts[@]} accounts | \
awk '/imap/ { print $1 }' | \ awk '/imap/ { print $1 }' | \
sort | \ sort | \
fzf --exit-0 --select-1 --ansi --layout=reverse \ fzf --exit-0 --select-1 --ansi --layout=reverse \
--header="Accounts" \ --header="Accounts" \
--preview="himalaya -a {} list -s 10" \ --preview="himalaya $himalaya_opts -a {} list -s 10" \
--preview-window=right,80% --preview-window=right,80%
} }
@ -17,20 +17,22 @@ function emails() {
if [ "$#" != "0" ]; then if [ "$#" != "0" ]; then
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 w3m_cmd="w3m ${w3m_opts[@]}"
local HIM_CMD="himalaya $himalaya_opts -a $acc list -s $size -w 150"
local selected=$( local selected=$(
FZF_DEFAULT_COMMAND="$HIM_CMD | 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=" --preview="
res=\$(himalaya -a $acc read -t html {1}); res=\$(himalaya $himalaya_opts -a $acc read -t html {1});
echo \$res | head -n 2; echo \$res | head -n 2;
echo -e "\\\\n\===============================================================================\\\\n"; echo -e "\\\\n\===============================================================================\\\\n";
echo \$res | tail -n +3 | w3m ${w3m_opts} echo \$res | tail -n +3 | ${w3m_cmd}
" \ " \
--preview-window=down,70% \ --preview-window=down,70% \
--bind="ctrl-r:reload(eval $FZF_DEFAULT_COMMAND)" --bind='ctrl-r:reload(eval $FZF_DEFAULT_COMMAND)'
) )
echo $selected | awk '{ print $1 }' echo $selected | awk '{ print $1 }'
fi fi
@ -45,7 +47,8 @@ do
eid=$(emails $acc $@) eid=$(emails $acc $@)
if [ "$eid" != "" ]; then if [ "$eid" != "" ]; then
res=$(himalaya -a $acc read -t html $eid) IFS=
res=$(himalaya $himalaya_opts -a $acc read -t html $eid)
echo $res | head -n 2 echo $res | head -n 2
echo -e "\n===============================================================================\n" echo -e "\n===============================================================================\n"
echo $res | tail -n +3 | w3m ${w3m_opts[@]} echo $res | tail -n +3 | w3m ${w3m_opts[@]}