2019-04-16 03:31:31 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2019-11-20 21:08:34 +00:00
|
|
|
usage() {
|
|
|
|
echo "$0 <mutt \$folder>"
|
|
|
|
echo " Generate mutt folder hooks for every maildir account in \$folder"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2019-04-16 16:45:41 +00:00
|
|
|
acc_dir="$HOME/.config/neomutt/accounts/"
|
2019-11-20 21:08:34 +00:00
|
|
|
mail_dir="$1"
|
2019-04-16 16:45:41 +00:00
|
|
|
|
2019-04-16 03:31:31 +00:00
|
|
|
# Select default account
|
2019-04-16 16:45:41 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
printf '%s\n' "$default"
|
2019-04-16 03:31:31 +00:00
|
|
|
|
2019-04-16 03:58:04 +00:00
|
|
|
# Order of the keys to use for the account switch macro
|
|
|
|
chars="1234567890azertyuiopqsdfghjklmwxcvbn"
|
|
|
|
i=1
|
|
|
|
|
2019-04-16 03:31:31 +00:00
|
|
|
# Setup folder hooks for all the accounts
|
2019-04-16 16:45:41 +00:00
|
|
|
for f in "$acc_dir"*.mail; do
|
2019-04-16 03:31:31 +00:00
|
|
|
account="$(basename -s '.mail' "$f")"
|
2019-10-27 12:17:03 +00:00
|
|
|
inbox="$(find "$mail_dir/$account" -maxdepth 1 -iname "inbox" -type d -printf "%f" -quit)"
|
2019-04-16 03:31:31 +00:00
|
|
|
printf 'folder-hook =%s '\''source %s'\''\n' "$account" "$f"
|
2019-04-16 03:58:04 +00:00
|
|
|
key="$(printf '%s' "$chars" | cut -c "$i")"
|
2019-10-27 12:17:03 +00:00
|
|
|
printf 'macro index,pager <Esc>%s "<change-folder>=%s/%s<Return>" "Change to %s Inbox"\n' \
|
|
|
|
"$key" "$account" "$inbox" "$account"
|
2019-04-16 03:58:04 +00:00
|
|
|
i=$((i+1))
|
2019-04-16 03:31:31 +00:00
|
|
|
done
|