[worklogger] Add a friendly start-of-the-day entrybox

This commit is contained in:
Sebastian Schulze 2019-06-05 13:06:02 +02:00
parent 5f69120f29
commit 5c63ae406c
Signed by: bascht
GPG Key ID: 5BCB1D3B4D38A35A
1 changed files with 12 additions and 4 deletions

View File

@ -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