Skip to content

Instantly share code, notes, and snippets.

@matiasw
Created June 24, 2015 11:54
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 matiasw/c90c4248659a6bffce03 to your computer and use it in GitHub Desktop.
Save matiasw/c90c4248659a6bffce03 to your computer and use it in GitHub Desktop.
geotag for git commit messages
This other day, I wanted to add a geotag to my git commits - like a character in Stephenson's Cryptonomicon has for email. Here's how I did it:
Requirements:
- jq
- nmcli
- perl
First, create a directory for git templates (eg. ~/.git). Then point git to globally use that directory: `git config --global init.templatedir ~/.git`
Then create a prepare-commit-msg hook:
~/.git/hooks/prepare-commit-msg:
echo "Made at meatspace coordinates " >> "$1"
~/getgeotag.sh > /tmp/geotag
echo "Latitude: " `jq '.location.lat' /tmp/geotag` >> "$1"
echo "Longitude: " `jq '.location.lng' /tmp/geotag` >> "$1"
Now let's create the scripts.
~/getgeotag.sh:
curl `~/getgeotag_url.sh`
~/getgeotag_url.sh:
echo "https://maps.googleapis.com/maps/api/browserlocation/json?browser=firefox&key=AIzaSyDBgL8fm9bD8RLShATOLI1xKmFcZ4ieMkM&sensor=true&"`~/getgeotag_url_params.sh`
~/getgeotag_url_params.sh:
nmcli -f SSID,BSSID,SIGNAL,CHAN dev wifi list |perl -ne "if(s/^(.+?)\s+(..:..:..:..:..:..)\s+(.+?)\s+(.+?)\s*$/wifi=mac:\2|ssid:"$(perl -MURI::Escape -e 'print uri_escape(\1);' "$2")"|signalStrength:\3|age:0|channel:\4|signalToNoiseRatio:50&/g){print;}"
And that's it! Now git init in any repo to make it use this as a commit message template (if it does not work, check to see if you already have a .git/hooks/prepare-commit-msg).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment