#!/usr/bin/env ruby # OrgMode Worklog appender # # This supersedes [Worklogger](https://github.com/bascht/worklogger) # by appending to [OrgMode](https://github.com/bastibe/org-journal) # journal files and using KDialog for querying. require 'pathname' unless File.open(__FILE__).flock(File::LOCK_EX|File::LOCK_NB) abort("An instance of Worklogger is already running. Aborting.") end 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" appending = File.exist?(CURRENT_FILE) && (not File.zero?(CURRENT_FILE)) File.open(CURRENT_FILE, "a+") do |f| 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}' --width=300 --text="#{last_tasks}\nAdd entry for #{time}:"`.strip f.write("** #{time} #{entry}\n") unless entry.empty? end