[bin] Fix up empty Worklogger entries on resume / empty journals

This commit is contained in:
Sebastian Schulze 2020-06-15 09:56:35 +02:00
parent aeadd295ce
commit aa1b0cfc71
Signed by: bascht
GPG Key ID: 5BCB1D3B4D38A35A
1 changed files with 11 additions and 12 deletions

23
bin/executable_worklogger Executable file → Normal file
View File

@ -19,21 +19,20 @@ JOURNAL_PATH = Pathname.new("~/Documents/Worklog").expand_path
CURRENT_FILE = Pathname.new(JOURNAL_PATH.join(now.strftime("%Y%m%d")))
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|
last_tasks = if we_are_appending
all_tasks = f.each_line.select{|line| line.start_with? "**" }
all_tasks.map{ |task| task.sub(/^\*\* /, "") }.last(3).join("")
else
location = `#{DIALOG} --title='worklogger' --text="Where are we today?"`.strip
f.write(now.strftime("* %A, %d/%m/%Y\n"))
f.write(" :PROPERTIES:\n :WORKLOG_LOCATION: #{location}\n :END:\n\n")
"First entry for today!"
last_tasks = if appending
all_tasks = f.each_line.select{|line| line.start_with? "**" }
all_tasks.map{ |task| task.sub(/^\*\* /, "") }.last(3).join("")
else
location = `#{DIALOG} --title='worklogger' --text="Where are we today?" --entry-text="HomeOffice"`.strip
f.write(now.strftime("* %A, %d/%m/%Y\n"))
f.write(" :PROPERTIES:\n :WORKLOG_LOCATION: #{location}\n :END:\n\n")
"First entry for today!"
end
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?
end