Skip to content

Instantly share code, notes, and snippets.

@fitnr
Created December 28, 2015 23:23
Show Gist options
  • Save fitnr/0d472fa298afe33fa113 to your computer and use it in GitHub Desktop.
Save fitnr/0d472fa298afe33fa113 to your computer and use it in GitHub Desktop.
git tool for converting log to ICS file
# git-ics
# Place in your $PATH (e.g. ~/bin)
# Accepts any options that can be passed to git log
# usage: git ics [opts] > cal.ics
echo BEGIN:VCALENDAR
echo METHOD:PUBLISH
echo VERSION:2.0
echo PRODID:-//git-ics//git-ics//EN
echo CALSCALE:GREGORIAN
git log --date=iso8601 --pretty="hash:%H%ndate:%ad%nsummary:%s%n" "$@" | \
while read -r line; do
prefix=$(cut -f 1 -d: <<< "$line")
content=$(cut -f 2- -d: <<< "$line")
# if commit
if [ "$prefix" == "hash" ]; then
echo BEGIN:VEVENT
echo UID:$content
echo LOCATION:$content
fi
# if date
if [ "$prefix" == "date" ]; then
DATE=$(date -juf "%Y-%m-%d %H:%M:%S %z" "$content" +"%Y%m%dT%H%M%SZ")
echo DTEND:$DATE
echo DTSTART:$DATE
fi
# if summary
if [ "$prefix" == "summary" ]; then
echo SUMMARY:$content
fi
if [ "$prefix" == "" ]; then
echo END:VEVENT
fi
done
echo END:VCALENDAR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment