-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdevlog
More file actions
executable file
·52 lines (44 loc) · 942 Bytes
/
devlog
File metadata and controls
executable file
·52 lines (44 loc) · 942 Bytes
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
#!/usr/bin/env ruby
FILENAME = "#{Dir.home}/Dropbox/devlog.org"
def fail_loudly
STDERR.puts "current_date is null"
exit 1
end
def main
dates = {}
current_date = nil
File.open(FILENAME).each_line { |line|
if /^\* (?<date>\d{4}-\d{2}-\d{2})/ =~ line
current_date = date
else
fail_loudly if current_date == nil
dates[current_date] ||= []
dates[current_date] << line
end
}
return dates
end
def output(dates)
file = File.open(FILENAME, 'w+')
dates.keys.sort.reverse.each { |date|
file.puts "* #{date}"
dates[date].each { |line|
file.puts line
}
}
end
def todays_date
year = Time.now.year
month = Time.now.month.to_s.rjust(2, "0")
day = Time.now.day.to_s.rjust(2, "0")
"#{year}-#{month}-#{day}"
end
begin
dates = main
dates[todays_date] ||= []
notes = "\n#{ARGV.first}"
dates[todays_date].push(notes)
output(dates)
rescue Errno::EPIPE
exit 0
end