-
Notifications
You must be signed in to change notification settings - Fork 1
/
ledger.rb
29 lines (24 loc) · 729 Bytes
/
ledger.rb
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
# Ti plugin that outputs worked time in ledger format
# to the file specified by the 'TIMELOG' env variable
#
# Example
# export TIMELOG=path_to_your.timelog
# ti Outbox Build amazing stuff
#
# On start, will append to `$TIMELOG` something like:
# i 2011-12-21 12:32:49 Outbox Build amazing stuff
#
# On finish, will append to `$TIMELOG` something like:
# o 2011-12-20 12:35:56
if ENV['TIMELOG']
def ledger_format time
time.strftime("%Y-%m-%d %H:%M:%S")
end
timer = Ti::Timer
timer.on :finish do
open(ENV['TIMELOG'], 'a') do |f|
f.puts "i #{ledger_format(timer.start_time)} #{timer.project} #{timer.task.split("\n").first}"
f.puts "o #{ledger_format(timer.end_time)}"
end
end
end