#!/usr/bin/env bash if [[ $# -lt 1 ]] then echo "Usage: ./build-time " echo -e "\texample: ./build-time ~/doom/WIP/my-wad.wad" exit 1 fi MAP_FILENAME=$(basename "$1") GIT_DIR=$(echo ${1::-"$((${#MAP_FILENAME} + 1))"}) max_break_minutes=30 max_break_seconds=$((max_break_minutes*60)) i=$((0)) build_seconds=$((0)) build_intervals=() for timestamp in $(git -C "$GIT_DIR" log --reverse --format=format:%at) do # Prime the pump if [[ $i -eq 0 ]] then build_intervals+=($timestamp) else prev_timestamp="${build_intervals[((i-1))]}" seconds=$(echo "(${timestamp}-${prev_timestamp})" | bc) build_intervals+=($timestamp) if [[ $seconds -lt $max_break_seconds ]] then ((build_seconds+=$seconds)) else break_seconds=$(echo "(${timestamp}-${prev_timestamp})" | bc) fi fi ((i++)) done echo "Active build time: $(date -ud "@$build_seconds" +"$(( $build_seconds/3600/24 )) days %H hours %M minutes %S seconds") (estimated)"