Last active
October 29, 2024 15:21
-
-
Save natebeaty/b3edf108434a2d16cc600bd0686e92a8 to your computer and use it in GitHub Desktop.
script to pull your git commit logs for various date ranges, formatted for a timesheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Pulls git log entries for a day formatted for pasting in a timesheet | |
# Usage: | |
# gitlog = all commits today | |
# gitlog -2 = all commits -2 days ago | |
# gitlog 2024-10-03 or 10/3/2024 or 10-3 | |
args=$1 | |
# Replace / with - in args for alternate date formats e.g. 10/3/2024 | |
args=${args//\//\-} | |
# Default day to today if no args are sent | |
day=`date +%F` | |
# Convert various argument formats to YYYY-MM-DD | |
if [[ $args =~ ^[0-9]{1,4}\-[0-9]{1,2}\-[0-9]{1,2}$ ]]; then | |
# already in format needed | |
day=$args | |
elif [[ $args =~ ^[0-9]{1,2}\-[0-9]{1,2}$ ]]; then | |
# 10-10 -> 2024-10-10 | |
day=`date -jf %m-%d +%Y-%m-%d $args` | |
elif [[ $args =~ ^[0-9]{1,2}\-[0-9]{1,2}\-[0-9]{1,4}$ ]]; then | |
# 10-10-2024 -> 2024-10-10 | |
day=`date -jf %m-%d-%Y +%Y-%m-%d $args` | |
elif [[ $args =~ ^\-[0-9]{1,2}$ ]]; then | |
# -2 (days ago) | |
day=`date -v"$args"d +%F` | |
fi | |
# Store output to var so we can spit it out to console then shove it in the clipboard | |
logs=$(git log --all --author="`git config user.name`" --no-merges --format="%s %ai" | grep $day | perl -pe 's/ (\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2} \-\d{4})//g' | perl -pe 's/^(compiled assets|pedant|cleanup|typo)\n$//g' | tail -r | perl -pe 's/\n/; /' | sed -e "s/; $//g") | |
if [ "$logs" = "" ]; then | |
echo "No git logs found for $day" | |
else | |
echo -e "Log for $day (also in clipboard):\n----\n$logs" | |
echo -e $logs | pbcopy | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment