Time tracking with Ledger
Whoever is reading this blog knows that I use Ledger-likes to track my finances. Some of you may also know that the currency is just some arbitrary name for any kind of unit. And a minority of you may also know there is special support for tracking time in the original Ledger program. This post explains how I use Ledger and a few Bash aliases to track different activities during a normal work day.
In a “regular” Ledger file you will find transactions that describe the flow of a commodity from one (or more) to another account at a certain time. There is however special support for timelog entries in the ledger program. They look similar but have special syntax to describe the start and end of a “transaction”
i 2019/03/02 00:30:20 Entertainment:Netflix
o 2019/03/02 00:35:20
which basically state what to account from i to o. Suppose you have a
timelog file foo.ledger then ledger -f time.ledger bal would give you
something like this:
9.07h Work
32.3m Mail
6.9m Admin
8.40h Development
1.69h Entertainment:Netflix
14.2m Drinking
11.9m Meetings
--------------------
11.19h
Of course, you can customize the date range and hierarchy depth. Let’s alias that to
All good. Now, adding new entries by “punching in” new lines like that above is more than just cumbersome, it’s something a simple alias could do as well. I have defined something like
where TIMELOG points to the time.ledger file. Once you type
an appropriate transaction will be made. To check what’s currently going on, this alias might help:
That all looks nice and dandy until you realize you don’t remember a particular activity you want to account you current time on. If you have used any CLI program you probably hit Tab more than twice. Wait no more, just define
and you are all set to complete the timelog entry while you clock in. You could write more elaborate logic in an appropriate scripting language but that’s an exercise for the reader.