mutt-wizard/removeaccount.sh

40 lines
1.0 KiB
Bash
Raw Normal View History

2018-02-10 07:47:29 +01:00
#!/bin/sh
2018-02-10 17:00:03 +01:00
muttdir="$HOME/.config/mutt/"
2018-02-10 07:47:29 +01:00
# This script will remove an account from ~/.offlineimaprc and the
# designated location in ~/.config/mutt/accounts.
# Feed the script the title of the account.
2018-02-10 18:12:10 +01:00
cat ~/.offlineimaprc | grep "^accounts =" | sed -e 's/accounts =\( \)//g;s/\(,\) /\n/g;' | nl --number-format=ln > /tmp/numbered
2018-02-10 07:47:29 +01:00
removeAccount() { sed -ie "
2018-02-10 18:12:10 +01:00
/Account $1]/,/Account/{//!d}
/Account $1]/d
s/ $1\(,\|$\)//g
s/=$1\(,\|$\)/=/g
2018-02-10 07:47:29 +01:00
s/,$//g
" ~/.offlineimaprc
2018-02-10 18:12:10 +01:00
rm "$muttdir"accounts/$1.muttrc
2018-02-10 19:02:44 +01:00
rm "$muttdir"credentials/$1.gpg
2018-02-11 00:00:14 +01:00
rm -rf "$muttdir"accounts/$1
2018-02-10 18:12:10 +01:00
echo $1 deleted. ;}
#/tmp/numbered
accounts=()
while read n s ; do
accounts+=($n "$s" off)
done < /tmp/numbered
choices=$(dialog --separate-output --checklist "Choose an email account to remove." 22 76 16 "${accounts[@]}" 2>&1 >/dev/tty)
clear
if [ -z "$choices" ];
then
2018-02-11 00:00:14 +01:00
clear
2018-02-10 18:12:10 +01:00
else
todelet=$(IFS="|"; keys="${choices[*]}"; keys="${keys//|/\\|}"; grep -w "${keys}" /tmp/numbered | awk '{print $2}')
for i in $todelet; do removeAccount $i; done
fi