Track time via the Linux ter­mi­nal

Keep­ing track of the time you spend on a project may seem like a Her­culean task in it­self. Thank­fully, Shashank Sharma has a quick and easy so­lu­tion.

APC Australia - - Contents -

Un­less you’re very, very or­gan­ised, you’re un­likely to be able to ac­cu­rately de­scribe the amount of time you spend on any given task per­formed over any given pe­riod. Keep­ing care­ful track of the amount of time spent on a task be­comes a pri­or­ity if you plan to bill clients on an hourly ba­sis.

A time-track­ing app can be used to help make sense of how you spend the hours at work. This data can help you iden­tify ar­eas where you need to in­crease your pro­duc­tiv­ity. You might re­alise you’re tak­ing rather long lunches or spend­ing too much time on re­search, and not enough re­spond­ing to emails (although, of course, we all know that some emails can be safely ig­nored [Care­ful­now...—Ed] or bet­ter still, deleted im­me­di­ately).

Wat­son is a com­mand-line util­ity writ­ten in Python and re­leased un­der the MIT Li­cense. It en­ables you to eas­ily track the time spent on projects and as­sign­ments. It can then gen­er­ate re­ports on the col­lected data and re­veal how you spent the work hours on any given day, week, month or even an year.


The project is hosted on GitHub and you can eas­ily clone the repos­i­tory and in­stall Wat­son. For most dis­tri­bu­tions, an eas­ier in­stal­la­tion op­tion is to use the pip pack­age man­ager. If you don’t al­ready have it in­stalled, you can run the sudo apt in­stall pip or su -c ‘dnf in­stall pip’ com­mand on your Ubuntu and Fe­dora ma­chines. Most other dis­tri­bu­tions also pro­vide pip in their repos­i­to­ries and you can in­stall it with­out has­sles. You can then in­stall Wat­son with sudo pip in­stall td-wat­son . This will au­to­mat­i­cally fetch and in­stall the tool in the ‘~/.lo­cal/ bin’ di­rec­tory. Be­cause this di­rec­tory isn’t de­scribed in $PATH, you can’t use Wat­son just yet. Run the echo ‘ex­port PATH=”$ HOME/.lo­cal/ bin:$ PATH”’ >> ~/.bashrc

com­mand, which adds this path to your .bashrc file. You must now reload the .bashrc file with the source

.bashrc com­mand. One of the best fea­tures of Bash is its tab-com­ple­tion and you can con­fig­ure Wat­son for tab-com­ple­tion by down­load­ing the wat­son. com­ple­tion file from the GitHub repos­i­tory and plac­ing it in the ‘/etc/ bash. com­ple­tion.d/’ di­rec­tory. When you restart the shell ter­mi­nal, you’ll be able to use tab-com­ple­tion with Wat­son. To be­gin, type wat­son [tab] [tab] in the ter­mi­nal for a list of all avail­able com­mands.

For each task you wish to record with Wat­son, you must spec­ify a project name and you can have sev­eral dif­fer­ent tasks within each project. For in­stance, a project named Leisure can be used to track the amount of time you spend on non-work ac­tiv­i­ties. Here, read­ing and video games are tasks within the project. These tasks within a project are re­ferred to as tags. You can use the same tags across dif­fer­ent projects. Ev­ery time you run the wat­son

start com­mand, the project records all the rel­e­vant data such as the name of the project, the rel­e­vant tags and the start time and stores it in what the project refers to as frames.

When you run the wat­son stop com­mand, the project stops record­ing and prints out the frame id for the last recorded ses­sion. You can get a list of all the recorded frames by run­ning the wat­son frames com­mand. The name of the frame it­self doesn’t re­veal any in­for­ma­tion about the data it con­tains, such as the project name or the start and stop times.


Be­fore you can be­gin gen­er­at­ing re­ports of how you spend your work hours, you must first iden­tify the dif­fer­ent projects and tasks you wish to record with Wat­son. Then you can start record­ing a ses­sion with the wat­son start pro­ject­name +tags . Each start com­mand sup­ports the use of sev­eral tags:

$ wat­son start Leisure +read­ing

Start­ing project Leisure [read­ing] at 19:53

The first com­mand tells Wat­son to record a project named Leisure. The use of +tags is op­tional, but we’ve used it here to iden­tify the type of leisure ac­tiv­ity. Wat­son will pro­vide the name of the frame for the most re­cently recorded ac­tiv­ity when you run the stop com­mand: $ wat­son stop Stop­ping project Leisure [read­ing], started 12 min­utes ago. (id: c382b06)

Wat­son uses a new frame for ev­ery new start com­mand, even if you restart an al­ready ex­ist­ing project. You can use mul­ti­ple tags with the start com­mand, or use dif­fer­ent tags for the same project at a later time, like us­ing the +Cof­fee and +Lunch tags at dif­fer­ent time to record the Breaks you take dur­ing the day: $ wat­son start Break +lunch Start­ing project Break [lunch] at 13:15 $ wat­son stop Stop­ping project Break [lunch], started 30 min­utes ago. (id: 0d8583d)

$ wat­son start Break +”evening tea”

Start­ing project Break [evening tea] at 19:25

As you can see, we’ve used the Break project but with dif­fer­ent tags each time. You can run the wat­son

frames and the wat­son projects com­mands to re­spec­tively fetch a list of all the frames and projects. Don’t worry about sev­eral frames ex­ist­ing for the same project and tags. When gen­er­at­ing re­ports, Wat­son will au­to­mat­i­cally add the amount of time spent on any project or task across dif­fer­ent frames.


You can use Wat­son to gen­er­ate daily, weekly or monthly re­ports. If you want re­ports for a spe­cific project only, or for a spe­cific pe­riod, like say 50 days, you can do that as well. The wat­son re­port com­mand will dis­play all the project’s de­tails: $ wat­son re­port Thu 15 Fe­bru­ary 2018 -> Thu 22 Fe­bru­ary 2018 Break - 2h 23m 34s [evening tea 2h 23m 34s] Doc­tor’s-Visit - 2h 21m 11s APC452 - 30h 04m 08s [Roundup 17h 01m 37s] [Tu­to­rial 13h 02m 31s] Leisure - 1h 04m 11s [comics 02m 32s] [read­ing 1h 04m 11s] Lunch - 1h 20m 48s [break 1h 20m 48s] To­tal: 36h 22m 38s

If look­ing at the above data makes you ques­tion our evening tea habits, don’t! By de­fault, Wat­son pro­vides the data for the past seven days. The block here is for the pe­riod be­tween 15 and 22 Fe­bru­ary. As you can see, it shows a lunch of only one hour 20 min­utes, which means we for­got to record the lunch on more than one oc­ca­sion dur­ing the week.

Should you wish to edit a frame, such as when you con­tin­ued work­ing on a project af­ter stop­ping Wat­son, you can run the wat­son edit frameid com­mand, which opens the rel­e­vant frame in the con­fig­ured text ed­i­tor, and you can then change the stop/start times. You can also re­name a project or tag with the wat­son re­name com­mand.

You can run the wat­son re­port -m com­mand for a list of all the projects you worked on in the cur­rent month. You can sim­i­larly gen­er­ate re­ports for a spe­cific tag or project us­ing the -T or the -p op­tions with re­ports:

$ wat­son re­port -T Roundup -m

Thu 01 Fe­bru­ary 2018 -> Thu 22 Fe­bru­ary 2018 APC453 - 17h 01m 37s [Roundup 17h 01m 37s] APC454 - 9h 51m 36s [Roundup 9h 51m 36s] To­tal: 26h 53m 13s Here, we’ve com­bined switches to gen­er­ate re­ports on a tag for the cur­rent month. Since we used the same tag across dif­fer­ent projects, Wat­son au­to­mat­i­cally re­ports the data for both projects.

Wat­son doesn’t iden­tify frames us­ing the project name, so you must run the

wat­son log com­mand for a list of all the Wat­son com­mands you’ve run. This will pro­vide you a date list of all the frames (lat­est first), and the cor­re­spond­ing project/tag name, etc.

It’s easy to see the ap­peal for a project like Wat­son, even if you’re not re­quired to keep time sheets. You might even be sur­prised at what it has to re­port at the end of the work­ing week. Now, about those emails...

Some com­mands have many op­tions and Wat­son pro­vides spe­cific op­tions for each with the --help switch: wat­son re­port --help.

You can use tab-com­ple­tion for the name of the com­mands such as start and re­port and also for the names of the projects and tags.

Newspapers in English

Newspapers from Australia

© PressReader. All rights reserved.