Skip to content

Instantly share code, notes, and snippets.

@vidakovic
Created February 3, 2015 21:57
Show Gist options
  • Save vidakovic/f3c04988aad928e9f3fd to your computer and use it in GitHub Desktop.
Save vidakovic/f3c04988aad928e9f3fd to your computer and use it in GitHub Desktop.

Revisions

  1. vidakovic created this gist Feb 3, 2015.
    32 changes: 32 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/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