forked from luna/vim-rana-local
new version 0.1.3. Cleaned up plugin. Automatically creating ~/.wakatime.log file.
This commit is contained in:
parent
3457b0b534
commit
61370df1ba
3 changed files with 161 additions and 177 deletions
|
@ -1,7 +1,7 @@
|
||||||
vim-wakatime 0.1.2
|
vim-wakatime 0.1.2
|
||||||
===========
|
===========
|
||||||
|
|
||||||
Automatic time tracking.
|
Automatic time tracking for Vim.
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
@ -12,7 +12,7 @@ https://wakati.me
|
||||||
|
|
||||||
2) Run this shell command replacing KEY with your api key:
|
2) Run this shell command replacing KEY with your api key:
|
||||||
|
|
||||||
echo "api_key=KEY" > ~/.wakatime
|
echo "api_key=KEY" >> ~/.wakatime
|
||||||
|
|
||||||
3) Using [Vundle](https://github.com/gmarik/vundle), the Vim plugin manager:
|
3) Using [Vundle](https://github.com/gmarik/vundle), the Vim plugin manager:
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import logging as log
|
||||||
|
|
||||||
|
|
||||||
# Config
|
# Config
|
||||||
version = '0.1.2'
|
version = '0.1.3'
|
||||||
user_agent = 'vim-wakatime/%s (%s)' % (version, platform.platform())
|
user_agent = 'vim-wakatime/%s (%s)' % (version, platform.platform())
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,14 +118,12 @@ def send_action(key, instance, action, task, timestamp, project, tags):
|
||||||
url = 'https://www.wakati.me/api/v1/actions'
|
url = 'https://www.wakati.me/api/v1/actions'
|
||||||
data = {
|
data = {
|
||||||
'type': action,
|
'type': action,
|
||||||
'task': task,
|
'task': os.path.realpath(task),
|
||||||
'time': time.time(),
|
'time': timestamp,
|
||||||
'instance_id': instance,
|
'instance_id': instance,
|
||||||
'project': project,
|
'project': project,
|
||||||
'tags': tags,
|
'tags': tags,
|
||||||
}
|
}
|
||||||
if timestamp:
|
|
||||||
data['time'] = timestamp
|
|
||||||
request = urllib2.Request(url=url, data=json.dumps(data))
|
request = urllib2.Request(url=url, data=json.dumps(data))
|
||||||
request.add_header('User-Agent', user_agent)
|
request.add_header('User-Agent', user_agent)
|
||||||
request.add_header('Content-Type', 'application/json')
|
request.add_header('Content-Type', 'application/json')
|
||||||
|
@ -173,7 +171,10 @@ def main(argv):
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
level = log.DEBUG
|
level = log.DEBUG
|
||||||
del args.verbose
|
del args.verbose
|
||||||
|
if not args.timestamp:
|
||||||
|
args.timestamp = time.time()
|
||||||
log.basicConfig(filename=os.path.expanduser('~/.wakatime.log'), format='%(asctime)s vim-wakatime/'+version+' %(levelname)s %(message)s', datefmt='%Y-%m-%dT%H:%M:%SZ', level=level)
|
log.basicConfig(filename=os.path.expanduser('~/.wakatime.log'), format='%(asctime)s vim-wakatime/'+version+' %(levelname)s %(message)s', datefmt='%Y-%m-%dT%H:%M:%SZ', level=level)
|
||||||
|
if os.path.isfile(os.path.realpath(args.task)):
|
||||||
tags = tags_from_path(args.task)
|
tags = tags_from_path(args.task)
|
||||||
project = project_from_path(args.task)
|
project = project_from_path(args.task)
|
||||||
send_action(project=project, tags=tags, **vars(args))
|
send_action(project=project, tags=tags, **vars(args))
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
" ============================================================================
|
" ============================================================================
|
||||||
" File: wakatime.vim
|
" File: wakatime.vim
|
||||||
" Description: invisible time tracker using Wakati.Me
|
" Description: Automatic time tracking for Vim.
|
||||||
" Maintainer: Wakati.Me <support@wakatime.com>
|
" Maintainer: Wakati.Me <support@wakatime.com>
|
||||||
" Version: 0.1.2
|
" Version: 0.1.3
|
||||||
" ============================================================================
|
" ============================================================================
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,49 +58,37 @@ let s:away_start = 0
|
||||||
" Create logfile if does not exist
|
" Create logfile if does not exist
|
||||||
exec "silent !touch ~/.wakatime.log"
|
exec "silent !touch ~/.wakatime.log"
|
||||||
|
|
||||||
python << ENDPYTHON
|
python import time
|
||||||
import vim
|
python import time
|
||||||
import uuid
|
python import uuid
|
||||||
import time
|
python import vim
|
||||||
|
python instance_id = str(uuid.uuid4())
|
||||||
instance_id = str(uuid.uuid4())
|
python vim.command('let s:instance_id = "%s"' % instance_id)
|
||||||
vim.command('let s:instance_id = "%s"' % instance_id)
|
|
||||||
ENDPYTHON
|
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
|
|
||||||
" Function Definitions {{{
|
" Function Definitions {{{
|
||||||
|
|
||||||
function! s:initVariable(var, value)
|
|
||||||
if !exists(a:var)
|
|
||||||
exec 'let ' . a:var . ' = ' . "'" . substitute(a:value, "'", "''", "g") . "'"
|
|
||||||
return 1
|
|
||||||
endif
|
|
||||||
return 0
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:setUpdateTime()
|
function! s:setUpdateTime()
|
||||||
if &updatetime < 60 * 1000 * 2
|
if &updatetime < 60 * 1000 * 2
|
||||||
let &updatetime = g:wakatime_updatetime * 60 * 1000
|
let &updatetime = g:wakatime_updatetime * 60 * 1000
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call s:setUpdateTime()
|
call s:setUpdateTime()
|
||||||
|
|
||||||
function! s:GetCurrentFile()
|
function! s:GetCurrentFile()
|
||||||
return expand("%:p")
|
return expand("%:p")
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:api(type, task)
|
function! s:GetCurrentTime()
|
||||||
if a:task != ''
|
python vim.command('let current_time="%f"' % time.time())
|
||||||
exec "silent !python " . s:plugin_directory . "/wakatime.py --key" g:wakatime_api_key "--instance" s:instance_id "--action" a:type "--task" shellescape(a:task) . " &"
|
return current_time
|
||||||
endif
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:api_with_time(type, task, time)
|
function! s:api(type, task, time)
|
||||||
if a:task != ''
|
if a:task != ''
|
||||||
exec "silent !python " . s:plugin_directory . "/wakatime.py --key" g:wakatime_api_key "--instance" s:instance_id "--action" a:type "--task" shellescape(a:task) "--time" printf("%f", a:time) . " &"
|
exec "silent !python " . s:plugin_directory . "/wakatime.py --key" g:wakatime_api_key "--instance" s:instance_id "--action" a:type "--task" shellescape(a:task) "--time" a:time . " &"
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -136,28 +124,23 @@ endfunction
|
||||||
" Event Handlers {{{
|
" Event Handlers {{{
|
||||||
|
|
||||||
function! s:bufenter()
|
function! s:bufenter()
|
||||||
let task = s:GetCurrentFile()
|
call s:api("open_file", s:GetCurrentFile(), s:GetCurrentTime())
|
||||||
call s:api("open_file", task)
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:bufleave()
|
function! s:bufleave()
|
||||||
let task = s:GetCurrentFile()
|
call s:api("close_file", s:GetCurrentFile(), s:GetCurrentTime())
|
||||||
call s:api("close_file", task)
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:vimenter()
|
function! s:vimenter()
|
||||||
let task = s:GetCurrentFile()
|
call s:api("open_editor", s:GetCurrentFile(), s:GetCurrentTime())
|
||||||
call s:api("open_editor", task)
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:vimleave()
|
function! s:vimleave()
|
||||||
let task = s:GetCurrentFile()
|
call s:api("quit_editor", s:GetCurrentFile(), s:GetCurrentTime())
|
||||||
call s:api("quit_editor", task)
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:bufwrite()
|
function! s:bufwrite()
|
||||||
let task = s:GetCurrentFile()
|
call s:api("write_file", s:GetCurrentFile(), s:GetCurrentTime())
|
||||||
call s:api("write_file", task)
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:cursorhold()
|
function! s:cursorhold()
|
||||||
|
@ -172,7 +155,7 @@ function! s:cursormoved()
|
||||||
" Don't do anything unless all other Vim instances are also away
|
" Don't do anything unless all other Vim instances are also away
|
||||||
if !s:allServersAway()
|
if !s:allServersAway()
|
||||||
let s:away_start = 0
|
let s:away_start = 0
|
||||||
call s:api("ping", s:away_task)
|
call s:api("ping", s:away_task, s:GetCurrentTime())
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -193,10 +176,10 @@ function! s:cursormoved()
|
||||||
endif
|
endif
|
||||||
let answer = input(printf("You were away %.f %s. Add time to current file? (y/n)", away_duration, away_unit))
|
let answer = input(printf("You were away %.f %s. Add time to current file? (y/n)", away_duration, away_unit))
|
||||||
if answer != "y"
|
if answer != "y"
|
||||||
call s:api_with_time("minimize_editor", s:away_task, s:away_start)
|
call s:api("minimize_editor", s:away_task, printf("%f", s:away_start))
|
||||||
call s:api_with_time("maximize_editor", s:away_task, away_end)
|
call s:api("maximize_editor", s:away_task, printf("%f", away_end))
|
||||||
else
|
else
|
||||||
call s:api("ping", s:away_task)
|
call s:api("ping", s:away_task, s:GetCurrentTime())
|
||||||
endif
|
endif
|
||||||
let s:away_start = 0
|
let s:away_start = 0
|
||||||
"redraw!
|
"redraw!
|
||||||
|
|
Loading…
Reference in a new issue