rc/config/neomutt/folder-hooks.sh

48 lines
1.2 KiB
Bash
Executable file

#!/bin/sh
usage() {
>&2 echo "$0 <mutt \$folder>"
>&2 echo " Generate mutt folder hooks for every maildir account in \$folder"
exit 1
}
if [ -z "$1" ]; then
usage
fi
acc_dir="$HOME/.config/neomutt/accounts/"
mail_dir="$1"
# Select default account
#default="$(find "$acc_dir" -name "*.mail" -printf "source '%p'\n" -quit)"
#if [ -z "$default" ]; then
# >&2 echo "No mail accounts found in $acc_dir"
# exit 1
#fi
# Order of the keys to use for the account switch macro
chars="1234567890azertyuiopqsdfghjklmwxcvbn"
i=1
# Setup folder hooks for all the accounts
for f in "$acc_dir"*.mail; do
account="$(basename -s '.mail' "$f")"
if [ ! -d "$mail_dir/$account" ]; then
continue
fi
if [ -z "$default" ]; then
default="source '$f'"
fi
inbox="$(find "$mail_dir/$account" -maxdepth 1 -iname "inbox" -type d -printf "%f" -quit)"
printf 'folder-hook =%s '\''source %s'\''\n' "$account" "$f"
key="$(printf '%s' "$chars" | cut -c "$i")"
printf 'macro index,pager <Esc>%s "<change-folder>=%s/%s<Return>" "Change to %s Inbox"\n' \
"$key" "$account" "$inbox" "$account"
i=$((i+1))
done
if [ ! -z "$default" ]; then
printf '%s\n' "$default"
fi