notenote 0.0.1 → 0.0.4

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: 6b6879e1aa7c6522ca4115b8cc9e2bb35e5b35c56d3d844546fbf5207472bd6b
4
+ data.tar.gz: 1b88305949d1ae6d7d8b1b63a0704942f8b3bf14df7ddb47b9c976675e079b46
5
5
  SHA512:
6
- metadata.gz: d33f41622a10955ac95866f3ec44a363e03e671891f6aec20a46edd0663d41f49b9a955bd3183aafa6076bf85c828caf18d149ee9fe4ebb174dd5f8a62e2be43
7
- data.tar.gz: bb96769bc6c62bf855499a127d7fa00043b9e712ffb7c479e788bd964211a042665839a937d1519c20a719da247250c65bb1fab91506082521d94564112a541d
6
+ metadata.gz: 0c710812b969e74bc21283132d006af95fa2883cbf64a510cf6bc32cf1170998ee770db5243cca139593094c1f181293781f6758e4d60734773cd6dbc5eab4c2
7
+ data.tar.gz: 582f0e27bb423fc3f54f5997c4d42d4c1ebf54f637e2a2931921ab4016af1e8f5e7ba4e5064a62ff5608d48b02dcdffc76143e81d572f6e40df400717011a786
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,133 @@ 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
+ notes_folder_full_path = File.join(Dir.pwd, notes_folder)
29
+
30
+ create_config_file(notes_folder: notes_folder_full_path)
31
+ create_readme_file
32
+ create_note_file
33
+
34
+
35
+ puts %(Your note folder "#{notes_folder}" and the first log file are created. You're ready to go! 🚀)
36
+
37
+ 0
38
+ elsif args.first == "on"
39
+ note_name = args[1..-1].join(" ") # "tax return" for `note on tax return``
40
+ file_name = note_name.gsub(/[^a-z0-9\-]+/, "_")
41
+
42
+ create_note_file(file_name: "#{file_name}.md")
43
+
44
+ 0
45
+ elsif args.first == "all"
46
+ notes_folder = notenote_config["notes_folder"]
47
+
48
+ open_editor(path: notes_folder)
49
+
50
+ 0
51
+ elsif args.first == "folder"
52
+ unless mac?
53
+ puts "Unfortunately, this command works only on Mac devices atm. Please, make a PR to support your OS. 🙏"
54
+ end
55
+
56
+ notes_folder = notenote_config["notes_folder"]
57
+
58
+ osascript <<-END
59
+ tell application "Terminal"
60
+ activate
61
+ tell application "System Events" to keystroke "t" using command down
62
+ do script "cd #{notes_folder}" in front window
63
+ do script "clear" in front window
64
+ end tell
65
+ END
29
66
 
30
67
  0
31
68
  else
32
69
  puts "Hm, I don't know this command 🤔"
70
+
71
+ 0
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ def create_readme_file
78
+ notes_folder = notenote_config["notes_folder"]
79
+
80
+ readme_file = File.join(notes_folder, "README.md")
81
+
82
+ File.open(readme_file, "w") do |file|
83
+ file.puts unindent <<-TEXT
84
+ # Daily notes
85
+
86
+
87
+ TEXT
33
88
  end
34
89
  end
90
+
91
+ def create_config_file(notes_folder:)
92
+ config_template = File.read(File.join(File.dirname(__FILE__), "config.json.template"))
93
+
94
+ config = config_template % {
95
+ notes_folder: notes_folder
96
+ }
97
+
98
+ config_file = File.join(Dir.home, ".notenote")
99
+
100
+ File.open(config_file, "w") do |f|
101
+ f.puts(config)
102
+ end
103
+ end
104
+
105
+ def create_note_file(file_name: "notes.md")
106
+ notes_folder = notenote_config["notes_folder"]
107
+
108
+ today_folder = File.join(notes_folder, Time.now.strftime("%d-%m-%Y"))
109
+
110
+ Dir.mkdir(today_folder) unless Dir.exist?(today_folder)
111
+
112
+ note_file = File.join(today_folder, file_name)
113
+
114
+ FileUtils.touch(note_file)
115
+
116
+ open_editor(path: note_file)
117
+ end
118
+
119
+ def notenote_config
120
+ config_file = File.join(Dir.home, ".notenote")
121
+
122
+ JSON.parse(File.read(config_file))
123
+ end
124
+
125
+ def open_editor(path:)
126
+ editor_command = notenote_config["editor_command"]
127
+
128
+ system("#{editor_command} #{path}")
129
+ end
130
+
131
+ def mac?
132
+ RbConfig::CONFIG["host_os"] =~ /darwin/
133
+ end
134
+
135
+ def osascript(script)
136
+ system "osascript", *unindent(script).split(/\n/).map { |line| ['-e', line] }.flatten
137
+ end
138
+
139
+ def unindent(str)
140
+ str.gsub(/^#{str.scan(/^[ \t]+(?=\S)/).min}/, "")
141
+ end
35
142
  end
36
143
  end
@@ -0,0 +1,5 @@
1
+ {
2
+ "notes_folder": "%{notes_folder}",
3
+ "editor_command": "code",
4
+ "commit_message": "Added new notes"
5
+ }
data/lib/note/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Note
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.4".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.4
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: