Customising Email Signatures with Fortune

When I look at someone’s email signature and see a thought-provoking quote like “Violence is the last refuge of the incompetent” (Salvor Hardin), I add it to my mental list of quotes, which, of course, is soon forgotten. Now, with a bit of pipe magic, I can use Mutt and fortune to make my signatures a bit more creative.

Preparing the database

1. Create a .fortune file in your home directory and insert your quotes.  Separate each quote/phrase with a % (percentage sign).

~ %   touch ~/fortune
~ %   vim ~/fortune
  1 De duobus malis minus est semper eligendum.
  2   -- Thomas a Kempis
  3 %
  4 Sic transit gloria mundi.
  5   -- Thomas a Kempis
  6 %

2. Randomise access to the strings with strfile.

~ %   strfile -r ~/fortune ~/fortune.dat
"/home/antony/fortune.dat" created
There were 2 strings
Longest string: 65 bytes
Shortest string: 47 bytes

To save yourself embarrassment in the future, keep your quotes short and SFW.

Integrating the database with Mutt

3. Create a simple script to use with Mutt.

~ %   touch bin/
~ %   vim bin/
  1 #!/bin/bash
  3 cat ~/.signature
  4 fortune ~/fortune
~ %   chmod +x bin/

4. Finally, set the script as Mutt’s default signature.

~ %   vim ~/.mutt/muttrc
17 set signature="~/bin/ |"

Now you can enjoy creative, original signatures in your emails.

After a bit of thought, I came up with a heavily customised signature script that will: print the contents of ~/.signature, append a justified fortune quote from my database and right justify the attributed author.  Of course, it needs some work because the last line is right justified regardless of if there is an attributed author or not.

1 #!/bin/bash
3 fortune ~/fortune | sed -e 's/^/++ /' -e 's/$/ ++/' > /tmp/signature.1
4 sed -n '$!p' /tmp/signature.1 | par -58s3p3 > /tmp/signature.2
5 tail -n1 /tmp/signature.1 | sed -e :a -e 's/^.\{1,56\}$/ &/;ta' -e 's/++/\ \ /' -e 's/^./++/' >> /tmp/signature.2
6 cat ~/.signature
7 cat /tmp/signature.2

outputting something similar to:

Antony Jepson / <> / GPG Key: 0x00000000
++ Sapere aude! (Dare to be wise!)                      ++
++                          -- Quintus Horatius Flaccus ++

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: