todo-jsonl 1.0.1 → 1.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 +4 -4
- data/bin/todo.rb +34 -26
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a12de5f4f64f3d33b1168b0c39dc69335435ce4229dea4855c46aa70ccc7b0a3
|
4
|
+
data.tar.gz: '018b97ef5b26f06143955d7cef8cdfd92c8dec7932b64a20721636e4a1800f8d'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acc30afd6f1d97e6f3752ec1b0350a73c61c350490836d85c5aa308312f2337ecfb0391ed43d90fec7953e4611af27b7e90559f57cd8fc078b65a924a55fb473
|
7
|
+
data.tar.gz: 834d2ff05757b86babd4a8b640f37b0516a54d6f76941aaaad9cbab525c3c33c0b6080eb9caf432a04b959a33344e3c51b45db2272203ed0898bf446e5bea453
|
data/bin/todo.rb
CHANGED
@@ -69,7 +69,7 @@ class Todo
|
|
69
69
|
DUE_DATE_TAG_PATTERN = /(^| )due:([a-zA-Z0-9-]+)/
|
70
70
|
CONTEXT_TAG_PATTERN = /(^| )[@+][\w-]+/
|
71
71
|
PRIORITY_FLAG = '*'
|
72
|
-
TODO_FILE =
|
72
|
+
TODO_FILE = File.join(Dir.home, 'todo.jsonl')
|
73
73
|
|
74
74
|
def execute(arguments)
|
75
75
|
begin
|
@@ -107,8 +107,8 @@ class Todo
|
|
107
107
|
raise action + ' command requires at least two parameters' if args.length < 2
|
108
108
|
add_note(args.first.to_i, args[1..-1].join(' '))
|
109
109
|
when 'delnote'
|
110
|
-
raise action + ' command requires
|
111
|
-
delete_note(args.first.to_i)
|
110
|
+
raise action + ' command requires one or two parameters' if args.length < 1 || args.length > 2
|
111
|
+
delete_note(args.first.to_i, args[1])
|
112
112
|
when 'list'
|
113
113
|
list(nil, args)
|
114
114
|
when 'show'
|
@@ -126,7 +126,7 @@ class Todo
|
|
126
126
|
else
|
127
127
|
list(nil, arguments)
|
128
128
|
end
|
129
|
-
rescue => error
|
129
|
+
rescue StandardError => error
|
130
130
|
puts "#{colorize('ERROR:', :red)} #{error}"
|
131
131
|
end
|
132
132
|
self
|
@@ -151,7 +151,7 @@ class Todo
|
|
151
151
|
* rename <tasknumber> <text> rename task
|
152
152
|
* del <tasknumber> delete task
|
153
153
|
* note <tasknumber> <text> add note to task
|
154
|
-
* delnote <tasknumber>
|
154
|
+
* delnote <tasknumber> [number] delete a specific or all notes from task
|
155
155
|
|
156
156
|
* list <regex> [regex...] list tasks (only active tasks by default)
|
157
157
|
* show <tasknumber> show all task details
|
@@ -163,9 +163,10 @@ class Todo
|
|
163
163
|
#{@queries.keys.each_with_index.map { |k, i| (i == 8 ? "\n" : '') + k }.join(', ')}
|
164
164
|
|
165
165
|
Due dates can be also added via tags in task title: "due:YYYY-MM-DD"
|
166
|
+
In addition to formatted dates, you can use date synonyms:
|
167
|
+
"due:today", "due:tomorrow", and day names e.g. "due:monday" or "due:tue"
|
166
168
|
|
167
|
-
Legend:
|
168
|
-
#{STATES.select { |k, v| k != 'default' }.map { |k, v| "#{k} #{v}" }.join(', ') }, priority #{PRIORITY_FLAG}
|
169
|
+
Legend: #{STATES.select { |k, v| k != 'default' }.map { |k, v| "#{k} #{v}" }.join(', ') }, priority #{PRIORITY_FLAG}
|
169
170
|
|
170
171
|
Todo file: #{TODO_FILE}
|
171
172
|
USAGE
|
@@ -176,6 +177,7 @@ class Todo
|
|
176
177
|
next_7_days = (0..6).map { |day| @today + day }
|
177
178
|
@due_date_days = next_7_days.map { |day| day.strftime('%A').downcase }
|
178
179
|
due_dates_for_queries = next_7_days.map { |day| day.strftime(DATE_FORMAT) }
|
180
|
+
recent_date = (@today - 7).strftime(DATE_FORMAT)
|
179
181
|
@queries = {
|
180
182
|
':active' => lambda { |task| /(new|started|blocked)/.match(task[:state]) },
|
181
183
|
':done' => lambda { |task| 'done' == task[:state] },
|
@@ -189,7 +191,8 @@ class Todo
|
|
189
191
|
':tomorrow' => lambda { |task| due_dates_for_queries[1] == task[:due] },
|
190
192
|
':next7days' => lambda { |task| /(#{due_dates_for_queries.join('|')})/.match(task[:due]) },
|
191
193
|
':overdue' => lambda { |task| task[:due] && task[:due] < due_dates_for_queries[0] },
|
192
|
-
':due' => lambda { |task| task[:due] }
|
194
|
+
':due' => lambda { |task| task[:due] },
|
195
|
+
':recent' => lambda { |task| recent_date <= task[:modified] }
|
193
196
|
}
|
194
197
|
end
|
195
198
|
|
@@ -211,9 +214,7 @@ class Todo
|
|
211
214
|
|
212
215
|
def write_tasks(tasks)
|
213
216
|
File.open(TODO_FILE, 'w:UTF-8') do |file|
|
214
|
-
tasks.keys.sort.each
|
215
|
-
file.write(JSON.generate(tasks[key]) + "\n")
|
216
|
-
end
|
217
|
+
tasks.keys.sort.each { |key| file.write(JSON.generate(tasks[key]) + "\n") }
|
217
218
|
end
|
218
219
|
end
|
219
220
|
|
@@ -227,15 +228,9 @@ class Todo
|
|
227
228
|
end
|
228
229
|
|
229
230
|
def add(text)
|
230
|
-
task = {
|
231
|
-
state: 'new',
|
232
|
-
title: text,
|
233
|
-
modified: @today.strftime(DATE_FORMAT)
|
234
|
-
}
|
231
|
+
task = { state: 'new', title: text, modified: @today.strftime(DATE_FORMAT) }
|
235
232
|
postprocess_tags(task)
|
236
|
-
File.open(TODO_FILE, 'a:UTF-8')
|
237
|
-
file.write(JSON.generate(task) + "\n")
|
238
|
-
end
|
233
|
+
File.open(TODO_FILE, 'a:UTF-8') { |file| file.write(JSON.generate(task) + "\n") }
|
239
234
|
list
|
240
235
|
end
|
241
236
|
|
@@ -305,7 +300,12 @@ class Todo
|
|
305
300
|
patterns ||= []
|
306
301
|
patterns += [':active'] if (patterns & [':active', ':done', ':blocked', ':started', ':new', ':all']).empty?
|
307
302
|
items = filter_tasks(tasks, patterns).sort_by do |num, task|
|
308
|
-
[
|
303
|
+
[
|
304
|
+
task[:priority] && task[:state] != 'done' ? 0 : 1,
|
305
|
+
ORDER[task[:state] || 'default'],
|
306
|
+
task[:state] != 'done' ? task[:due] || 'n/a' : task[:modified],
|
307
|
+
num
|
308
|
+
]
|
309
309
|
end
|
310
310
|
items.each do |num, task|
|
311
311
|
state = task[:state] || 'default'
|
@@ -326,7 +326,7 @@ class Todo
|
|
326
326
|
end
|
327
327
|
due_date = ' ' + due_date
|
328
328
|
end
|
329
|
-
puts "#{num.to_s.rjust(task_indent
|
329
|
+
puts "#{num.to_s.rjust(task_indent)}:#{priority_flag}#{display_state} #{title}#{due_date}"
|
330
330
|
end
|
331
331
|
puts 'No todos found' if items.empty?
|
332
332
|
end
|
@@ -338,17 +338,25 @@ class Todo
|
|
338
338
|
end)
|
339
339
|
end
|
340
340
|
|
341
|
-
def delete_note(item)
|
341
|
+
def delete_note(item, num = nil)
|
342
342
|
update_task(item, :show, lambda do |task|
|
343
|
-
|
343
|
+
if num.to_s.empty?
|
344
|
+
task.delete(:note)
|
345
|
+
else
|
346
|
+
raise "#{num.to_i}: Note does not exist" if num.to_i <= 0 || task[:note].to_a.size < num.to_i
|
347
|
+
task[:note].delete_at(num.to_i - 1)
|
348
|
+
task.delete(:note) if task[:note].empty?
|
349
|
+
end
|
344
350
|
end)
|
345
351
|
end
|
346
352
|
|
347
353
|
def show(item, tasks = nil)
|
348
354
|
tasks ||= load_tasks(item)
|
349
|
-
tasks[item].each do |
|
350
|
-
|
351
|
-
|
355
|
+
tasks[item].each do |k, v|
|
356
|
+
v = "\n" + v.each_with_index.
|
357
|
+
map { |n, i| v.size > 1 ? "#{(i + 1).to_s.rjust(v.size.to_s.size)}: #{n}" : n }.
|
358
|
+
join("\n") if v.is_a?(Array)
|
359
|
+
puts "#{colorize(k.to_s.rjust(10) + ':', :cyan)} #{v}"
|
352
360
|
end
|
353
361
|
end
|
354
362
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: todo-jsonl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabor Bata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -32,7 +32,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version:
|
35
|
+
version: 2.5.0
|
36
36
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|