2006-02-22

The Fruits of My .muttrc-Killing Labor

The script I ended up with after accidentally erasing my .muttrc file looks as follows. I first wrote a portion of the script in Python, but soon realized that awk, as always, was faster and better suited to the task:

$ cat /home/toby/bin/muttrc.do
cp $HOME/.muttrc $HOME/.muttrc.bak
sed -e '/^mailboxes/d;/^$/d' $HOME/.muttrc | sort -u
echo ""
ls -ad1 $HOME/Maildir/.[A-Z]*  | sort -u  | awk -F'\/' '
     BEGIN{ printf("mailboxes !") }
     { printf(" +%s",$5) }
     END{ printf("\n") }
   '

Putting this to work involves the following line placed (all on one line) into your crontab:

01 09 * * * sh -e $HOME/bin/muttrc.do > $HOME/.muttrc.new ; \
  mv $HOME/.muttrc.new $HOME/.muttrc

Still testing this code, so the standard disclaimers apply: your actual mileage may vary, don't blame me if this eats your hard drive or obliterates any files you may care about (not the least of which is your .muttrc file), et cetera, et cetera, et cetera.

No comments: