GTD with Mutt

logo for article: GTD with Mutt

X-Labels are nice to add comments to mails in your inbox. If you keep track of your TODO stuff in a GTD-way ("Getting things done") X-Labels can be even more useful. Here's a little script I'm using to comfortably label and save incoming mails with Mutt.

You can get the whole package here: http://footils.org/pkg/mutt-gtd.tgz

Installation

If you downloaded the tarfile you can follow these instructions:

  • Put "editlabel" somewhere into your path and make it executable ("chmod +x /path/to/editlabel")
  • Put "label-wide" and "label-narrow" into ~/.mutt/ (or adapt the paths)
  • add muttrc-gtd into your ~/.muttrc (or source it from there)

editlabel is actually a dumbed-down version of the Mutt X-Labeller written by Alberto Bertogli. I didn't want to insert prefabricated labels, but free-form labels, so I just removed all the stuff dealing with that.

While I was at it, I also removed the menu to specify actions like "clean" from it. To delete an X-Label, just insert a label wih just "x". (Of course if your NextAction for something is "x", you're fsck'd.)

The labeller then was married with the GTD/Mutt ideas of koweycode: Two keyboard macros, Alt-a and Alt-w (rsp. Esc-a or Esc-w) were added to edit a label and then save to the ACTION- rsp. WAITFOR-folder in your maildir.

There still seems to be a bug in this somewhere (or a bug in Mutt) because somehow the wrong message is selected for saving after a label was edited. I tried both with the <next-undeleted>-command after syncing, and without it, but on both versions it sometimes works correctly, and sometimes it doesn't.

Using a Config-trick from the Mutt-Wiki I also added a mapping to expand and (almost) hide the X-Label in the index view. As default it is mapped to <esc>x (Alt-x).

Here are the files included in the tarfile:

editlabel:

 #!/bin/bash
# $1 is the filename

FNAME="$1"
NFNAME="/tmp/editlabels-`basename "$1"`.$$"

function asklabel() {
    read -e -p "Label ('x' to del) [$2]: " $1
    CVAL=${!1}
}

ACT=`formail -c -X X-Label < "$FNAME"`
asklabel LNAME "`echo $ACT | sed -e 's/^X-Label: //'`"

if [ "$LNAME" ]; then
    if [ "$LNAME" == "x" ]; then
        # label "x" means remove label:
        formail -I "X-Label:" < "$FNAME" > "$NFNAME"
    else
        # set label to new label:
        NEW="X-Label: $LNAME"
        formail -I "$NEW" < "$FNAME" > "$NFNAME"
    fi
fi

# if we created a new file, step over the old one
if [ -f "$NFNAME" ]; then
    mv "$NFNAME" "$FNAME"
fi

muttrc-gtd:

# put this at the end of your muttrc:

# store editor to be able to restore it after label editing:
set my_default_editor=$editor

# labels, inspired by: http://auriga.wearlab.de/~alb/other/mutt-labels/
macro index,pager y "<enter-command>set editor=\"editlabel\"<enter>\
<edit><sync-mailbox><next-undeleted>\
<enter-command>set editor=\"$my_default_editor\"<enter>" "Add/remove label"

# write label, save to action file:
macro index,pager <esc>a "<enter-command>set editor=\"editlabel\"<enter>\
<edit><sync-mailbox><next-undeleted>\
<enter-command>set editor=\"$my_default_editor\"<enter><save-message>=ACTION" "Add label and save to ACTION"

# write label, save to waitfor file:
macro index,pager <esc>w "<enter-command>set editor=\"editlabel\"<enter>\
<edit><sync-mailbox><next-undeleted>\
<enter-command>set editor=\"$my_default_editor\"<enter><save-message>=WAITFOR" "Add label and save to WAITFOR"

# save message that need a response to the RESPOND mbox:
macro index,pager <esc>q "<save-message>=RESPOND" "Save message to RESPOND"
macro index,pager <esc>s "<save-message>=inbox-archive" "Save message to inbox-archive"

# start with a narrow label-display (this also maps <esc>x to toggle label width)
set my_default_index_format="%4C %Z %{%b %d} %-15.15F (%4l) [%?Y?%-3.3y&---?] %s"
set my_label_index_format="%4C %Z %{%b %d} %-15.15F (%4l) [%?Y?%-45.45y&---------------------------------------------?] %s"
set index_format=$my_default_index_format

source ~/.mutt/label-narrow

label-wide:

set index_format="$my_label_index_format"
macro index <esc>x "<enter-command>source ~/.mutt/label-narrow<enter>" "Switch Label Width"

label-narrow:

set index_format="$my_default_index_format"
macro index <esc>x "<enter-command>source ~/.mutt/label-wide<enter>" "Switch Label Width"

Some comments

Post a comment

footils.org