Gitlog Automagical Timesheet Filler Outer Redux

I’ve been using variations on this script for several years to spit out my git commit log in a timesheet-friendly format:

https://blog.clixel.com/post/111391696763/daily-git-log-for-your-timesheet

I’ve now refined it to a li’l bash script that has a few extra tricks up its sleeve:

# Usage:
#!/bin/bash
# Pulls git log for an author formatted for a timesheet

# Usage:
# gitlog = last 8 hours of commits
# gitlog 48 = last 48 hours of commits
# gitlog 2018-12-20 = all commits on 12/20/2018
# gitlog yesterday = all commits since yesterday
# gitlog 1 week ago = all commits since a week ago

# Your username
user="Nate"

# Default values if no args are sent
since="8.hours.ago"
until=""

# Regex to match 2018-12-20
re_date='^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$'

# Regex to match 5, 15, 150
re_hours='^[0-9]{1,3}$'

# Concatenate all args into single string (to allow for "1 week ago" without quotes)
args="$*"

if [ -n "$args" ]
then
	if [[ $args =~ $re_date ]]
	then
		echo "Log for $args (also in clipboard):"
		since="$args 00:00"
		until="$args 23:59"
	elif [[ $args =~ $re_hours ]]
	then
		echo "Log for last $args hours (also in clipboard):"
		since="$args.hours.ago"
	else
		echo "Log since $args (also in clipboard):"
		since="$args"
	fi
else
	# default
	echo "Log for last 8 hours (also in clipboard):"
fi
echo "----"

# Store output to var so we can spit it out to console then shove it in the clipboard
OUTPUT=$(git log --author=$user --since="$since" --until="$until" --all-match --format="%s" | sed "/Merge branch/d" | tail -r | tr "\n" "😂" | sed -e "s/😂/; /g" | sed -e "s/; $//g")
echo $OUTPUT
echo $OUTPUT | tr -d '\n' | pbcopy

You set your name in the script, drop it in your ~/bin dir and chmod +x it, then run gitlog from a repo dir with various options, the default being the last 8 hours, or you can specify a day. Your git commit messages are concatenated in a format I use on timesheets, ready to be pasted into whatever time-tracking program you prefer. e.g.:

$ gitlog
Log for last 8 hours (also in clipboard):
----
various copy updates; more readme blather; conf tweaks; remove jquery and inline js, show 10 recent posts w/ archive link, remove nav from header; add fab dev, bring back home link for footer nav

Not the most elegant script, could certainly be fancier—but I sure use the hell out of it as-is.