Last active
March 24, 2016 16:23
-
-
Save mmcdaris/710ff13add5938e56ac5 to your computer and use it in GitHub Desktop.
rescuetime daily habits post-commit hook
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/sh | |
# more info on set -e https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html#The-Set-Builtin | |
set -e | |
## CREDIT | |
# I made this from: https://github.com/RescueTime/git-commits-to-rescuetime-daily-highlights/blob/master/post-commit.sample | |
# Thanks @robby1066 it's been fun fine tuning this | |
## INSTALLATION | |
# add this to any project's .git/hooks/ dir as post-commit | |
# chmod -x .git/hooks/post-commit | |
## GLOBAL INSTALLATION - Thanks to: JefRomi - http://stackoverflow.com/a/2293578/1332122 | |
# move this file to the global dir for templates in hooks: | |
# `export hook_dir="$(git config --global --get init.templatedir)/hooks"` ( usually /usr/local/share/git-core/templates/hooks on a mac) | |
# `mv post-commit $hook_dir` | |
# make executable: | |
# `chmod -x $hook_dir/post-commit` | |
# re-initialize your projects: | |
# run `git init` in the projects that already exist and post-commit will be copied to .git/hooks/post-commit | |
# Set your RESCUETIME_KEY | |
RESCUETIME_KEY=real_value | |
# [ you can generate a key at https://www.rescuetime.com/anapi/manage ] | |
# REQUIRED FIELDS - Today's date and commit message | |
MESSAGE=$(git log -1 HEAD --pretty=format:%s) | |
DATE_TODAY=$(date +"%Y-%m-%d") | |
# Label is not required | |
LABEL='git' | |
# you should do `gem install terminal-notifier` if you want local notifications | |
TERMINAL_NOTIFIER=$(which -a terminal-notifier | head -n 1) | |
if [$TERMINAL_NOTIFIER -f]; then | |
BID=com.rescuetime.RescueTime | |
NOTIFY="$TERMINAL_NOTIFIER | |
-title Highlight | |
-sender $BID | |
-message" | |
fi | |
# If the RESCUETIME_KEY is not empty then continue | |
if [$RESCUETIME_KEY -n ]; then | |
curl --data \ | |
"key=$RESCUETIME_KEY&highlight_date=$DATE_TODAY&description=$MESSAGE&source=$LABEL" \ | |
https://www.rescuetime.com/anapi/highlights_post \ | |
1>/dev/null 2>/dev/null | |
if [$TERMINAL_NOTIFIER -f]; then | |
$NOTIFY $MESSAGE | |
fi | |
else | |
echo "You need to set the RESCUETIME_KEY in the post-commit" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment