notenote 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eac76f549a64f9d6b6086a5d49d636f20144e0b74ab0d106ce5bfc12f228fdbf
4
- data.tar.gz: f3cf49d14d34e87219c14ecea709c9d36d67701723ce4551a3d3697c364429f4
3
+ metadata.gz: '09351642b43ef12aa169a2b8f861b1882397153d029c90a82d6d85a83dfd36ad'
4
+ data.tar.gz: ddc9b0421e3c66f367a877a97ccec2038e16110d68d2b63b655d8216d8bab89c
5
5
  SHA512:
6
- metadata.gz: d33f41622a10955ac95866f3ec44a363e03e671891f6aec20a46edd0663d41f49b9a955bd3183aafa6076bf85c828caf18d149ee9fe4ebb174dd5f8a62e2be43
7
- data.tar.gz: bb96769bc6c62bf855499a127d7fa00043b9e712ffb7c479e788bd964211a042665839a937d1519c20a719da247250c65bb1fab91506082521d94564112a541d
6
+ metadata.gz: 7e3c7dc3285f7c715d66abfab6cb96857aec7fed0de60cd88f913ad6c65176381578d988dd4f26a707905e0c04dceab7e85a10e38d4d296c65ffce78870a9e32
7
+ data.tar.gz: 967d5900a7c65b37cd2b1b01cb1ae74ec353e2f1de6e6ba2958fe86a86016d328ddc39522c2ef084b47b7ba890b8b0abb4dbcd7c5e59a03b80d8072e1df4e4cb
data/lib/note/cli.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "optparse"
4
+ require "json"
4
5
 
5
6
  $LOAD_PATH << File.expand_path(__dir__)
6
7
 
@@ -10,27 +11,80 @@ module Note
10
11
  if args.first == "init"
11
12
  require "fileutils"
12
13
 
13
- folder_name = args[1]
14
+ notes_folder = args[1]
14
15
 
15
- if folder_name.nil?
16
+ if notes_folder.nil?
16
17
  puts "Provide a valid folder name, please. ☺️"
17
18
  return
18
19
  end
19
20
 
20
- if Dir.exists?(folder_name)
21
- puts %(The folder named "#{folder_name}" already exists. ☺️)
21
+ if Dir.exists?(notes_folder)
22
+ puts %(The folder named "#{notes_folder}" already exists. ☺️)
22
23
  return
24
+ else
25
+ Dir.mkdir(notes_folder)
23
26
  end
24
27
 
25
- Dir.mkdir(folder_name)
26
- FileUtils.touch(File.join(folder_name, Time.now.strftime("%d-%m-%Y.md")))
27
- puts %(Your note folder "#{folder_name}" and the first \
28
- log file are created. You're ready to go! 🚀)
28
+ create_config_file(notes_folder: notes_folder)
29
+ create_note_file
30
+
31
+ puts %(Your note folder "#{notes_folder}" and the first log file are created. You're ready to go! 🚀)
32
+
33
+ 0
34
+ elsif args.first == "on"
35
+ note_name = args[1..-1].join(" ") # "tax return" for `note on tax return``
36
+ file_name = note_name.gsub(/[^a-z0-9\-]+/, "_")
37
+
38
+ create_note_file(file_name: "#{file_name}.md")
29
39
 
30
40
  0
31
41
  else
32
42
  puts "Hm, I don't know this command 🤔"
43
+
44
+ 0
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def create_config_file(notes_folder:)
51
+ config_template = File.read(File.join(File.dirname(__FILE__), "config.json.template"))
52
+
53
+ config = config_template % {
54
+ notes_folder: notes_folder
55
+ }
56
+
57
+ config_file = File.join(Dir.home, ".notenote")
58
+
59
+ File.open(config_file, "w") do |f|
60
+ f.puts(config)
33
61
  end
34
62
  end
63
+
64
+ def create_note_file(file_name: "notes.md")
65
+ notes_folder = notenote_config["notes_folder"]
66
+
67
+ today_folder = File.join(notes_folder, Time.now.strftime("%d-%m-%Y"))
68
+
69
+ Dir.mkdir(today_folder) unless Dir.exist?(today_folder)
70
+
71
+ note_file = File.join(today_folder, file_name)
72
+
73
+ FileUtils.touch(note_file)
74
+
75
+ open_editor(file: note_file)
76
+ end
77
+
78
+ def notenote_config
79
+ config_file = File.join(Dir.home, ".notenote")
80
+
81
+ JSON.parse(File.read(config_file))
82
+ end
83
+
84
+ def open_editor(note_file:)
85
+ editor_command = notenote_config["editor_command"]
86
+
87
+ system("#{editor_command} #{note_file}")
88
+ end
35
89
  end
36
90
  end
@@ -0,0 +1,4 @@
1
+ {
2
+ "notes_folder": "%{notes_folder}",
3
+ "editor_command": "code"
4
+ }
data/lib/note/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Note
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.2".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notenote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoli Makarevich
@@ -78,6 +78,7 @@ files:
78
78
  - bin/note
79
79
  - lib/note.rb
80
80
  - lib/note/cli.rb
81
+ - lib/note/config.json.template
81
82
  - lib/note/version.rb
82
83
  homepage: https://github.com/makaroni4/note
83
84
  licenses: