notenote 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b6879e1aa7c6522ca4115b8cc9e2bb35e5b35c56d3d844546fbf5207472bd6b
4
- data.tar.gz: 1b88305949d1ae6d7d8b1b63a0704942f8b3bf14df7ddb47b9c976675e079b46
3
+ metadata.gz: f78d842dc42121cfc84e9610b0b7869b6c968f0dcaa4874dda75d618de9bfa81
4
+ data.tar.gz: 7b2efa649831bb0ce998974cfab33879864486118fab60baaa4ea313f4bf0509
5
5
  SHA512:
6
- metadata.gz: 0c710812b969e74bc21283132d006af95fa2883cbf64a510cf6bc32cf1170998ee770db5243cca139593094c1f181293781f6758e4d60734773cd6dbc5eab4c2
7
- data.tar.gz: 582f0e27bb423fc3f54f5997c4d42d4c1ebf54f637e2a2931921ab4016af1e8f5e7ba4e5064a62ff5608d48b02dcdffc76143e81d572f6e40df400717011a786
6
+ metadata.gz: 4e3962ada9564374f722f51ce976e99934c7d3bdda17a165f0c7f856a4b88d3ea53d588d4c0a916b77c8f20250cd01e2c75b06644e1ba3d3cdbe4c40118c878d
7
+ data.tar.gz: 7937389c96e845c4f96e70dcc005ae272be582fe0068c83deff63fb773a713a215c4b196853c1e4c5cc0e40e282b5f3b47749a4c65ca4be6a6e4de8d0da97fef
data/lib/note/cli.rb CHANGED
@@ -64,6 +64,14 @@ module Note
64
64
  end tell
65
65
  END
66
66
 
67
+ 0
68
+ elsif args.first == "push"
69
+ push_notes
70
+
71
+ 0
72
+ elsif args.first == "push!"
73
+ push_notes(force: true)
74
+
67
75
  0
68
76
  else
69
77
  puts "Hm, I don't know this command 🤔"
@@ -104,8 +112,9 @@ module Note
104
112
 
105
113
  def create_note_file(file_name: "notes.md")
106
114
  notes_folder = notenote_config["notes_folder"]
115
+ date_format = notenote_config["date_format"]
107
116
 
108
- today_folder = File.join(notes_folder, Time.now.strftime("%d-%m-%Y"))
117
+ today_folder = File.join(notes_folder, Time.now.strftime(date_format))
109
118
 
110
119
  Dir.mkdir(today_folder) unless Dir.exist?(today_folder)
111
120
 
@@ -139,5 +148,54 @@ module Note
139
148
  def unindent(str)
140
149
  str.gsub(/^#{str.scan(/^[ \t]+(?=\S)/).min}/, "")
141
150
  end
151
+
152
+ # This function parses the output of diffstat:
153
+ #
154
+ # git diff HEAD | diffstat -Cm
155
+ #
156
+ # notes.md | 2 ++
157
+ # testing.md | 5 ----!
158
+ # 2 files changed, 2 insertions(+), 4 deletions(-), 1 modification(!)
159
+ #
160
+ # { "+" => 2, "-" => 4, "!" => 1}
161
+ def git_diff_stat
162
+ Dir.chdir(notenote_config["notes_folder"])
163
+
164
+ raw_diffstat = `git diff HEAD | diffstat -Cm`
165
+
166
+ raw_changes = raw_diffstat.split("\n").last.split(",").map(&:strip)
167
+
168
+ raw_changes.each_with_object({}) do |change, o|
169
+ next unless change =~ /[\+\-\!]/
170
+
171
+ type = change.scan(/([\+\-\!])/)[0][0]
172
+ num = change.scan(/\A(\d+)\s/)[0][0]
173
+
174
+ o[type] = num
175
+ end
176
+ end
177
+
178
+ def notes_changed_or_deleted?
179
+ diff_stat = git_diff_stat
180
+
181
+ diff_stat.member?("-") || diff_stat.member?("!")
182
+ end
183
+
184
+ def push_notes(force: false)
185
+ if !force && notes_changed_or_deleted?
186
+ puts "Some of the notes were mofified or deleted. Please, check them up and push manually."
187
+ return
188
+ end
189
+
190
+ Dir.chdir(notenote_config["notes_folder"])
191
+
192
+ system "git add ."
193
+
194
+ system %(git commit -m "#{notenote_config["commit_message"]}")
195
+
196
+ system "git push"
197
+
198
+ puts "Pushed. ✅"
199
+ end
142
200
  end
143
201
  end
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "notes_folder": "%{notes_folder}",
3
+ "date_format": "%d-%m-%Y",
3
4
  "editor_command": "code",
4
5
  "commit_message": "Added new notes"
5
6
  }
data/lib/note/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Note
2
- VERSION = "0.0.4".freeze
2
+ VERSION = "0.0.6".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.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoli Makarevich