Tracking time with the command line
I didn’t mean for the title of this post to rhyme, but hey why not.
I’ve spent years back and forth between Windows and Linux and always manged to land back on Windows for one reason or another. I’m quite happy to say that I’ve been using my linux installation now for atleast a year. I feel like it might be longer though. I rarely boot into Windows anymore and I’m finally starting to see the light even brighter.
Time tracking has always been a challenge. I’ve used all the different apps out there and for one reason or another I just stopped using them. Being a Linux convert for longer than my usual 2 months has really opened my eyes to the possibilities that working with Linux opens up. For starters, the simplicity of doing different things absolutely amazes me.
If you’ve been following along, you’ll know that I use Plain Text Accounting for my businesses and my personal finances. (I need to update my article on Plain Text Accounting as I’ve migrated to using HLedger for a few reasons). Time tracking is another trick of plain text accounting. I hadn’t initially used it as I found it cumbersome to enter time manually. I still enter transactions manually for my accounting needs but I found a pretty awesome script online for starting and stopping a timer in the command line.
My initial thinking is always the wrong way…
So to clarify my previous statement about simplicity, initially I set out to write my own script to track time in the command line. I was thinking it would be a counter or something that when ending would just post the transaction to my hledger file. I don’t know what it is but I wildly overcomplicated that.
It’s really quite simple. Instead of a complicated timer or counter running the entire time we’re working, all we need to do is post a transaction at the start time and an ending transaction when we’re done. Use our system time and that’s it.
I don’t know why I felt the need to share my overly complicated thoughts… but food for thought anyway maybe you’ll get something out of it.
I think this will shape the way I think about things and processes in the future. Simple always seems to “just work” in my experience.
The script
This script is so elegantly simple, it’s actually amazing. Or maybe I’m just fascinated by it’s simplicity Below is the man page
Usage: tt [COMMAND] [ARGS]
Track time
i|in "Time in" to begin a task. Args: [optional date] [task name]
o|out "Time out" to end a task. Args: [optional date]
s|stat Show the current status (last line in the timeclock file).
b|bal Show daily balances.
n|sw|next|switch End (time out of) the current task, and begin the next.
task. New task name is the next arg.
e|edit Edit the timeclock file with ${EDITOR}.
t|tail Show the last 10 lines of the ledger
So it’s quite simple to actually start tracking time
$ tt i Personal:Blog:Writing
Begin Personal:Blog:Writing at 2022-12-08 10:05:48
To stop it’s as simple as
tt o
If I forget to stop the timer, I can always open the file in any editor or just simple run
tt e
And the ledger file will open in my default text editor.
The script has even included some simple reporting.
Bal = Shows balance of hours total
d = Daily
w = weekly
q = Quarterly
Not sure what happened to monthly, but I’m sure it wouldn’t be hard to incorporate.
I also haven’t dug into hledger’s reporting on time, but the script does use native reporting commands.
That’s pretty much all I’ve got here on this. The simplicity is really what drives this for me. It just works, it doesn’t get in the way, it’s nearly everywhere I need it and it’s always ready.