Tracking time on the command line with Taskwarrior and Timewarrior

Juri Rischel Jensen
4 min readJun 3, 2020

--

As a DevOps consultant I have to track the time I use on a given assignment, to base my invoicing on. Sometimes I only have to sum up the hours used in a month, and invoice based on that, sometimes I have to track time on individual customer projects or even individual issues/tickets. And it’s the latter that can be a bit cumbersome, especially if you jump between issues several times a day.

Last year I had an assignment where I had to track time used on individual issues, register that time in the customers timetracking system on a weekly basis, and invoice on the summed up hours for the month. Fortunately I got a MacBook to do my work on (my preferred platform) that had a fresh OS install, and an account with full admin rights. I could setup the laptop as I like it. That’s when I made the switch to the Fish shell, and used Taskwarrior and Timewarrior to track my time, and sync it with the issue tracker, Jira.

I had played around with Taskwarrior a couple of times, but never incorporated it into my workflow. I knew that I could combine it with Timewarrior to track my time too. So I went out for setting it up.

Taskwarrior installation and configuration

On macOS Taskwarrior is easy to install. In a terminal window type:

brew install task

By running the task command once, you create the config file:

task

This creates the file .taskrc in your home directory. The only customization I did, was to change the color theme. Ensure that the .taskrc file contains the following line:

include /usr/local/Cellar/task/2.5.1/share/doc/task/rc/solarized-dark-256.theme

Of course the version should match the version you’re using. Now we’re ready to install and configure timewarrrior:

Timewarrior installation and configuration

In a terminal window type:

brew install timewarrior

Start by running the timew command:

timew — version

This creates the datadirectory (~/.timewarrior/data) and the configuration file (~/.timewarrior/timewarrior.cfg). We now need to configure the exclusions for timewarrior (the periods of the week that we don’t want to track with timewarrior). Add the following to the ~/.taskwarrior/taskwarrior.cfg file:

Take a look at the third line. It excludes everything before 9.00AM, the lunchbreak between 12–12:30 and everything after 5PM. The last two lines excludes both saturday and sunday. This setup allows you to start a timer on a task on friday, and let it run during the weekend until you stop working on the task late monday afternoon. It only tracks the workhours spent friday, until 5PM, and the hours after 9AM monday, even though the timer has been active during the weekend. That makes the reporting much easier.

Now we need to add a hook to taskwarrior, that starts a timer when you start working on a task, and stops the timer when you stop the work. Copy the on-modify hook that’s distributed with the timewarrior package, to the hooks dir:

cp /usr/local/share/doc/timew/ext/on-modify.timewarrior ~/.task/hooks/

Now make the hook script executable:

chmod +x ~/.task/hooks/on-modify.timewarrior

Once it’s installed, run the task diagnostics command:

task diagnostics

This command shows a lot of information about your taskwarrior installation. Look for the Hooks section:

Now you’re ready to use task- and timewarrior together. Start by adding a task:

task add Test task- and timewarrior integration

When you press enter you will see that the task is being added. Start working on the task by typing:

As you work, you can get a status on the timetracking:

To stop the tracking, type:

And to get a report of the time spent that week in a graphlike view:

And in the end of the month, you could get a list-view report, to base your invoicing on:

This setup enabled me to switch between tasks, by using task start/stop and get a report at the end of the month, without leaving the terminal at all, which makes it so much easier to track time.

--

--

Juri Rischel Jensen
Juri Rischel Jensen

Written by Juri Rischel Jensen

This is the space for my thoughts and methods regarding my work, my hobbies and the way I train and eat.