The idea of this script came by realizing that the main reason I (almost) never fill my timesheet, is because I just forget it. How easier could it be if my editor (namely vim) could fill it for me ? Or at least, help me fill it. This script is meant to help this process. It will hook to every configured event (in the code below, BufRead and BufNewFile) and add a log line to the log file. Easy heh ? Of course, the script it self won't be of much use, I'll have to add some more events to track as well as writting some kind of frontend for it, with reporting & all.
if exists('trackloaded')
finish
endif
" list of autocmd events:
" http://www.vim.org/htmldoc/autocmd.html#autocmd-events
let trackevents = ['BufRead', 'BufNewFile', 'BufEnter', 'BufWrite', 'BufLeave']
let trackfile = '/tmp/timetrack.dat'
let trackloaded = 1
for event in trackevents
execute 'autocmd '.event.' * call Track("'.event.'")'
endfor
unlet event
function Track(event)
let l:filename = @%
if l:filename != g:trackfile
if match(l:filename, '/') != 0
let l:filename = getcwd().'/'.l:filename
endif
silent execute '!echo `date +\%s` '.a:event.' '.l:filename.' >> '.g:trackfile
endif
endfunction
You might note from this snippet that I'm not very comfortable with vimscripting :-) If you have a better way of doing this (I'm thinking mostly about the file writting here), don't hesitate to tell me.