Skip to content

Commit 4107226

Browse files
nexusuwnexus-uw
authored andcommitted
Set status bar text to show the uncommitted time
- check that gtm is at least v1.0-beta.8 - did some more refactoring - bumped to 0.0.3
1 parent 47a4f58 commit 4107226

3 files changed

Lines changed: 72 additions & 55 deletions

File tree

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ From [git-time-metric/gtm](https://github.com/git-time-metric/gtm)
1414

1515
## Requirements
1616

17-
1. ```gtm``` must be installed locally and accessible on the ```$PATH``` ([installation instructions](https://github.com/git-time-metric/gtm#install-the-latest-gtm-release))
18-
2. In VSCode, open the command pallet, and type ```>ext install vscode-gtm```
17+
1. ```gtm``` must be installed locally, be at least 1.0.beta.8 and accessible on the ```$PATH``` ([installation instructions](https://github.com/git-time-metric/gtm#install-the-latest-gtm-release))
18+
2. In VSCode, open the command pallet, type ```>ext install``` and then search for ```vscode-gtm```
1919

2020
## Extension Settings
2121

@@ -27,6 +27,10 @@ only tested on Ubuntu, so may not work on OSX, other Linuxs, and/or Windows
2727

2828
## Release Notes
2929

30+
### 0.0.3
31+
32+
Status bar now shows total uncommitted time
33+
3034
### 0.0.2
3135

3236
Improved reporting logic to factor in changing current text file
@@ -35,7 +39,5 @@ Improved reporting logic to factor in changing current text file
3539

3640
Initial release of vscode-gtm
3741

38-
39-
4042
### Notes
4143
Logo belongs to https://github.com/git-time-metric/gtm

package.json

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
{
2-
"name": "vscode-gtm",
3-
"displayName": "vscode-gtm",
4-
"description": "VSCode plugin to support Git Time Metrics",
5-
"version": "0.0.2",
6-
"publisher": "s3ramsay",
7-
"license": "MIT",
8-
"engines": {
9-
"vscode": "^1.0.0"
10-
},
11-
"categories": [
12-
"Other"
13-
],
14-
"activationEvents": [
15-
"*"
16-
],
17-
"keywords":[
18-
"gtm",
19-
"git time metrics",
20-
"time tracking"
21-
],
22-
"icon":"GTMLogo-128.png",
23-
"main": "./out/src/extension",
24-
"contributes": {
25-
},
26-
"scripts": {
27-
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
28-
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
29-
"postinstall": "node ./node_modules/vscode/bin/install",
30-
"test":"node ./node_modules/vscode/bin/compile"
31-
},
32-
"devDependencies": {
33-
"typescript": "^1.8.5",
34-
"vscode": "^0.11.0"
35-
}
2+
"name": "vscode-gtm",
3+
"displayName": "vscode-gtm",
4+
"description": "VSCode plugin to support Git Time Metrics",
5+
"version": "0.0.3",
6+
"publisher": "s3ramsay",
7+
"license": "MIT",
8+
"engines": {
9+
"vscode": "^1.0.0"
10+
},
11+
"categories": [
12+
"Other"
13+
],
14+
"activationEvents": [
15+
"*"
16+
],
17+
"keywords": [
18+
"gtm",
19+
"git time metrics",
20+
"time tracking"
21+
],
22+
"icon": "GTMLogo-128.png",
23+
"main": "./out/src/extension",
24+
"contributes": {},
25+
"scripts": {
26+
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
27+
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
28+
"postinstall": "node ./node_modules/vscode/bin/install",
29+
"test":"node ./node_modules/vscode/bin/compile"
30+
},
31+
"devDependencies": {
32+
"typescript": "^1.8.5",
33+
"vscode": "^0.11.0"
34+
}
3635
}

src/extension.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
'use strict';
2+
23
import * as vscode from 'vscode';
3-
var spawn = require('child_process').spawn;
4-
5-
function run_cmd(cmd, args, callBack) {
6-
var child = spawn(cmd, args);
7-
var resp = "";
8-
child.on('error', function (code) { console.error('error', resp); callBack(code) });
9-
child.stdout.on('data', function (buffer) { resp += buffer.toString() });
10-
child.on('close', function (code) {console.log(resp) ;callBack(code) });
4+
const spawn = require('child_process').spawn;
5+
6+
interface Result {
7+
code: number;
8+
output: string;
9+
}
10+
11+
function run_cmd(cmd: string, args: string[]): Promise<Result> {
12+
const child = spawn(cmd, args);
13+
let output = "";
14+
return new Promise((resolve, reject) => {
15+
child.on('error', (code: number) => {
16+
console.error('error', output);
17+
reject(<Result>{ code, output });
18+
});
19+
child.stdout.on('data', (buffer) => output += buffer.toString());
20+
child.stderr.on('data', (buffer) => output += buffer.toString()); // since gtm -v outputs to stderr on ubuntu....
21+
child.on('close', (code: number) => resolve(<Result>{ code, output }));
22+
});
1123
}
1224

1325
export function activate(context: vscode.ExtensionContext) {
1426
// check if gtm is installed + avaliable
15-
run_cmd('gtm', [], (res) => {
16-
if (res < 0) {
17-
vscode.window.showErrorMessage('gtm is not avaliable on your $PATH. please install it first');
18-
}
19-
});
27+
run_cmd('gtm', ['-v'])
28+
.then((res: Result) => {
29+
if(res.output < 'v1.0-beta.8'){
30+
vscode.window.showWarningMessage('Installed gtm version is below v1.0-beta.8. Please update your gtm installation.');
31+
}
32+
}, (res: Result) => {
33+
if (res.code < 0) {
34+
vscode.window.showErrorMessage('gtm is not avaliable on your $PATH. please install it first');
35+
}
36+
});
2037
let subscriptions: vscode.Disposable[] = [];
21-
22-
2338
let lastUpdated: Date = new Date();
2439
let lastSavedFileName: string;
2540
const MIN_UPDATE_FREQUENCE_MS = 30000; // 30 seconds
@@ -28,7 +43,8 @@ export function activate(context: vscode.ExtensionContext) {
2843
const now = new Date();
2944
// if a new file is being saved OR it have been at least MIN_UPDATE_FREQUENCE_MS, record it
3045
if (fileName !== lastSavedFileName || (now.getTime() - lastUpdated.getTime()) >= MIN_UPDATE_FREQUENCE_MS) {
31-
run_cmd('gtm', ['record', lastSavedFileName], () => { });
46+
run_cmd('gtm', ['record', '--status', lastSavedFileName])
47+
.then((res: Result) => vscode.window.setStatusBarMessage(res.output));
3248
lastSavedFileName = fileName;
3349
lastUpdated = now;
3450
}
@@ -44,4 +60,4 @@ export function activate(context: vscode.ExtensionContext) {
4460
vscode.window.onDidChangeActiveTextEditor((e:vscode.TextEditor) => handleUpdateEvent(e.document.fileName), this, subscriptions);
4561
}
4662

47-
// always active, so no need to deactivate
63+
// always active, so no need to deactivate

0 commit comments

Comments
 (0)