forked from WhatNodyn/kakoune-wakatime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wakatime.kak
69 lines (56 loc) · 2.09 KB
/
wakatime.kak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# wakatime.kak version 4.0.0
# By Nodyn
decl str wakatime_cli "~/.wakatime/wakatime-cli"
decl bool wakatime_debug true
decl -hidden str wakatime_version "4.0.0"
decl -hidden str wakatime_beat_rate 120
decl -hidden str wakatime_last_file
decl -hidden int wakatime_last_beat
def -hidden wakatime-heartbeat -params 0..1 %{
evaluate-commands %sh{
# If we're not in a real file, abort.
if [ "$kak_buffile" = "$kak_bufname" ]; then
exit
fi
# Get the current time.
now=$(date "+%s")
# Can we send a heartbeat?
if [ "$kak_buffile" = "$kak_opt_wakatime_last_file" ]; then
if [ "$1" != "write" ]; then
if [ $(($now - ${kak_opt_wakatime_last_beat:-0})) -lt $kak_opt_wakatime_beat_rate ]; then
exit
fi
fi
fi
if [ "$kak_opt_wakatime_debug" = "true" ]; then
echo "echo -debug '[WakaTime Debug] Sending a heartbeat $now'"
fi
echo "set global wakatime_last_file '$kak_buffile'"
echo "set global wakatime_last_beat $now"
command="$kak_opt_wakatime_cli"
command="$command --entity \"$kak_buffile\""
command="$command --time $now"
command="$command --plugin \"kakoune/$kak_version kakoune-wakatime/$kak_opt_wakatime_version\""
if [ "$1" = "write" ]; then
command="$command --write"
fi
if [ -n "$kak_cursor_byte_offset" ]; then
cursorpos="$((${#kak_cursor_byte_offset}))"
command="$command --cursorpos $cursorpos"
fi
if [ -n "$kak_filetype" ]; then
command="$command --alternate-language $kak_filetype"
fi
(eval "$command") < /dev/null > /dev/null 2> /dev/null &
}
}
def -hidden wakatime-init %{
evaluate-commands %sh{
echo "echo -debug '[WakaTime] Ready.'"
echo "hook -group WakaTime global InsertKey .* %{ wakatime-heartbeat }"
echo "hook -group WakaTime global ModeChange push:.*:insert %{ wakatime-heartbeat }"
echo "hook -group WakaTime global BufWritePost .* %{ wakatime-heartbeat write }"
echo "hook -group WakaTime global BufCreate .* %{ wakatime-heartbeat }"
}
}
hook -group WakaTime global KakBegin .* %{ wakatime-init }