Skip to content

Commit ada383b

Browse files
committed
Display total time spent for uncommitted work in the status bar
1 parent 3a756d4 commit ada383b

3 files changed

Lines changed: 122 additions & 15 deletions

File tree

README.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,72 @@
33

44
Git Time Metrics (GTM) is a tool to automatically track time spent reading and working on code that you store in a Git repository. By installing GTM and using supported plug-ins for your favorite editors, you can immediately realize better insight into how you are spending your time and on what files.
55

6-
### Installation
6+
# Installation
77

88
Installing GTM is a two step process. First, it's recommended you install the GTM executable that the plug-in integrates with and then install the Sublime 3 GTM plug-in. Please submit an issue if you have any problems and/or questions.
99

10-
1. Follow the [Getting Started](https://github.com/git-time-metric/gtm/blob/master/README.md) section to install the GTM executable for your operating system.
10+
1. Follow the [Getting Started](https://github.com/git-time-metric/gtm/blob/master/README.md) section to install the GTM executable for your operating system.
1111
2. Install the plug-in via [Package Control](https://packagecontrol.io).
12+
13+
# Features
14+
15+
### Status Bar
16+
17+
In the status bar see your total time spent for in-process work (uncommitted).
18+
19+
![](https://cloud.githubusercontent.com/assets/630550/16570803/e25a7980-4212-11e6-9e7a-a6eff4be118c.png)
20+
21+
This can be disabled by setting `gtm_status_bar: false` in gtm.sublime-settings.
22+
23+
*Note* - the time shown is based on the file's path and the Git repository it belongs to. You can have several files open that belong to different Git repositories. The status bar will display the time for the current file's Git repository. Also keep in mind, a Git repository must be initialized for time tracking in order to track time.
24+
25+
Consult the [README](https://github.com/git-time-metric/gtm/blob/master/README.md) and [Wiki](https://github.com/git-time-metric/gtm/wiki) for more information.
26+
27+
### Command Line Inteface
28+
29+
Use the command line to report on time logged for your commits.
30+
31+
Here are some examples of insights GTM can provide you.
32+
33+
**Git commits with time spent**
34+
35+
```
36+
9361c18 Rename packages
37+
Sun Jun 19 09:56:40 2016 -0500 Michael Schenk 34m 30s
38+
39+
341bd77 Vagrant file for testing on Linux
40+
Sun Jun 19 09:43:47 2016 -0500 Michael Schenk 1h 16m 0s
41+
42+
792ba19 Require a 40 char SHA commit hash
43+
Thu Jun 16 22:28:45 2016 -0500 Michael Schenk 1h 1m 0s
44+
```
45+
46+
**Git commits with detailed time spent by file**
47+
48+
```
49+
b2d16c8 Refactor discovering of paths when recording events
50+
Thu Jun 16 11:08:47 2016 -0500 Michael Schenk
51+
52+
30m 18s [m] event/event.go
53+
12m 31s [m] event/manager.go
54+
3m 14s [m] project/project.go
55+
1m 12s [r] .git/COMMIT_EDITMSG
56+
1m 0s [r] .git/index
57+
25s [r] event/manager_test.go
58+
20s [r] metric/manager.go
59+
49m 0s
60+
```
61+
62+
**Timeline of time spent by day**
63+
64+
```
65+
0123456789012345678901234
66+
Fri Jun 24 * 22m 0s
67+
Sat Jun 25 ** 1h 28m 0s
68+
Sun Jun 26 **** 3h 28m 0s
69+
Mon Jun 27 * 4m 0s
70+
Tue Jun 28 ** 1h 36m 0s
71+
6h 58m 0s
72+
```
73+
74+
Consult the [README](https://github.com/git-time-metric/gtm/blob/master/README.md) and [Wiki](https://github.com/git-time-metric/gtm/wiki) for more information.

gtm-plugin.py

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import os
66
import subprocess
77

8+
gtm_settings = {}
9+
810
def find_gtm_path():
911
if sys.platform == 'win32':
1012
exe = 'gtm.exe'
@@ -30,25 +32,56 @@ def find_gtm_path():
3032

3133
return None
3234

35+
def plugin_loaded():
36+
global gtm_settings
37+
gtm_settings = sublime.load_settings('gtm.sublime-settings')
38+
gtm_settings.add_on_change('gtm_status_bar', set_status_bar)
39+
set_status_bar()
40+
41+
def set_status_bar():
42+
if GTM.status_option_found and gtm_settings.get('gtm_status_bar', True):
43+
GTM.status_option = '--status'
44+
print("Enabling reporting time in status bar")
45+
else:
46+
GTM.status_option = ''
47+
print("Disabling reporting time in status bar")
48+
3349
class GTM(sublime_plugin.EventListener):
3450
update_interval = 30
35-
last_update = 0.0
51+
last_update = 0
3652
last_path = None
53+
status_option = ""
3754

38-
gtm_path = find_gtm_path()
39-
40-
no_gtm_err = ("GTM executable not found\n"
41-
"Install GTM and/or update your system path\n"
42-
"Make sure to restart Sublime after install\n"
55+
no_gtm_err = ("GTM executable not found. "
56+
"Install GTM and/or update your system path. "
57+
"Make sure to restart Sublime after install. \n\n"
4358
"See https://www.github.com/git-time-metric/gtm")
4459

45-
record_err = ("GTM error saving time\n"
46-
"Install GTM and/or update your system path\n"
47-
"Make sure to restart Sublime after install\n"
60+
record_err = ("GTM error saving time. "
61+
"Install GTM and/or update your system path. "
62+
"Make sure to restart Sublime after install.\n\n"
4863
"See https://www.github.com/git-time-metric/gtm")
4964

65+
ver_warn = ("GTM executable does not support all required features. "
66+
"Please install the latest GTM version and restart Sublime.\n\n"
67+
"See https://www.github.com/git-time-metric/gtm")
68+
69+
gtm_path = find_gtm_path()
70+
5071
if not gtm_path:
5172
sublime.error_message(no_gtm_err)
73+
else:
74+
# check support for [gtm record --status] feature
75+
p = subprocess.Popen("{0} record --help".format(gtm_path),
76+
shell=True,
77+
stdin=subprocess.PIPE,
78+
stdout=subprocess.PIPE,
79+
stderr=subprocess.STDOUT,
80+
close_fds=True)
81+
output = p.stdout.read()
82+
status_option_found = '-status' in output.decode('utf-8')
83+
if not status_option_found:
84+
sublime.error_message(ver_warn)
5285

5386
def on_post_save_async(self, view):
5487
self.record(view, view.file_name())
@@ -71,8 +104,15 @@ def record(self, view, path):
71104
GTM.last_update = time.time()
72105
GTM.last_path = path
73106

74-
cmd = '{0} record "{1}"'.format(GTM.gtm_path, path)
75-
return_code = subprocess.call(cmd, shell=True)
76-
77-
if return_code != 0:
107+
cmd = '{0} record {1} "{2}"'.format(GTM.gtm_path,
108+
GTM.status_option,
109+
path)
110+
111+
try:
112+
cmd_output = subprocess.check_output(cmd, shell=True)
113+
if GTM.status_option != "":
114+
view.set_status("gtm-statusbar", cmd_output.decode('utf-8'))
115+
else:
116+
view.erase_status("gtm-statusbar")
117+
except subprocess.CalledProcessError as e:
78118
sublime.error_message(GTM.record_err)

gtm.sublime-settings

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
// enable time reporting in status bar
3+
"gtm_status_bar": true
4+
}

0 commit comments

Comments
 (0)