diff --git a/home/bin/worklogger b/home/bin/worklogger index e69e051..c1e6969 100755 --- a/home/bin/worklogger +++ b/home/bin/worklogger @@ -7,6 +7,7 @@ # journal files and using KDialog for querying. require 'pathname' +require 'pry' unless File.open(__FILE__).flock(File::LOCK_EX|File::LOCK_NB) abort("An instance of Worklogger is already running. Aborting.") @@ -16,15 +17,22 @@ now = Time.now JOURNAL_PATH = Pathname.new("~/Documents/Worklog").expand_path CURRENT_FILE = Pathname.new(JOURNAL_PATH.join(now.strftime("%Y%m%d"))) +DIALOG="zenity --entry --title='worklogger'" we_are_appending = CURRENT_FILE.exist? + + File.open(CURRENT_FILE, "a+") do |f| - unless we_are_appending - location = `kdialog --inputbox "Where are we today?"`.strip + 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} --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") - end - entry = `kdialog --inputbox "What's rolling?"`.strip + "First entry for today!" + end + entry = `#{DIALOG} --text="#{last_tasks}"`.strip f.write("** #{now.strftime('%H:%M')} #{entry}\n") unless entry.empty? end