ttag
- Simple time tracking π
Since I’m working a lot in a CLI, and need to keep track of time and events, I’ve made this very simplistic time and event tracking utility.
It’s based on a small script that appends a logfile.
You need three things:
- a logfile path
- the
ttag.sh
-script - adding
alias
-es to eg~/.bashrc
Logfile π
The logfile is just a text file. You need to determine the absolute path to it and add that to the ttag.sh
script.
Eg in /cygdrive/c/Dropbox/tools/ttag/ttag-logfile.txt
as I do on Windows + Cygwin.
ttag.sh
π
First, adjust the path to LOGFILE
if necessary.
The script should be placed somewhere, doesn’t matter much where. Just adopt the path to this in the alias.
#!/bin/sh
#
# simple script to add timestamp to a log to keep track of time
# has two timestamps, first to be able to read quickly, second to
# make it easier to calc timediffs -> activity duration
#
# make an alias
# alias ttag='/cygdrive/c/tools/ttag/ttag.sh'
# alias ttagcat='cat /cygdrive/c/tools/ttag/ttag-logfile.txt'
# then run it like so,
# > ttag project1 installing tools
# > ttag project1 conference call
# > ttag lunch
# > ttag -lunch
#
# > ttagcat
# 2017-03-13 11.32.27 - 1489401147: project1 isntalling tools
# 2017-03-13 11.32.28 - 1489401148: project1 conference call
# 2017-03-13 11.32.28 - 1489401148: lunch
# 2017-03-13 11.32.28 - 1489401148: -lunch
#
#
# example log entry
# Mon 2017-03-13 13.37.00 - 143242334211: husq installing tools
# %F full date; same as %Y-%m-%d
# %s seconds since 1970-01-01 00:00:00 UTC
# date +"%F %H.%M.S - %s:"
# specify the logfile
LOGFILE=/cygdrive/c/Dropbox/tools/ttag/ttag-logfile.txt
# timestamp format
TIMESTAMP_NICE=$(date +"%F %H.%M.%S - %s:")
# always append to the logfile
echo $TIMESTAMP_NICE "$@" >> $LOGFILE
Adding aliases π
The aliases makes it easier to run the utility.
#------------------------------------------------------------------------------
# time-tag utility
#
# This below goes into your ~/.bashrc
#
# simple utility that appends to a log, to be able to check for how
# long time an activity lasted
#
# usage
# ttag PROJECT ACTIVITY
# eg
# ttag apiary installing tools
# ttag apiary setting up branch and stuff
# ttag lunch
# ttag back
# ttagcat
alias ttag='/cygdrive/c/Dropbox/tools/ttag/ttag.sh'
alias ttagcat='cat /cygdrive/c/Dropbox/tools/ttag/ttag-logfile.txt'
alias ttago='open /cygdrive/c/Dropbox/tools/ttag/ttag-logfile.txt'
Github gist π
There’s a Github gist that holds the ttag.sh
and the contents to add to ~/.bashrc
. Do note that you need to adjust the path to both ttag.sh
and the logfile. I’ve chosen to put it on dropbox for direct sync across devices.
Usage π
Here’s how to use it.
Adding notes π
> ttag starting on project X
> ttag going to lunch
> ttag back from lunch
Reading notes π
The alias ttagcat
will print out the file. Pipe it to eg tail -n 10
for the last ten lines if you prefer.
> ttagcat
2022-04-05 13.18.00 - 1649157480: projectX starting
2022-04-05 13.19.11 - 1649157551: lunch
2022-04-05 13.19.21 - 1649157561: -lunch
Open the logfile in a text editor π
In Cygwin, I’ve aliased cygstart
=== open
. This is the same as double-clicking (opening) the file in File Explorer, which opens it using the registered application.
alias open='cygstart'
Hence, we simply do ttago
which opens the file in an editor.
Calculating time π
This functionality is not included in the ttag
utility here, but when appending, there are two timestamps added. First is in human-readable format, second one is in epochs and easier to work with programmatically. Parsing is made easier by separating timestamps from comments with :
.