Skip to content

Instantly share code, notes, and snippets.

@mktcode
Last active October 9, 2025 07:48
Show Gist options
  • Select an option

  • Save mktcode/d055e558b644241a40ee9d7b1b943689 to your computer and use it in GitHub Desktop.

Select an option

Save mktcode/d055e558b644241a40ee9d7b1b943689 to your computer and use it in GitHub Desktop.
A very simple time tracking tool for the command line.
# Time Tracking Tool
####################
# Simply writes dates/times/comments in a file.
# Each week has it's own file (e.g. ~/.ttt/2019-01.txt).
#
# ttt <comment>: add entry to current week's file
# tttt: output current week's file content with cat
# ttte: edit current week's file with vim
# tttp: pause
# ttts: sum times
ttt() {
mkdir -p ~/.ttt
file="/home/$USER/.ttt/$(date +"%Y-%W").txt"
echo `date '+%Y-%m-%d %H:%M'`" | "$* >> $file
printf "Added time tracking entry:\n"
tail -1 $file
}
alias tttt='cat ~/.ttt/$(date +"%Y-%W").txt'
alias ttte='vim ~/.ttt/$(date +"%Y-%W").txt'
alias tttp='ttt pause'
alias ttts='awk '"'"'BEGIN{ FS=" *\\| *" }
function to_epoch(s, cmd, out){
cmd = "date -d \"" s "\" +%s";
cmd | getline out; close(cmd);
return out + 0;
}
{
dt = $1; # "YYYY-MM-DD HH:MM"
key = $2; # alles hinter dem |
gsub(/^[ \t]+|[ \t]+$/, "", key);
t = to_epoch(dt);
if (have_last && last_key != "pause")
times[last_key] += (t - last_time);
last_time = t;
last_key = key;
have_last = 1;
}
END{
for (k in times)
printf "%-20s %.2f Std\n", k, times[k]/3600;
}
'"'"' ~/.ttt/$(date +"%Y-%W").txt'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment