├── .gitignore
├── LICENSE
├── README.md
└── plugin
└── gtm.vim
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | .gtm/
3 | release
4 | /.gtm/
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Michael Schenk
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |

2 | Git Time Metric
3 |
4 | ### Vim Git Time Metrics (GTM) plug-in
5 |
6 | #### Simple, seamless, lightweight time tracking for all your git projects
7 |
8 | 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.
9 |
10 | ### Installation
11 |
12 | 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 Vim GTM plug-in. Please submit an issue if you have any problems and/or questions.
13 |
14 | 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.
15 | 2. The easy way to install the plug-in is to use your favorite Vim plug-in manager.
16 | - **Plug** `Plug 'git-time-metric/gtm-vim-plugin'`
17 | - **NeoBundle** `NeoBundle 'git-time-metric/gtm-vim-plugin'`
18 | - **Vundle** `Plugin 'git-time-metric/gtm-vim-plugin'`
19 | - **Pathogen** `git clone https://github.com/git-time-metric/gtm-vim-plugin.git ~/.vim/bundle/gtm`
20 |
21 | **Note** - to enable time tracking for a Git repository, you need to initialize it with `gtm init` otherwise it will be ignored by GTM. This is done via the command line.
22 | ```
23 | > cd /path/to/your/project
24 | > gtm init
25 | ```
26 |
27 | 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.
28 |
29 | # Features
30 |
31 | ### Status Bar
32 |
33 | In the status bar see your total time spent for in-process work (uncommitted).
34 |
35 | 
36 |
37 | By default this feature is off, to enable set `g:gtm_plugin_status_enabled` in your `.vimrc`.
38 |
39 | ```
40 | let g:gtm_plugin_status_enabled = 1
41 | ```
42 |
43 | Here's an example of diplaying time spent within Vim's status line.
44 |
45 | ```
46 | set statusline=%{exists('*GTMStatusline')?'['.GTMStatusline().']':''}\ %<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
47 | ```
48 |
49 | If you have the [Vim Airline plug-in](https://github.com/vim-airline/vim-airline) loaded, here's an example for adding it to the status line.
50 | ```
51 | function! AirlineInit()
52 | if exists('*GTMStatusline')
53 | call airline#parts#define_function('gtmstatus', 'GTMStatusline')
54 | let g:airline_section_b = airline#section#create([g:airline_section_b, ' ', '[', 'gtmstatus', ']'])
55 | endif
56 | endfunction
57 | autocmd User AirlineAfterInit call AirlineInit()
58 | ```
59 |
60 | **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.
61 |
62 | ### Command Line Interface
63 |
64 | Use the command line to report on time logged for your commits.
65 |
66 | Here are some examples of insights GTM can provide you.
67 |
68 | ##### $ gtm report -last-month
69 |
70 |
71 | ##### $ gtm report -last-month -format summary
72 |
73 |
74 | ##### $ gtm report -last-month -format timeline-hours
75 |
76 | GTM is automatic, seamless and lightweight. There is no need to remember to start and stop timers. It runs on occasion to capture activity triggered by your editor. The time metrics are stored locally with the git repository as [Git notes](https://git-scm.com/docs/git-notes) and can be pushed to the remote repository.
77 |
78 | # Support
79 |
80 | To report a bug, please submit an issue on the [GitHub Page](https://github.com/git-time-metric/gtm-vim-plugin/issues)
81 |
82 | 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.
83 |
--------------------------------------------------------------------------------
/plugin/gtm.vim:
--------------------------------------------------------------------------------
1 | " Git Time Metric Vim plugin
2 | " Author: Michael Schenk
3 | " License: MIT
4 |
5 | if exists('g:gtm_plugin_loaded') || &cp
6 | finish
7 | endif
8 | let g:gtm_plugin_loaded = 1
9 |
10 | let s:gtm_ver_req = '>= 1.2.5'
11 |
12 | let s:no_gtm_err = 'GTM exe not found, install GTM or update your path'
13 | let s:gtm_ver_err = 'GTM exe is out of date and may not work properly, please install the latest GTM exe'
14 | let s:gtm_url = 'see https://www.github.com/git-time-metric/gtm'
15 |
16 | if executable('gtm') == 0
17 | echomsg '.'
18 | echomsg s:no_gtm_err
19 | echomsg s:gtm_url
20 | echomsg '.'
21 | finish
22 | endif
23 |
24 | function! s:verify(ver)
25 | let output=system('gtm verify ' . shellescape(a:ver))
26 | if v:shell_error
27 | return 0
28 | else
29 | if output != 'true'
30 | return 0
31 | endif
32 | endif
33 | return 1
34 | endfunction
35 |
36 | let g:gtm_verify_version = get(g:, 'gtm_verify_version', 0)
37 |
38 | if g:gtm_verify_version == 1 && s:verify(s:gtm_ver_req) == 0
39 | echomsg '.'
40 | echomsg s:gtm_ver_err
41 | echomsg s:gtm_url
42 | echomsg '.'
43 | endif
44 |
45 | let g:gtm_plugin_status_enabled = get(g:, 'gtm_plugin_status_enabled', 0)
46 |
47 | let s:last_update = 0
48 | let s:last_file = ''
49 | let s:update_interval = 30
50 | let s:gtm_plugin_status = ''
51 |
52 | function! s:record()
53 | let fpath = expand('%:p')
54 | " record if file path has changed or last update is greater than update_interval
55 | if s:last_file != fpath || localtime() - s:last_update > s:update_interval
56 | let s:cmd = (g:gtm_plugin_status_enabled == 1 ? 'gtm record --status' : 'gtm record')
57 | let output=system(s:cmd . ' ' . shellescape(fpath))
58 | if v:shell_error
59 | echoerr s:no_gtm_err
60 | else
61 | let s:gtm_plugin_status = (g:gtm_plugin_status_enabled ? substitute(output, '\n\+$', '', '') : '')
62 | endif
63 | let s:last_update = localtime()
64 | let s:last_file = fpath
65 | endif
66 | endfunction
67 |
68 | function! GTMStatusline()
69 | return s:gtm_plugin_status
70 | endfunction
71 |
72 | augroup gtm_plugin
73 | autocmd!
74 | autocmd BufReadPost,BufWritePost,CursorMoved,CursorMovedI * silent call s:record()
75 | augroup END
76 |
--------------------------------------------------------------------------------