notenote 0.0.7 → 0.0.9

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: 7e739b649898fe2b3cd03fef0dc45bd728ffbce50c3ee5cb6f7d1918bf59612f
4
- data.tar.gz: e23ae24148d1ef7666fd26430f3f5413b228d4a9c8563ec039c6878ef542326d
3
+ metadata.gz: a71839ec326f5f762ebea46f47b74d4fccd94f80961ce24b1753e9a842c39cab
4
+ data.tar.gz: eaeaf9f0a5bf5f24780a05dd943277d657b6731a0b21512643deb4980c820af7
5
5
  SHA512:
6
- metadata.gz: a129c33ebc60c59500cac01472a99f71889579797adddc746c6b1177c9b4bbc60c1a38736b9c235d9b38df35d5091b43e84ec8da2ec98b556010b3e5b4f54924
7
- data.tar.gz: aed23da98e1307fd318300a518b5c70381bb294f25b9488c850fa57ed65d235019f7793e7c7adfea97a3515ae8404fd0a694d7238c6cd0e5d76cbb1fae4305c8
6
+ metadata.gz: 8f0da4b7681d4680f0b81d2bad79f649304cb7c8a065f50a241f8bc6d00ca3baf2d30a01ca5341b3fa30b5cfdd08817b4254a0d6072c8f4778456d6cb05571a4
7
+ data.tar.gz: d953b1120e9cfcf957622a92985546d79916e4b725baaf5705737f289ffad146e189cba24ea1fa1b4b93ddd5e1bd009c9a0c9b3c885f786c4f276500ad13aee6
data/lib/note/cli.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "optparse"
4
4
  require "json"
5
+ require "date"
5
6
 
6
7
  $LOAD_PATH << File.expand_path(__dir__)
7
8
 
@@ -37,9 +38,8 @@ module Note
37
38
  0
38
39
  elsif args.first == "on"
39
40
  note_name = args[1..-1].join(" ") # "tax return" for `note on tax return``
40
- file_name = note_name.gsub(/[^a-z0-9\-]+/, "_")
41
41
 
42
- create_note_file(file_name: "#{file_name}.md")
42
+ create_note_file(note_name: note_name)
43
43
 
44
44
  0
45
45
  elsif args.first == "all"
@@ -65,6 +65,8 @@ module Note
65
65
  END
66
66
 
67
67
  0
68
+ elsif args.first == "pull"
69
+ pull_notes
68
70
  elsif args.first == "push"
69
71
  push_notes
70
72
 
@@ -74,7 +76,16 @@ module Note
74
76
 
75
77
  0
76
78
  else
77
- puts "Hm, I don't know this command 🤔"
79
+ notes_folder = notenote_config["notes_folder"]
80
+
81
+ today_folder = File.join(notes_folder, formatted_todays_date)
82
+ today_note_file = File.join(today_folder, "#{notenote_config["default_note_file_name"]}.md")
83
+
84
+ if File.exist?(today_note_file)
85
+ open_editor(path: today_note_file)
86
+ else
87
+ create_note_file
88
+ end
78
89
 
79
90
  0
80
91
  end
@@ -110,17 +121,31 @@ module Note
110
121
  end
111
122
  end
112
123
 
113
- def create_note_file(file_name: "notes.md")
124
+ def create_note_file(note_name: "#{notenote_config["default_note_file_name"]}.md")
114
125
  notes_folder = notenote_config["notes_folder"]
115
- date_format = notenote_config["date_format"]
116
126
 
117
- today_folder = File.join(notes_folder, Time.now.strftime(date_format))
127
+ today_folder = File.join(notes_folder, formatted_todays_date)
118
128
 
119
129
  Dir.mkdir(today_folder) unless Dir.exist?(today_folder)
120
130
 
131
+ file_name = note_name.strip.downcase.
132
+ gsub(/[^a-z0-9\-]+/, "_").
133
+ gsub(/\A\_+/, "").
134
+ gsub(/\_+\z/, "").
135
+ concat(".md")
121
136
  note_file = File.join(today_folder, file_name)
122
137
 
123
- FileUtils.touch(note_file)
138
+ if File.exist?(note_file)
139
+ puts "This note already exists. ⚠️"
140
+ else
141
+ File.open(note_file, "w") do |file|
142
+ file.puts unindent <<-TEXT
143
+ # #{note_name}
144
+
145
+
146
+ TEXT
147
+ end
148
+ end
124
149
 
125
150
  open_editor(path: note_file)
126
151
  end
@@ -198,6 +223,12 @@ module Note
198
223
  puts "Pushed. ✅"
199
224
  end
200
225
 
226
+ def pull_notes
227
+ Dir.chdir(notenote_config["notes_folder"])
228
+
229
+ system "git pull --ff-only"
230
+ end
231
+
201
232
  # A custom string format method to avoid type
202
233
  # errors when using str % hash.
203
234
  def safe_tt(str, hash)
@@ -209,5 +240,11 @@ module Note
209
240
 
210
241
  str_copy
211
242
  end
243
+
244
+ def formatted_todays_date
245
+ date_format = notenote_config["date_format"]
246
+
247
+ Date.today.strftime(date_format)
248
+ end
212
249
  end
213
250
  end
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "notes_folder": "%{notes_folder}",
3
3
  "date_format": "%d-%m-%Y",
4
+ "default_note_file_name: "notes",
4
5
  "editor_command": "code",
5
6
  "commit_message": "Added new notes"
6
7
  }
data/lib/note/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Note
2
- VERSION = "0.0.7".freeze
2
+ VERSION = "0.0.9".freeze
3
3
  end
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.7
4
+ version: 0.0.9
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-06 00:00:00.000000000 Z
11
+ date: 2022-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler