Skip to content

Instantly share code, notes, and snippets.

@HashNuke
Last active November 28, 2024 13:00
Show Gist options
  • Save HashNuke/f4a051af581152e1e2b8ec2ecb495ed3 to your computer and use it in GitHub Desktop.
Save HashNuke/f4a051af581152e1e2b8ec2ecb495ed3 to your computer and use it in GitHub Desktop.
Put this in your $HOME directory. And then run it from any git repository.

howlong.sh

Usage

  1. Copy the script (scroll below) into $HOME directory on your linux or mac.
  2. Run the command below within any git repository.
bash ~/howlong.sh

Output should look something like this CleanShot 2024-11-28 at 19 54 18@2x

#!/bin/bash
# This script calculates and prints the first commit date and total days of effort in the current Git repository.
# Ensure we are in a git repository
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
echo "Error: Not inside a git repository. Please run this script from within a git repo."
exit 1
fi
# Get the first commit date
first_commit_date=$(git log --reverse --date=short --pretty=format:"%ad" | head -n 1)
# Check if there is any commit
if [ -z "$first_commit_date" ]; then
echo "Error: No commits found in this repository."
exit 1
fi
# Calculate the days since the first commit
first_commit_days=$(( ($(date +%s) - $(date -j -f "%Y-%m-%d" "$first_commit_date" +%s)) / 86400 ))
# Calculate total days of effort
days_of_effort=$(git log --date=short --pretty=format:"%ad" | sort -u | wc -l | xargs)
# Print the results
echo ""
echo "🏁 First commit $first_commit_days days ago"
echo "👷 $days_of_effort days of effort. Make money yet?"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment