From aa1b0cfc71fa10d73009b29d5dfebb9d5f4de56f Mon Sep 17 00:00:00 2001 From: Sebastian Schulze Date: Mon, 15 Jun 2020 09:56:35 +0200 Subject: [PATCH] [bin] Fix up empty Worklogger entries on resume / empty journals --- bin/executable_worklogger | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) mode change 100755 => 100644 bin/executable_worklogger diff --git a/bin/executable_worklogger b/bin/executable_worklogger old mode 100755 new mode 100644 index 1654792..9877cb7 --- a/bin/executable_worklogger +++ b/bin/executable_worklogger @@ -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