Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created October 20, 2010 01:24
Show Gist options
  • Save nbqx/635576 to your computer and use it in GitHub Desktop.
Save nbqx/635576 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
%w(rubygems growl-logger optparse).each{|x| require x}
MEMO_FILE_DIR = "/Volumes/HDD/Dropbox/PlainText"
EDITOR_CMD = "gvim"
opt = OptionParser.new
o = Hash.new
begin
opt.on('-t'){|v| o[:t] = v}
opt.on('-m'){|v| o[:m] = v}
opt.on('-e'){|v| o[:e] = v}
opt.parse!(ARGV)
rescue
puts "#{__FILE__}: unrecognized option \`#{ARGV[0]} \'"
exit
end
memo_file = ""
def disp(m)
contents = m.read.split("---\n")
formatted_contents = []
contents.each do |cont|
spl = cont.split("\n")
date = spl.shift
text = spl.join('')
unless date.nil?
formatted_contents << {:date => date, :content => text}
end
end
growl = GrowlLogger.new(:name => "From Noti")
memos = []
formatted_contents.each do |c|
memos << c[:date]+": "+c[:content]
end
growl.info("\n"+memos.join("\n"))
end
if o[:t] && o[:e]
system "#{EDITOR_CMD} #{MEMO_FILE_DIR}/todo.txt"
elsif o[:m] && o[:e]
system "#{EDITOR_CMD} #{MEMO_FILE_DIR}/memo.txt"
elsif o[:t]
memo_file = File.open("#{MEMO_FILE_DIR}/todo.txt")
disp(memo_file)
else o[:m]
memo_file = File.open("#{MEMO_FILE_DIR}/memo.txt")
disp(memo_file)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment