-
-
Save AndersonFirmino/7b184903d596e7d2ce4a81ed96a39493 to your computer and use it in GitHub Desktop.
Wakatime Git 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/bash | |
# NOTE: actually it would be nice to add something like the branch and SHA, but for the sake of demonstration I'm just using this file to feed Wakatime | |
# these variables are not used, but they might be useful; for someone else to play around | |
MESSAGE=$1 | |
SHA=$(git rev-parse HEAD) | |
BRANCH=$(git symbolic-ref --short HEAD) | |
# give it a name | |
PLUGIN="githook-wakatime/0.0.1" | |
# read the API key | |
API_KEY=$(awk '/^api_key/{print $NF}' ~/.wakatime.cfg) | |
# make sure we stay in this directory | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
# feed Wakatime with a file; anyone withh a better idea? | |
FILE="$DIR/post-commit" | |
# download Wakatime CLI if necessary | |
if [ ! -d "$DIR/wakatime" ]; | |
then | |
mkdir "$DIR/wakatime" | |
wget -t 30 -w 5 --waitretry 20 --random-wait -O - https://github.com/wakatime/wakatime/archive/master.tar.gz | tar -C "$DIR/wakatime" --strip-components=1 -zxv | |
fi | |
# NOTE: in case you want to test more then enable this line | |
#python wakatime/wakatime-cli.py --write --verbose --logfile wakatime.log --file "$FILE" --key "$API_KEY" --plugin "$PLUGIN" | |
python "$DIR/wakatime/wakatime-cli.py" --write --file "$FILE" --key "$API_KEY" --plugin "$PLUGIN" | |
# optionally you could provide the --project parameter here to aggregate the stats in a separate project; | |
# maybe there will be a better solution once Alan has implemented the categories feature |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment