[worklogger] Add a friendly start-of-the-day entrybox
This commit is contained in:
parent
5f69120f29
commit
5c63ae406c
|
@ -7,6 +7,7 @@
|
||||||
# journal files and using KDialog for querying.
|
# journal files and using KDialog for querying.
|
||||||
|
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
|
require 'pry'
|
||||||
|
|
||||||
unless File.open(__FILE__).flock(File::LOCK_EX|File::LOCK_NB)
|
unless File.open(__FILE__).flock(File::LOCK_EX|File::LOCK_NB)
|
||||||
abort("An instance of Worklogger is already running. Aborting.")
|
abort("An instance of Worklogger is already running. Aborting.")
|
||||||
|
@ -16,15 +17,22 @@ now = Time.now
|
||||||
|
|
||||||
JOURNAL_PATH = Pathname.new("~/Documents/Worklog").expand_path
|
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 --title='worklogger'"
|
||||||
|
|
||||||
we_are_appending = CURRENT_FILE.exist?
|
we_are_appending = CURRENT_FILE.exist?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
File.open(CURRENT_FILE, "a+") do |f|
|
File.open(CURRENT_FILE, "a+") do |f|
|
||||||
unless we_are_appending
|
last_tasks = if we_are_appending
|
||||||
location = `kdialog --inputbox "Where are we today?"`.strip
|
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(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")
|
||||||
end
|
"First entry for today!"
|
||||||
entry = `kdialog --inputbox "What's rolling?"`.strip
|
end
|
||||||
|
entry = `#{DIALOG} --text="#{last_tasks}"`.strip
|
||||||
f.write("** #{now.strftime('%H:%M')} #{entry}\n") unless entry.empty?
|
f.write("** #{now.strftime('%H:%M')} #{entry}\n") unless entry.empty?
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue