Created
June 13, 2020 00:06
-
-
Save thekad/f6f567fe62f9f06a7f7e87c03a506293 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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