#!/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)) echo -e "changes\tbld t\tbrk t\tbreaks" echo "===============================================" i=$((0)) breaks=$((0)) break_seconds=$((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) ((breaks++)) fi echo -ne "\r${i}\t${build_seconds}\t${break_seconds}\t${breaks}" fi ((i++)) done echo echo "Active build time: $(date -ud "@$build_seconds" +"$(( $build_seconds/3600/24 )) days %H hours %M minutes %S seconds") (estimated)" head_timestamp=$(git -C "$GIT_DIR" log --format=format:%at | head -1) tail_timestamp=$(git -C "$GIT_DIR" log --format=format:%at | tail -1) total_build_seconds=$(echo "${head_timestamp}-${tail_timestamp}" | bc) echo "Total build time: $(date -ud "@$total_build_seconds" +"$(( $total_build_seconds/3600/24 )) days %H hours %M minutes %S seconds")"