-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreviewer.rb
36 lines (28 loc) · 829 Bytes
/
reviewer.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
30
31
32
33
34
35
36
# Ti plugin to review time entries before finishing
#
# Opens the system's editor (defaults to vim if $EDITOR is not defined)
# and allows you to make changes to the time entry at once the timer is finished
#
timer = Ti::Timer
timer.on :finish, 0 do
file =`mktemp /tmp/ti.XXXXXXXX`.chomp
attrs = [:project, :start_time, :end_time]
open(file, 'w') do |f|
f.puts timer.task
f.puts "\n---\n\n"
pad = attrs.map(&:length).max + 1
attrs.each do |attr|
f.puts "#{attr}:".ljust(pad) + " #{timer.send(attr)}"
end
end
system("#{ENV['EDITOR'] || 'vim'} #{file}")
content = open(file, 'r').read
task, data = content.split(/\n\n?---\n\n?/)
timer.task = task
attrs.each do |attr|
if m = data.match(/^#{attr}:\s*(.*)$/)
timer.send("#{attr}=", m[1])
end
end
`rm #{file}`
end