-
-
Save joequery/6232026 to your computer and use it in GitHub Desktop.
Create a parseable time tracking log for vim. Requires https://gist.github.com/joequery/6231493 for the `git info` command.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Lets me know how much time I've spent editing a file | |
" Keyboard shortcut -> \dt | |
augroup TimeSpentEditing | |
au! | |
au BufWinEnter * if !exists('b:tstart')|let b:tstart=reltime()|en | |
augroup END | |
function! TimeSpentEditing() | |
let secs = str2nr(reltimestr(reltime(b:tstart))) | |
let hours = secs / 3600 | |
let minutes = (secs - hours * 3600) / 60 | |
let seconds = secs - hours * 3600 - minutes * 60 | |
return printf("%d:%02d:%02d", hours, minutes, seconds) | |
endfunction | |
function! s:logTimespent() | |
let secs = str2nr(reltimestr(reltime(b:tstart))) | |
let curFile = expand("%:p") | |
let time = TimeSpentEditing() | |
let path = expand("$HOME/.vimtime") | |
let timestamp = strftime('%s') | |
let end_timestamp = str2nr(timestamp) | |
let start_timestamp = end_timestamp - secs | |
"execute '!echo ' . curFile . ' : ' . time . ' >> ' . path | |
execute ':silent !echo ' . start_timestamp . '-' . timestamp . ':$(git info):' . curFile . ':[' . time . '] >> ' . path | |
endfunction | |
autocmd VimLeave * call s:logTimespent() | |
com! TimeSpentEditing echo TimeSpentEditing() | |
map <silent> <leader>dt :TimeSpentEditing<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment