├── .gitignore ├── index.js ├── package.json ├── readme.md ├── test.js └── usage.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var homedir = require('home-dir') 4 | var fs = require('fs') 5 | var mkdirp = require('mkdirp') 6 | var prompt = require('prompt-sync') 7 | var child = require('child_process') 8 | var currentLocation = require('current-location') 9 | var args = require('minimist')(process.argv.slice(2)) 10 | 11 | var configPath = args.home || (homedir() + '/.config') 12 | var entries = configPath + '/gititude.txt' 13 | mkdirp.sync(configPath) 14 | 15 | var cmd = args._[0] 16 | 17 | if (!cmd) { 18 | console.error(fs.readFileSync(__dirname + '/usage.txt').toString()) 19 | process.exit(1) 20 | } 21 | 22 | if (cmd === 'set') { 23 | var lat = args.lat 24 | var lon = args.lon 25 | 26 | if (!lat || !lon) { 27 | if (!process.stdin.isTTY) process.exit(1) 28 | process.stdout.write('Latitude' + (lat ? ' (' + lat + ')' : '') + ': ') 29 | lat = prompt() || lat 30 | process.stdout.write('Longitude' + (lon ? ' (' + lon + ')' : '') + ': ') 31 | lon = prompt() || lon 32 | } 33 | 34 | var date = args.date 35 | if (!date) date = new Date() 36 | else date = new Date(date) 37 | appendEntry(lat, lon, date) 38 | } 39 | 40 | if (cmd === 'list') { 41 | fs.createReadStream(entries).on('error', function hayguyz () {}).pipe(process.stdout) 42 | } 43 | 44 | if (cmd === 'latest') { 45 | console.log(JSON.stringify(latest())) 46 | } 47 | 48 | if (cmd === 'commit') { 49 | var latest1 = latest() 50 | if (!latest1) throw new Error('Sorry sir or madam you must first do gititude set or update') 51 | var commit = child.spawn('git', process.argv.slice(2), {stdio: 'inherit'}) 52 | commit.on('exit', function (code) { 53 | if (code !== 0) return console.error('UHOH git exited non-zero') 54 | var tagId = 'gititude-' + +new Date() 55 | var tag = child.spawn('git', ['tag', '-m', JSON.stringify(latest1), tagId]) 56 | tag.on('exit', process.exit) 57 | }) 58 | } 59 | 60 | if (cmd === 'update') { 61 | currentLocation(function (err, loc) { 62 | if (err) throw new Error(err) 63 | if (!loc) throw new Error('Could not get location') 64 | var latestLoc = latest() 65 | if (latestLoc && latestLoc.latitude === loc.latitude && latestLoc.longitude === loc.longitude) { 66 | console.log('Already up to date') 67 | process.exit(0) 68 | } 69 | console.log('Adding new location to entry log', loc) 70 | appendEntry(loc.latitude, loc.longitude, new Date()) 71 | }) 72 | } 73 | 74 | function latest () { 75 | try { 76 | var stat = fs.statSync(entries) 77 | var fd = fs.openSync(entries, 'r') 78 | var buf = new Buffer(1024) 79 | var read = fs.readSync(fd, buf, 0, 1024, stat.size - 1024) 80 | buf = buf.slice(0, read) 81 | var lines = buf.toString().trim().split('\n') 82 | var latest = JSON.parse(lines[lines.length - 1]) 83 | return latest 84 | } catch (e) {} 85 | } 86 | 87 | function appendEntry (lat, lon, date) { 88 | date = date.toISOString() 89 | var location = JSON.stringify({latitude: lat, longitude: lon, timestamp: date}) + '\n' 90 | fs.createWriteStream(entries, {flags: 'a+'}).end(location) 91 | } 92 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gititude", 3 | "version": "2.1.1", 4 | "description": "add latitude and longitude to your git commits", 5 | "main": "index.js", 6 | "bin": { 7 | "gititude": "index.js" 8 | }, 9 | "keywords": [], 10 | "author": "max ogden", 11 | "license": "ISC", 12 | "scripts": { 13 | "test": "standard && node test.js" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/maxogden/gititude.git" 18 | }, 19 | "bugs": { 20 | "url": "https://github.com/maxogden/gititude/issues" 21 | }, 22 | "homepage": "https://github.com/maxogden/gititude#readme", 23 | "dependencies": { 24 | "current-location": "^1.1.0", 25 | "home-dir": "^1.0.0", 26 | "minimist": "^1.2.0", 27 | "mkdirp": "^0.5.1", 28 | "prompt-sync": "^3.0.0" 29 | }, 30 | "devDependencies": { 31 | "mkdirp": "^0.5.1", 32 | "rimraf": "^2.5.0", 33 | "standard": "^5.4.1", 34 | "tape": "^4.4.0", 35 | "tape-spawn": "^1.4.0" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # gititude 2 | 3 | add latitude and longitude to your git commits 4 | 5 | if you use `gititude commit` instead of `git commit` then you will get get git tags automatically added to your commits that contain your latest latitude and longitude 6 | 7 | ## install 8 | 9 | ``` 10 | npm i gititude -g 11 | ``` 12 | 13 | ## usage 14 | 15 | ``` 16 | gititude 17 | 18 | set (--lat --lon --date) manually add a new location to the log 19 | update try to set new latest location automatically 20 | list list all logged locations (stored in ~/.config) 21 | latest get latest location 22 | ``` 23 | 24 | you have to run either `gititude set` or `gititude update` to update your latest location 25 | 26 | on Mac you can use the [Monu](https://github.com/maxogden/monu) application and the [`run-every`](https://npmjs.org) module to do this in the background: `run-every 600 bash -c "gititude update || true"` 27 | 28 | then you can use `gititude commit` and it will automatically tag your commit with your latest location using git tags 29 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | var os = require('os') 2 | var test = require('tape') 3 | var spawn = require('tape-spawn') 4 | var mkdirp = require('mkdirp') 5 | var rimraf = require('rimraf') 6 | 7 | var bin = __dirname + '/index.js' 8 | var tmp = os.tmpdir() + '/gititude-tests' 9 | rimraf.sync(tmp) 10 | mkdirp.sync(tmp) 11 | 12 | test('set', function (t) { 13 | var g = spawn(t, bin + ' set --lat=5 --lon=5 --date=1 --home=' + tmp) 14 | g.stdout.empty() 15 | g.stderr.empty() 16 | g.end() 17 | }) 18 | 19 | test('latest', function (t) { 20 | var g = spawn(t, bin + ' latest --home=' + tmp) 21 | g.stdout.match('{"latitude":5,"longitude":5,"timestamp":"1970-01-01T00:00:00.001Z"}\n') 22 | g.stderr.empty() 23 | g.end() 24 | }) 25 | 26 | test('list', function (t) { 27 | var g = spawn(t, bin + ' latest --home=' + tmp) 28 | g.stdout.match('{"latitude":5,"longitude":5,"timestamp":"1970-01-01T00:00:00.001Z"}\n') 29 | g.stderr.empty() 30 | g.end() 31 | }) 32 | -------------------------------------------------------------------------------- /usage.txt: -------------------------------------------------------------------------------- 1 | gititude [--lat --lon --date] 2 | 3 | set manually add a new location to the log (stored in ~/.config) 4 | update set new latest location automatically using the system location (if available) 5 | list list all logged locations 6 | latest get latest location 7 | --------------------------------------------------------------------------------