Because I use Mutt, any mailbox that has new mail tends to get my attention when I check my email. This became particularly annoying because I kept opening my spam mailbox to check a single spam message. Therefore, I decided to come up with a way to delay the delivery of my spam to once per day.
I started by changing my “.procmailrc” to deliver spam messages to a different mailbox that Mutt does not check.
MAIL=`echo $HOME/Mail`
[...]
:H
* ^X-Spam-Status: Yes
$MAIL/delay_spam
[...]
Then I created a new procmailrc file called “spam.procmailrc” that would deliver mail to my checked spam mailbox.
MAIL=`echo $HOME/Mail`
:0
$MAIL/spam
Next, I wrote a short Bash script to use Formail and Procmail to deliver all of the messages in the delayed delivery spam mailbox to the normal spam mailbox.
#! /bin/bash
FORMAIL=/usr/bin/formail
PROCMAIL=/usr/bin/procmail
PROCMAILRC=$HOME/.procmail/spam.procmailrc
MAIL=$HOME/Mail
DELAY=$MAIL/delay_spam
TEMP=$MAIL/.spam
LOCK=$TEMP.lock
# Make sure there is delayed mail and we can get the lock (retry once)
if ( test -s $DELAY && lockfile -r 1 $LOCK 2>/dev/null ); then
# Add the delayed mail to the temp mailbox and empty the delayed mailbox
cat $DELAY >> $TEMP && cat /dev/null > $DELAY
# Process each delayed message
$FORMAIL -s $PROCMAIL $PROCMAILRC < $TEMP && rm -f $TEMP
# Delete the lock now that we are done
rm -f $LOCK
fi
Finally, I set the script to run daily using Cron. Now I am only interrupted by spam when I choose to be instead of every time a new message arrives. I have used the same technique to delay the delivery of emails to unimportant mailing lists so I only read them hourly instead of every time a message arrives.
In my previous post, I described how to set up tab completion for many common commands using these Bash completion files. This works well for established commands, but it doesn’t work so well for commands that I have written myself.
I use a command called “hc12-console” to connect to 68HC12 microcontrollers over a serial port. The command takes two arguments: the name of a microcontroller to connect to and a file to load. I only have two microcontrollers called “dragon1″ and “dragon2″. Therefore, I want to be able to tab complete the first argument to one of those values only. The second argument should be the name of a file that ends in “.load”.
I do this with a function that checks the argument number and then completes it based on a specified list or by limiting the types of files that will be listed.
_hc12console ()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
# First argument completes with either dragon1 or dragon2
if [[ $COMP_CWORD -eq 1 ]] ; then
COMPREPLY=( $( compgen -W "dragon1 dragon2" -- $cur ) )
return 0
fi
# Second argument completes with only files matching *.load
if [[ $COMP_CWORD -eq 2 ]] ; then
COMPREPLY=( $( compgen -f -X '!*.load' -- $cur ) )
return 0
fi
# All other arguments will not auto-complete
return 0
}
complete -F _hc12console hc12-console
I added the script above to a file that my bashrc sources. It associates the function with the shell command, and then instead of manually typing out:
hc12-console dragon1 file.load <enter>
I can type:
hc12<tab> <tab>1 <tab> <enter>
I had a directory of BMP image files that I wanted to convert to EPS (Encapsulated PostScript). Since I was planning on adding files to the directory, I did not want to hard code the names of the files into the makefile that would do the conversion. Therefore, the trick was to run a shell command inside of the makefile. The first line lists all of the BMP files and assigns it to “BMP_FILES”. The next line replaces the “bmp” extension with “eps”. The complete makefile is below.
BMP_FILES = $(shell ls *.bmp)
EPS_FILES = ${BMP_FILES:%.bmp=%.eps}
all: ${EPS_FILES}
%.eps : %.bmp
convert $*.bmp $*.eps
All that is left is to type “make” in the directory, and all of the BMP files will be converted to EPS.
I prefer to do all of my Subversion work from the command line, but I realize that not all people are like me. Clarissa and I have been using a wiki to keep track of most of our shared information (including our wedding preparations), but our wiki does not work well for content like spreadsheets. Therefore, I decided to try out a Subversion repository. After some initial searching for graphical clients, I found ZigVersion. It is a simple graphical Subversion client for Mac OS X. It took a little bit to explain how it worked and how to use it to Clarissa, but now we have been sharing and editing non-wiki-friendly files for a few weeks.