Toolchain Extension

Posted on 2015-08-26 by fp
Send us your comments.

If you found it tedious to manually transfer vCalendar invitations in your (console-based) email-client into your taskwarrior struggle no more, ’cause I struggled enough to spend a night coding a basic translation tool: taskharrier. I have been using a tag-based, indexing email-client called sup for quite some time now, and have been using console-based clients for almost all my digital live. I do appreciate the simplicity of using text-based tools for (essentially) text-based communication.

But, using different tools for different applications instead of subscribing to any of the one-framework-for-all applications, sometimes requires a little handiwork to make those different tools work together. But that’s what I like most about simple tools: they are much easier extendable, for example by writing a small translator that connects those tools (and often those are already available or get incorporated in those tools very fast, because if you need that functionality others probably do as well).

At the core of this small translator you’ll find a small function that — in my eyes — shows off the elegance I very much like about haskell:
veTaskAddStr:: VEvent -> String
veTaskAddStr e = intercalate " "
                 $ catMaybes
                 [ Just "task add"
                 , ((veDTStart e >>= (return.dtStartDateTimeValue)) >>= (return.veTaskTime))
                 , Just "--"
                 , (veSummary e >>= (return.(T.unpack).summaryValue))
                 , (veLocation e >>= (return.(T.unpack).locationValue))

Essentially we have a function that translates a calender event into a string (that’s the type declaration in the first line). Within the square brackets you’ll find a list of things that comprise the commandline, which seems to me, quite simple to read (except the tedious return-statements that I will get rid off in the next version, when I understand applicatives).

First there is the string “task add” which is the command-line invocation of taskwarrior. And then I simply queue the start-time of the event — or the Task-Time-field of the Start—Data-TimeValue of the Start-Structure within the VEvent-Datatype. Then follows whatever is included in the events summary and location.

All is glued together (if the respective field contained a value), separated by spaces (that’s the “intercalate”-function).

And that’s about it, except I had to spend half a night finding the rightfunctions to read a file, learn to use the parsing library (which is easy), and haggled with different time-zones. Finally I did a touch ouf user-interaction to let the user express his consent with including that particular event into his schedule.

That part of the code is (not yet) completely beautiful, but I am working on getting better there.