Created
December 21, 2016 03:53
-
-
Save tily/66b80a5edc807dbaccfce18e04e6ca7a to your computer and use it in GitHub Desktop.
すぐにローカルのメモを書きはじめられるやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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