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:

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

# Usage:
# 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

# Default values if no args are sent

# Regex to match 2018-12-20

# Regex to match 5, 15, 150

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

if [ -n "$args" ]
	if [[ $args =~ $re_date ]]
		echo "Log for $args (also in clipboard):"
		since="$args 00:00"
		until="$args 23:59"
	elif [[ $args =~ $re_hours ]]
		echo "Log for last $args hours (also in clipboard):"
		echo "Log since $args (also in clipboard):"
	# default
	echo "Log for last 8 hours (also in clipboard):"
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.