[bin] Fix up empty Worklogger entries on resume / empty journals
This commit is contained in:
parent
aeadd295ce
commit
aa1b0cfc71
|
@ -19,21 +19,20 @@ JOURNAL_PATH = Pathname.new("~/Documents/Worklog").expand_path
|
||||||
CURRENT_FILE = Pathname.new(JOURNAL_PATH.join(now.strftime("%Y%m%d")))
|
CURRENT_FILE = Pathname.new(JOURNAL_PATH.join(now.strftime("%Y%m%d")))
|
||||||
DIALOG="zenity --entry"
|
DIALOG="zenity --entry"
|
||||||
|
|
||||||
we_are_appending = CURRENT_FILE.exist?
|
appending = File.exist?(CURRENT_FILE) && (not File.zero?(CURRENT_FILE))
|
||||||
|
binding.pry
|
||||||
|
|
||||||
|
|
||||||
File.open(CURRENT_FILE, "a+") do |f|
|
File.open(CURRENT_FILE, "a+") do |f|
|
||||||
last_tasks = if we_are_appending
|
last_tasks = if appending
|
||||||
all_tasks = f.each_line.select{|line| line.start_with? "**" }
|
all_tasks = f.each_line.select{|line| line.start_with? "**" }
|
||||||
all_tasks.map{ |task| task.sub(/^\*\* /, "") }.last(3).join("")
|
all_tasks.map{ |task| task.sub(/^\*\* /, "") }.last(3).join("")
|
||||||
else
|
else
|
||||||
location = `#{DIALOG} --title='worklogger' --text="Where are we today?"`.strip
|
location = `#{DIALOG} --title='worklogger' --text="Where are we today?" --entry-text="HomeOffice"`.strip
|
||||||
f.write(now.strftime("* %A, %d/%m/%Y\n"))
|
f.write(now.strftime("* %A, %d/%m/%Y\n"))
|
||||||
f.write(" :PROPERTIES:\n :WORKLOG_LOCATION: #{location}\n :END:\n\n")
|
f.write(" :PROPERTIES:\n :WORKLOG_LOCATION: #{location}\n :END:\n\n")
|
||||||
"First entry for today!"
|
"First entry for today!"
|
||||||
end
|
end
|
||||||
time = now.strftime('%H:%M')
|
time = now.strftime('%H:%M')
|
||||||
entry = `#{DIALOG} --title='worklogger @#{time}' --text="#{last_tasks}"`.strip
|
entry = `#{DIALOG} --title='worklogger @#{time}' --width=300 --text="#{last_tasks}"`.strip
|
||||||
f.write("** #{time} #{entry}\n") unless entry.empty?
|
f.write("** #{time} #{entry}\n") unless entry.empty?
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue