notenote 0.0.2 → 0.0.5
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 +112 -5
- data/lib/note/config.json.template +3 -1
- data/lib/note/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecfda3937a0ea3defb410fab57624938d0d3b1c6d1396c9f26ba8fe43d092e03
|
4
|
+
data.tar.gz: 0ae3216b3fa3b55c1717f9e7667344285c2416217c4f3069e5e3032a96ad5080
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d4d126d852699215f245f83ee14dec71e0e1fee91bda9bead8ea9b7c1a5631fe5fc60149271fd2639e6a2377fb3ffe4e982ef09c1511c3e55d0439694a09059
|
7
|
+
data.tar.gz: 45a92cfbc51472c916481172c5434df36d296273b7e09dba62b2b8b795717027070fc218d6c8ed5e052400c0309c0508718a898ec4c2d56997ee852d872e09d8
|
data/lib/note/cli.rb
CHANGED
@@ -25,9 +25,13 @@ module Note
|
|
25
25
|
Dir.mkdir(notes_folder)
|
26
26
|
end
|
27
27
|
|
28
|
-
|
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
|
29
32
|
create_note_file
|
30
33
|
|
34
|
+
|
31
35
|
puts %(Your note folder "#{notes_folder}" and the first log file are created. You're ready to go! 🚀)
|
32
36
|
|
33
37
|
0
|
@@ -37,6 +41,33 @@ module Note
|
|
37
41
|
|
38
42
|
create_note_file(file_name: "#{file_name}.md")
|
39
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
|
66
|
+
|
67
|
+
0
|
68
|
+
elsif args.first == "push"
|
69
|
+
push_notes
|
70
|
+
|
40
71
|
0
|
41
72
|
else
|
42
73
|
puts "Hm, I don't know this command 🤔"
|
@@ -47,6 +78,20 @@ module Note
|
|
47
78
|
|
48
79
|
private
|
49
80
|
|
81
|
+
def create_readme_file
|
82
|
+
notes_folder = notenote_config["notes_folder"]
|
83
|
+
|
84
|
+
readme_file = File.join(notes_folder, "README.md")
|
85
|
+
|
86
|
+
File.open(readme_file, "w") do |file|
|
87
|
+
file.puts unindent <<-TEXT
|
88
|
+
# Daily notes
|
89
|
+
|
90
|
+
|
91
|
+
TEXT
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
50
95
|
def create_config_file(notes_folder:)
|
51
96
|
config_template = File.read(File.join(File.dirname(__FILE__), "config.json.template"))
|
52
97
|
|
@@ -63,8 +108,9 @@ module Note
|
|
63
108
|
|
64
109
|
def create_note_file(file_name: "notes.md")
|
65
110
|
notes_folder = notenote_config["notes_folder"]
|
111
|
+
date_format = notenote_config["date_format"]
|
66
112
|
|
67
|
-
today_folder = File.join(notes_folder, Time.now.strftime(
|
113
|
+
today_folder = File.join(notes_folder, Time.now.strftime(date_format))
|
68
114
|
|
69
115
|
Dir.mkdir(today_folder) unless Dir.exist?(today_folder)
|
70
116
|
|
@@ -72,7 +118,7 @@ module Note
|
|
72
118
|
|
73
119
|
FileUtils.touch(note_file)
|
74
120
|
|
75
|
-
open_editor(
|
121
|
+
open_editor(path: note_file)
|
76
122
|
end
|
77
123
|
|
78
124
|
def notenote_config
|
@@ -81,10 +127,71 @@ module Note
|
|
81
127
|
JSON.parse(File.read(config_file))
|
82
128
|
end
|
83
129
|
|
84
|
-
def open_editor(
|
130
|
+
def open_editor(path:)
|
85
131
|
editor_command = notenote_config["editor_command"]
|
86
132
|
|
87
|
-
system("#{editor_command} #{
|
133
|
+
system("#{editor_command} #{path}")
|
134
|
+
end
|
135
|
+
|
136
|
+
def mac?
|
137
|
+
RbConfig::CONFIG["host_os"] =~ /darwin/
|
138
|
+
end
|
139
|
+
|
140
|
+
def osascript(script)
|
141
|
+
system "osascript", *unindent(script).split(/\n/).map { |line| ['-e', line] }.flatten
|
142
|
+
end
|
143
|
+
|
144
|
+
def unindent(str)
|
145
|
+
str.gsub(/^#{str.scan(/^[ \t]+(?=\S)/).min}/, "")
|
146
|
+
end
|
147
|
+
|
148
|
+
# This function parses the output of diffstat:
|
149
|
+
#
|
150
|
+
# git diff HEAD | diffstat -Cm
|
151
|
+
#
|
152
|
+
# notes.md | 2 ++
|
153
|
+
# testing.md | 5 ----!
|
154
|
+
# 2 files changed, 2 insertions(+), 4 deletions(-), 1 modification(!)
|
155
|
+
#
|
156
|
+
# { "+" => 2, "-" => 4, "!" => 1}
|
157
|
+
def git_diff_stat
|
158
|
+
Dir.chdir(notenote_config["notes_folder"])
|
159
|
+
|
160
|
+
raw_diffstat = `git diff HEAD | diffstat -Cm`
|
161
|
+
|
162
|
+
raw_changes = raw_diffstat.split("\n").last.split(",").map(&:strip)
|
163
|
+
|
164
|
+
raw_changes.each_with_object({}) do |change, o|
|
165
|
+
next unless change =~ /[\+\-\!]/
|
166
|
+
|
167
|
+
type = change.scan(/([\+\-\!])/)[0][0]
|
168
|
+
num = change.scan(/\A(\d+)\s/)[0][0]
|
169
|
+
|
170
|
+
o[type] = num
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def notes_changed_or_deleted?
|
175
|
+
diff_stat = git_diff_stat
|
176
|
+
|
177
|
+
diff_stat.member?("-") || diff_stat.member?("!")
|
178
|
+
end
|
179
|
+
|
180
|
+
def push_notes
|
181
|
+
if notes_changed_or_deleted?
|
182
|
+
puts "Some of the notes were mofified or deleted. Please, check them up and push manually."
|
183
|
+
return
|
184
|
+
end
|
185
|
+
|
186
|
+
Dir.chdir(notenote_config["notes_folder"])
|
187
|
+
|
188
|
+
system "git add ."
|
189
|
+
|
190
|
+
system %(git commit -m "#{notenote_config["commit_message"]}")
|
191
|
+
|
192
|
+
system "git push"
|
193
|
+
|
194
|
+
puts "Pushed. ✅"
|
88
195
|
end
|
89
196
|
end
|
90
197
|
end
|
data/lib/note/version.rb
CHANGED