na 1.1.12 → 1.1.13

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: da1e1113960a99932feda46ee18cd7a8b9e8d309f479c9e3a6ec323d97db686a
4
- data.tar.gz: 871fcae47831f04efcff94b7034abb70d32cb47b2f504247b94705ad015c191f
3
+ metadata.gz: 03c240ef72b49cbb692ba1f55da9a36036d72bd51bb29549ea87262cceedfd51
4
+ data.tar.gz: e61a921f6af384ae5615f54116cb4e4e0c9472ab76d4a347fc50ea5633fc80a3
5
5
  SHA512:
6
- metadata.gz: c8e8c92c9d3a3ffa4a00fe8fcdd8ace94681e19f9ac53a3d8b988bcf4bd69d3b032765b4a870e3d9f660cd58b18783e97e8333cdb252164cb60f0062495210b5
7
- data.tar.gz: de5596e85883b893afbe2ca43833fe60f82fd96ab12e1f2506d84d13a90644d5d403b748b6598c9fb4c4d4db3998bdd0e560a1c071f4f7c2946b5f75dd45c728
6
+ metadata.gz: e577876361f3022e29d4c56e06d7c507fe05ac81da752debe476b481f92f671ee85ab25cb06e32a0608baf1b926454ea4e68aa6391e32ee7c5e7e02a5751dd11
7
+ data.tar.gz: 660039f2b13e23365ffa88fa8a59266f50941275830175458f867a26bfcbcd3553c8e5dc6ef70da1d1ab5946fc9d7a3361bdf932f8d63eda23c3c692657a5074
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 1.1.13
2
+
3
+ 2022-10-06 06:28
4
+
5
+ #### IMPROVED
6
+
7
+ - When specifying arguments to `next`, allow paths separated by / to do more exact matching
8
+
1
9
  ### 1.1.12
2
10
 
3
11
  2022-10-06 05:42
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- na (1.1.12)
4
+ na (1.1.13)
5
5
  gli (~> 2.21.0)
6
6
  tty-reader (~> 0.9, >= 0.9.0)
7
7
  tty-screen (~> 0.8, >= 0.8.1)
data/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  _If you're one of the rare people like me who find this useful, feel free to
10
10
  [buy me some coffee][donate]._
11
11
 
12
- The current version of `na` is 1.1.12
12
+ The current version of `na` is 1.1.13
13
13
  .
14
14
 
15
15
  `na` ("next action") is a command line tool designed to make it easy to see what your next actions are for any project, right from the command line. It works with TaskPaper-formatted files (but any plain text format will do), looking for `@na` tags (or whatever you specify) in todo files in your current folder.
@@ -136,28 +136,16 @@ module NA
136
136
  end
137
137
  else
138
138
  search.each do |t|
139
- new_rx = t[:token].to_s.wildcard_to_rx
140
-
141
- if negate
142
- optional.push(new_rx) if t[:negate]
143
- required.push(new_rx) if t[:required] && t[:negate]
144
- negated.push(new_rx) unless t[:negate]
145
- else
146
- optional.push(new_rx) unless t[:negate]
147
- required.push(new_rx) if t[:required] && !t[:negate]
148
- negated.push(new_rx) if t[:negate]
149
- end
139
+ optional, required, negated = parse_search(t, negate)
150
140
  end
151
141
  end
152
142
  end
153
143
 
154
- na_tag = "@#{NA.na_tag.sub(/^@/, '')}"
155
-
156
- if query.nil?
157
- files = find_files(depth: depth)
158
- else
159
- files = match_working_dir(query)
160
- end
144
+ files = if query.nil?
145
+ find_files(depth: depth)
146
+ else
147
+ match_working_dir(query)
148
+ end
161
149
 
162
150
  files.each do |file|
163
151
  save_working_dir(File.expand_path(file))
@@ -207,6 +195,40 @@ module NA
207
195
  [files, actions]
208
196
  end
209
197
 
198
+ def edit_file(file: nil, app: nil)
199
+ os_open(file, app: app) if file && File.exist?(file)
200
+ end
201
+
202
+ ##
203
+ ## Platform-agnostic open command
204
+ ##
205
+ ## @param file [String] The file to open
206
+ ##
207
+ def os_open(file, app: nil)
208
+ os = RbConfig::CONFIG['target_os']
209
+ case os
210
+ when /darwin.*/i
211
+ darwin_open(file, app: app)
212
+ when /mingw|mswin/i
213
+ win_open(file)
214
+ else
215
+ linux_open(file)
216
+ end
217
+ end
218
+
219
+ def weed_cache_file
220
+ db_dir = File.expand_path('~/.local/share/na')
221
+ db_file = 'tdlist.txt'
222
+ file = File.join(db_dir, db_file)
223
+ if File.exist?(file)
224
+ dirs = IO.read(file).split("\n")
225
+ dirs.delete_if { |f| !File.exist?(f) }
226
+ File.open(file, 'w') { |f| f.puts dirs.join("\n") }
227
+ end
228
+ end
229
+
230
+ private
231
+
210
232
  ##
211
233
  ## Generate a menu of options and allow user selection
212
234
  ##
@@ -234,6 +256,25 @@ module NA
234
256
  res
235
257
  end
236
258
 
259
+ def parse_search(tag, negate)
260
+ required = []
261
+ optional = []
262
+ negated = []
263
+ new_rx = tag[:token].to_s.wildcard_to_rx
264
+
265
+ if negate
266
+ optional.push(new_rx) if tag[:negate]
267
+ required.push(new_rx) if tag[:required] && tag[:negate]
268
+ negated.push(new_rx) unless tag[:negate]
269
+ else
270
+ optional.push(new_rx) unless tag[:negate]
271
+ required.push(new_rx) if tag[:required] && !tag[:negate]
272
+ negated.push(new_rx) if tag[:negate]
273
+ end
274
+
275
+ [optional, required, negated]
276
+ end
277
+
237
278
  ##
238
279
  ## Get path to database of known todo files
239
280
  ##
@@ -276,7 +317,7 @@ module NA
276
317
  notify('{r}No na database found', exit_code: 1) unless File.exist?(file)
277
318
 
278
319
  dirs = IO.read(file).split("\n")
279
- dirs.delete_if { |d| !d.matches(any: optional, all: required) }
320
+ dirs.delete_if { |d| !d.dir_matches(any: optional, all: required) }
280
321
  dirs.sort.uniq
281
322
  end
282
323
 
@@ -289,21 +330,6 @@ module NA
289
330
  File.open(file, 'w') { |f| f.puts dirs.join("\n") }
290
331
  end
291
332
 
292
- def weed_cache_file
293
- db_dir = File.expand_path('~/.local/share/na')
294
- db_file = 'tdlist.txt'
295
- file = File.join(db_dir, db_file)
296
- if File.exist?(file)
297
- dirs = IO.read(file).split("\n")
298
- dirs.delete_if { |f| !File.exist?(f) }
299
- File.open(file, 'w') { |f| f.puts dirs.join("\n") }
300
- end
301
- end
302
-
303
- def edit_file(file: nil, app: nil)
304
- os_open(file, app: app) if file && File.exist?(file)
305
- end
306
-
307
333
  def darwin_open(file, app: nil)
308
334
  if app
309
335
  `open -a "#{app}" #{Shellwords.escape(file)}`
@@ -323,22 +349,5 @@ module NA
323
349
  notify('{r}Unable to determine executable for `xdg-open`.')
324
350
  end
325
351
  end
326
-
327
- ##
328
- ## Platform-agnostic open command
329
- ##
330
- ## @param file [String] The file to open
331
- ##
332
- def os_open(file, app: nil)
333
- os = RbConfig::CONFIG['target_os']
334
- case os
335
- when /darwin.*/i
336
- darwin_open(file, app: app)
337
- when /mingw|mswin/i
338
- win_open(file)
339
- else
340
- linux_open(file)
341
- end
342
- end
343
352
  end
344
353
  end
data/lib/na/string.rb CHANGED
@@ -24,6 +24,14 @@ class ::String
24
24
  gsub(/(\s|m)(@[^ ("']+)(?:(\()(.*?)(\)))?/, "\\1#{tag_color}\\2#{paren_color}\\3#{value_color}\\4#{paren_color}\\5#{last_color}")
25
25
  end
26
26
 
27
+ def dir_to_rx
28
+ split(%r{[/:]}).join('.*?/.*?') + '[^/]+$'
29
+ end
30
+
31
+ def dir_matches(any: [], all: [])
32
+ matches_any(any.map { |token| token.dir_to_rx }) && matches_all(all.map { |token| token.dir_to_rx })
33
+ end
34
+
27
35
  def matches(any: [], all: [], none: [])
28
36
  matches_any(any) && matches_all(all) && matches_none(none)
29
37
  end
@@ -36,6 +44,7 @@ class ::String
36
44
  end
37
45
 
38
46
  def matches_any(regexes)
47
+ string = dup
39
48
  regexes.each do |rx|
40
49
  return true if match(Regexp.new(rx, Regexp::IGNORECASE))
41
50
  end
data/lib/na/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Na
2
- VERSION = '1.1.12'
2
+ VERSION = '1.1.13'
3
3
  end
data/src/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  _If you're one of the rare people like me who find this useful, feel free to
10
10
  [buy me some coffee][donate]._
11
11
 
12
- The current version of `na` is <!--VER-->1.1.11<!--END VER-->.
12
+ The current version of `na` is <!--VER-->1.1.12<!--END VER-->.
13
13
 
14
14
  `na` ("next action") is a command line tool designed to make it easy to see what your next actions are for any project, right from the command line. It works with TaskPaper-formatted files (but any plain text format will do), looking for `@na` tags (or whatever you specify) in todo files in your current folder.
15
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: na
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.12
4
+ version: 1.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra