notenote 0.0.11 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/note/cli.rb +44 -38
- data/lib/note/config.json.template +2 -1
- data/lib/note/helpers.rb +59 -0
- data/lib/note/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c1d8aaf090a602327ca4668ddf2302f8f44c0d9b8214b6b5ee5ef3e4708a4df
|
4
|
+
data.tar.gz: 430c780ce77443c2d35e59df835c700b4083ead5277cda6fd5e0a6b2835aeb5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d2813c76e15f4752700371fbbbc7d3d8ceb369f4591cacb541437c577f91d94df6dd43d50e8f65f7984df240bab6bafec268d41f40afaffc4aa8fc7b5dacf80
|
7
|
+
data.tar.gz: ab3916c6b9b49da5ac7861f6687eeba44528e46b523c1f965d53c58af031140ed25d8f17a8fce07905cb915a29014c74d8aa02fdc561db13927ed53ec227fb6c
|
data/lib/note/cli.rb
CHANGED
@@ -3,15 +3,18 @@
|
|
3
3
|
require "optparse"
|
4
4
|
require "json"
|
5
5
|
require "date"
|
6
|
+
require_relative "helpers"
|
6
7
|
|
7
8
|
$LOAD_PATH << File.expand_path(__dir__)
|
8
9
|
|
9
10
|
module Note
|
10
11
|
class CLI
|
12
|
+
include Helpers
|
13
|
+
|
14
|
+
CONFIG_FILE_NAME = ".notenote"
|
15
|
+
|
11
16
|
def run(args = [])
|
12
17
|
if args.first == "init"
|
13
|
-
require "fileutils"
|
14
|
-
|
15
18
|
notes_folder = args[1]
|
16
19
|
|
17
20
|
if notes_folder.nil?
|
@@ -26,13 +29,32 @@ module Note
|
|
26
29
|
Dir.mkdir(notes_folder)
|
27
30
|
end
|
28
31
|
|
32
|
+
vscode_config_folder = File.join(notes_folder, ".vscode")
|
33
|
+
unless Dir.exists?(vscode_config_folder)
|
34
|
+
Dir.mkdir(vscode_config_folder)
|
35
|
+
end
|
36
|
+
|
37
|
+
vscode_settings_file = File.join(vscode_config_folder, "settings.json")
|
38
|
+
if File.exist?(vscode_settings_file)
|
39
|
+
vscode_settings = JSON.parse(File.read(vscode_settings_file))
|
40
|
+
|
41
|
+
vscode_settings["markdown.editor.drop.enabled"] = false
|
42
|
+
|
43
|
+
File.open(vscode_settings_file, "w") do |f|
|
44
|
+
f.puts(JSON.pretty_generate(vscode_settings))
|
45
|
+
end
|
46
|
+
else
|
47
|
+
File.open(vscode_settings_file, "w") do |f|
|
48
|
+
f.puts(JSON.pretty_generate({ "markdown.editor.drop.enabled": false }))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
29
52
|
notes_folder_full_path = File.join(Dir.pwd, notes_folder)
|
30
53
|
|
31
54
|
create_config_file(notes_folder: notes_folder_full_path)
|
32
55
|
create_readme_file
|
33
56
|
create_note_file
|
34
57
|
|
35
|
-
|
36
58
|
puts %(Your note folder "#{notes_folder}" and the first log file are created. You're ready to go! 🚀)
|
37
59
|
|
38
60
|
0
|
@@ -74,6 +96,10 @@ module Note
|
|
74
96
|
elsif args.first == "push!"
|
75
97
|
push_notes(force: true)
|
76
98
|
|
99
|
+
0
|
100
|
+
elsif args.first == "version"
|
101
|
+
puts Note::VERSION
|
102
|
+
|
77
103
|
0
|
78
104
|
elsif args.size == 0
|
79
105
|
notes_folder = notenote_config["notes_folder"]
|
@@ -90,6 +116,8 @@ module Note
|
|
90
116
|
0
|
91
117
|
else
|
92
118
|
puts "Hm, looks like there's no such command. 🤔"
|
119
|
+
|
120
|
+
0
|
93
121
|
end
|
94
122
|
end
|
95
123
|
|
@@ -110,31 +138,33 @@ module Note
|
|
110
138
|
end
|
111
139
|
|
112
140
|
def create_config_file(notes_folder:)
|
141
|
+
config_file = File.join(Dir.home, CONFIG_FILE_NAME)
|
142
|
+
|
143
|
+
if File.exist?(config_file)
|
144
|
+
puts "📢 You already have a config file: ~/#{CONFIG_FILE_NAME}"
|
145
|
+
return
|
146
|
+
end
|
147
|
+
|
113
148
|
config_template = File.read(File.join(File.dirname(__FILE__), "config.json.template"))
|
114
149
|
|
115
|
-
config =
|
150
|
+
config = hash_format(config_template, {
|
116
151
|
notes_folder: notes_folder
|
117
152
|
})
|
118
153
|
|
119
|
-
config_file = File.join(Dir.home, ".notenote")
|
120
|
-
|
121
154
|
File.open(config_file, "w") do |f|
|
122
155
|
f.puts(config)
|
123
156
|
end
|
124
157
|
end
|
125
158
|
|
126
|
-
def create_note_file(note_name:
|
159
|
+
def create_note_file(note_name: notenote_config["default_note_file_name"])
|
127
160
|
notes_folder = notenote_config["notes_folder"]
|
128
161
|
|
129
162
|
today_folder = File.join(notes_folder, formatted_todays_date)
|
130
163
|
|
131
164
|
Dir.mkdir(today_folder) unless Dir.exist?(today_folder)
|
132
165
|
|
133
|
-
file_name = note_name
|
134
|
-
|
135
|
-
gsub(/\A\_+/, "").
|
136
|
-
gsub(/\_+\z/, "").
|
137
|
-
concat(".md")
|
166
|
+
file_name = markdown_file_name(note_name: note_name)
|
167
|
+
|
138
168
|
note_file = File.join(today_folder, file_name)
|
139
169
|
|
140
170
|
if File.exist?(note_file)
|
@@ -142,7 +172,7 @@ module Note
|
|
142
172
|
else
|
143
173
|
File.open(note_file, "w") do |file|
|
144
174
|
file.puts unindent <<-TEXT
|
145
|
-
# #{note_name
|
175
|
+
# #{upcate_first(note_name)}
|
146
176
|
|
147
177
|
|
148
178
|
TEXT
|
@@ -153,7 +183,7 @@ module Note
|
|
153
183
|
end
|
154
184
|
|
155
185
|
def notenote_config
|
156
|
-
config_file = File.join(Dir.home,
|
186
|
+
config_file = File.join(Dir.home, CONFIG_FILE_NAME)
|
157
187
|
|
158
188
|
JSON.parse(File.read(config_file))
|
159
189
|
end
|
@@ -164,18 +194,6 @@ module Note
|
|
164
194
|
system("#{editor_command} #{path}")
|
165
195
|
end
|
166
196
|
|
167
|
-
def mac?
|
168
|
-
RbConfig::CONFIG["host_os"] =~ /darwin/
|
169
|
-
end
|
170
|
-
|
171
|
-
def osascript(script)
|
172
|
-
system "osascript", *unindent(script).split(/\n/).map { |line| ['-e', line] }.flatten
|
173
|
-
end
|
174
|
-
|
175
|
-
def unindent(str)
|
176
|
-
str.gsub(/^#{str.scan(/^[ \t]+(?=\S)/).min}/, "")
|
177
|
-
end
|
178
|
-
|
179
197
|
# This function parses the output of diffstat:
|
180
198
|
#
|
181
199
|
# git diff HEAD | diffstat -Cm
|
@@ -231,18 +249,6 @@ module Note
|
|
231
249
|
system "git pull --ff-only"
|
232
250
|
end
|
233
251
|
|
234
|
-
# A custom string format method to avoid type
|
235
|
-
# errors when using str % hash.
|
236
|
-
def safe_tt(str, hash)
|
237
|
-
str_copy = str
|
238
|
-
|
239
|
-
hash.each do |key, value|
|
240
|
-
str_copy.gsub!("%{#{key}}", value.to_s)
|
241
|
-
end
|
242
|
-
|
243
|
-
str_copy
|
244
|
-
end
|
245
|
-
|
246
252
|
def formatted_todays_date
|
247
253
|
date_format = notenote_config["date_format"]
|
248
254
|
|
data/lib/note/helpers.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module Helpers
|
2
|
+
private
|
3
|
+
|
4
|
+
def markdown_file_name(note_name:)
|
5
|
+
note_name.strip.downcase.
|
6
|
+
gsub(/[^a-z0-9]+/, "_").
|
7
|
+
gsub(/\A\_+/, "").
|
8
|
+
gsub(/\_+\z/, "").
|
9
|
+
concat(".md")
|
10
|
+
end
|
11
|
+
|
12
|
+
def upcate_first(str)
|
13
|
+
return if str.nil?
|
14
|
+
return "" if str.empty?
|
15
|
+
|
16
|
+
str.dup.tap { |s| s[0] = s[0].upcase }
|
17
|
+
end
|
18
|
+
|
19
|
+
# A custom string format method to avoid type
|
20
|
+
# errors when using str % hash.
|
21
|
+
def hash_format(str, hash)
|
22
|
+
return if str.nil?
|
23
|
+
|
24
|
+
str_copy = str.dup
|
25
|
+
|
26
|
+
hash.each do |key, value|
|
27
|
+
str_copy.gsub!("%{#{key}}", value.to_s)
|
28
|
+
end
|
29
|
+
|
30
|
+
str_copy
|
31
|
+
end
|
32
|
+
|
33
|
+
def unindent(str)
|
34
|
+
return if str.nil?
|
35
|
+
|
36
|
+
str_copy = str.dup
|
37
|
+
lines = str_copy.split("\n")
|
38
|
+
|
39
|
+
first_char = str_copy[0]
|
40
|
+
|
41
|
+
while lines.all? { |l| l.start_with?(first_char) } &&
|
42
|
+
(first_char == " " || first_char == "\t")
|
43
|
+
|
44
|
+
lines.map! { |l| l[1..-1] }
|
45
|
+
|
46
|
+
first_char = lines.first[0]
|
47
|
+
end
|
48
|
+
|
49
|
+
return lines.join("\n")
|
50
|
+
end
|
51
|
+
|
52
|
+
def mac?
|
53
|
+
RbConfig::CONFIG["host_os"] =~ /darwin/
|
54
|
+
end
|
55
|
+
|
56
|
+
def osascript(script)
|
57
|
+
system "osascript", *unindent(script).split(/\n/).map { |line| ["-e", line] }.flatten
|
58
|
+
end
|
59
|
+
end
|
data/lib/note/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notenote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anatoli Makarevich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: CLI tool to keep daily notes.
|
70
84
|
email:
|
71
85
|
- makaroni4@gmail.com
|
@@ -79,6 +93,7 @@ files:
|
|
79
93
|
- lib/note.rb
|
80
94
|
- lib/note/cli.rb
|
81
95
|
- lib/note/config.json.template
|
96
|
+
- lib/note/helpers.rb
|
82
97
|
- lib/note/version.rb
|
83
98
|
homepage: https://github.com/makaroni4/note
|
84
99
|
licenses:
|