Skip to content

Instantly share code, notes, and snippets.

@CameronBanga
Created June 15, 2016 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CameronBanga/0c03f2174fb9fa8b0264e262b13fc279 to your computer and use it in GitHub Desktop.
Save CameronBanga/0c03f2174fb9fa8b0264e262b13fc279 to your computer and use it in GitHub Desktop.
#!/bin/bash
TERM=xterm-color
# Set a Date
NOW=$(date +"%F")
# The name to give you at the top of your text file.
name="Cameron"
# The author email set in your global git config.
author=$(git config --global user.email)
# The username of your macOS account. I use cmbang on my Mac.
macuseraccount="cmbang"
# I'm creating a new directory in my Documents folder called GitHistory if necessary, to store all of my work journals.
# Feel free to move this to Dropbox, etc.
githistorypath="/Users/$macuseraccount/Documents/GitHistory"
mkdir -p $githistorypath
# Create a new log, and give it a title.
printf $name"'s Git Log for $NOW \n\n" >> $githistorypath/$NOW.txt
# Run through the contents of your Home directory, looking for git directories, and then adding the commits from the past 24 hours to a log
# This can take a while if you have a lot of files, so feel free to refine your directory here under find, to speed up.
# I personally limit the search to /Users/cmbang/Documents/
for i in $(find /Users/$macuseraccount/ -name ".git");
do
directory="$i"
name=$(echo ${directory#/Users/$macuseraccount/})
shortname=$(echo $name | sed 's/\(.*\)...../\1/')
git --git-dir=$directory log --pretty=format:"$shortname - %h - %ai : %s" --author=$author --since=24.hour >> $githistorypath/$NOW.txt
done
# Remove some ISO timestamp stuff because I think it looks messy
sed -i.bak s/-0500\ //g $githistorypath/$NOW.txt
rm $githistorypath/*.txt.bak
# This adds the journal to my DayOne 2 journal. Feel free to skip this if you don't use it. Also, I run this script
# As a cron job at 9am everyday, to pick up the past 24 hours, and then create a new journal entry for the previous day
# by adding -d="yesterday" right after the -j flag, and before the new commany.
dayone -j="/Users/$macuseraccount/Library/Group Containers/5U8NS4GX82.dayoneapp2/Data/Auto Import/Default Journal.dayone" new < $githistorypath/$NOW.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment