programmer challenge: write a script which, when given a file in the current git repository, outputs the average age of the lines in the file
bonus challenge: implement a toggle to include or exclude blank lines
@jamey `systime()` isn’t POSIX but i imagine that’s doable to replace? awk probably is the easiest solution here huh
@Lady there's always the approach of sticking '$(date +%s)'
there instead 😁
@jamey or
("date +%s" | getline); print ($0 - mean) / 86400
worked for me if you want to keep it in awk 😂
(macOS uses a fork of "The One True AWK”, not GNU awk, by default so the question isn’t purely hypothetical)
@Lady that's a delightful option too! I just take way too much pleasure in metaprogramming things that weren't meant to be metaprogrammed. 😅 and yeah, I assumed you were asking due to being on one of the BSD-ish platforms, which is a totally reasonable constraint
@Lady interesting challenge! this prints the average age of the lines in
$filename
, in days:git blame --line-porcelain "$filename" | grep '^author-time ' | awk '{ mean += ($2 - mean) / NR } END { print (systime() - mean) / 86400 }'
excluding blank lines is a little trickier but the
--line-porcelain
output does have enough information to do it