Skip to content

Instantly share code, notes, and snippets.

@tily
Created December 21, 2016 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tily/66b80a5edc807dbaccfce18e04e6ca7a to your computer and use it in GitHub Desktop.
Save tily/66b80a5edc807dbaccfce18e04e6ca7a to your computer and use it in GitHub Desktop.
すぐにローカルのメモを書きはじめられるやつ
require 'fileutils'
require 'highline'
BASE_DIR = File.join(ENV['HOME'], 'Desktop')
TITLE = 'Untitled'
def main
title = HighLine.new.ask("Title: ")
title = TITLE if title == ""
path = note_path(title)
FileUtils.touch(path)
system "xyzzycli #{path}"
end
def note_path(title)
if File.exists?(with_dir("#{today}_#{title}.txt"))
index = get_index(title)
with_dir("#{today}_#{title}-#{index}.txt")
else
with_dir("#{today}_#{title}.txt")
end
end
def with_dir(filename)
File.join(BASE_DIR, filename)
end
def get_index(title)
i = 2
while File.exists?(with_dir("#{today}_#{title}-#{i}.txt"))
i += 1
end
i
end
def today
@today ||= Time.now.strftime('%Y%m%d')
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment