Skip to content

Instantly share code, notes, and snippets.

@thekad
Created June 13, 2020 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thekad/f6f567fe62f9f06a7f7e87c03a506293 to your computer and use it in GitHub Desktop.
Save thekad/f6f567fe62f9f06a7f7e87c03a506293 to your computer and use it in GitHub Desktop.
#!/bin/bash
session="${1:-mutt}"
echo "reading all configured accounts"
declare -A accounts
for af in ~/.mutt/account-*.rc; do
if [[ -f "$(realpath "$af")" ]]; then
account=$(basename "$af" .rc | sed -e "s/account-//")
accounts["$account"]="$af"
fi
done
if [[ ${#accounts[*]} -gt 0 ]]; then
declare -p accounts
else
echo "no accounts configured?"
exit
fi
if tmux has-session -t "$session"; then
echo "attaching to existing multi-mutt session"
tmux switch-client -t "$session"
else
echo "creating new multi-mutt session"
tmux new-session -d -s "$session"
fi
for account in "${!accounts[@]}"; do
if tmux list-windows -F '#{window_name}' -t "$session" | grep -q "^${account}$"; then
echo "account $account already opened"
else
echo "opening account $account"
tmux new-window -P -n "$account" "mutt -F ${accounts["$account"]}"
fi
done
tmux kill-window -t bash
tmux attach-session -d -t "$session"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment