markdown_exec 0.2.0 → 0.2.1
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/CHANGELOG.md +5 -0
- data/README.md +6 -9
- data/assets/approve.png +0 -0
- data/assets/blocks.png +0 -0
- data/assets/executed.png +0 -0
- data/assets/select.png +0 -0
- data/assets/select_file.png +0 -0
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/markdown_exec.rb +50 -11
- 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: 7a2b550aaccca7d0752e57c39808f5d8d3b889b9d74cf3330dee6832b2f6c535
|
4
|
+
data.tar.gz: 1296490dd79071f78b5009cb843c911fe822257ed148b4c1a516366eb02407ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43f659be4397e4bb24811a8219de7b58e9665aa8751063281e2cfbbf94263ceda15f411a34fe31293869f0bbdba761c2afce72ea7f800b54edba75424313bd19
|
7
|
+
data.tar.gz: bd48ac8a5ebedbc8b92af6345743d1bd6cf50705d05769e7144ccad998ddf0f00de72366779cb654a4272c3cc2f044c4c7e46ae9df935dcb4fc486a67e54453e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.1] - 2022-03-12
|
4
|
+
|
5
|
+
- Accept file or folder as first optional positional argument.
|
6
|
+
- Hide blocks with parentheses in the name, like "(name)". This is useful for blocks that are to be required and not selected to execute alone.
|
7
|
+
|
3
8
|
## [0.2.0] - 2022-03-12
|
4
9
|
|
5
10
|
- Improve processing of file and path sepcs.
|
data/README.md
CHANGED
@@ -25,9 +25,11 @@ Displays help information.
|
|
25
25
|
Process `README.md` file in the current folder. Displays all the blocks in the file and allows you to select using [up], [down], and [return]. Press [ctrl]-c to abort selection.
|
26
26
|
|
27
27
|
`mde -f my.md`
|
28
|
+
`mde my.md`
|
28
29
|
Select a block to execute from `my.md`.
|
29
30
|
|
30
31
|
`mde -p .`
|
32
|
+
`mde .`
|
31
33
|
Select a markdown file in the current folder. Select a block to execute from that file.
|
32
34
|
|
33
35
|
`mde --list-blocks`
|
@@ -52,31 +54,26 @@ e.g. Use to set the default file for the current folder.
|
|
52
54
|
|
53
55
|
# Example blocks
|
54
56
|
|
55
|
-
When prompted, select either the `awake` or `asleep` block.
|
57
|
+
When prompted, select either the `awake` or `asleep` block.
|
56
58
|
|
57
59
|
``` :(day)
|
58
|
-
|
59
|
-
export MYTIME=early
|
60
|
+
export TIME=early
|
60
61
|
```
|
61
62
|
|
62
63
|
``` :(night)
|
63
|
-
|
64
|
-
export MYTIME=late
|
64
|
+
export TIME=late
|
65
65
|
```
|
66
66
|
|
67
67
|
``` :awake +(day) +(report)
|
68
|
-
# block named "awake", select to see result
|
69
68
|
export ACTIVITY=awake
|
70
69
|
```
|
71
70
|
|
72
71
|
``` :asleep +(night) +(report)
|
73
|
-
# block named "asleep", select to see result
|
74
72
|
export ACTIVITY=asleep
|
75
73
|
```
|
76
74
|
|
77
75
|
``` :(report)
|
78
|
-
|
79
|
-
echo "time: $MYTIME, activity: $ACTIVITY"
|
76
|
+
echo "$TIME -> $ACTIVITY"
|
80
77
|
```
|
81
78
|
|
82
79
|
## Example blocks
|
data/assets/approve.png
CHANGED
Binary file
|
data/assets/blocks.png
CHANGED
Binary file
|
data/assets/executed.png
CHANGED
Binary file
|
data/assets/select.png
CHANGED
Binary file
|
data/assets/select_file.png
CHANGED
Binary file
|
data/lib/markdown_exec.rb
CHANGED
@@ -123,28 +123,35 @@ module MarkdownExec
|
|
123
123
|
#
|
124
124
|
|
125
125
|
lm = line.match(/^`{3,}([^`\s]*) *(.*)$/)
|
126
|
-
|
127
126
|
do1 = false
|
128
127
|
if opts[:bash_only]
|
129
128
|
do1 = true if lm && (lm[1] == 'bash')
|
130
|
-
elsif opts[:exclude_expect_blocks]
|
131
|
-
do1 = true unless lm && (lm[1] == 'expect')
|
132
129
|
else
|
133
130
|
do1 = true
|
131
|
+
do1 = !(lm && (lm[1] == 'expect')) if opts[:exclude_expect_blocks]
|
132
|
+
|
133
|
+
# if do1 && opts[:exclude_matching_block_names]
|
134
|
+
# puts " MW a4"
|
135
|
+
# puts " MW a4 #{(lm[2].match %r{^:\(.+\)$})}"
|
136
|
+
# do1 = !(lm && (lm[2].match %r{^:\(.+\)$}))
|
137
|
+
# end
|
134
138
|
end
|
135
139
|
|
140
|
+
in_block = true
|
136
141
|
if do1 && (!opts[:title_match] || (lm && lm[2] && lm[2].match(opts[:title_match])))
|
137
142
|
current = []
|
138
|
-
in_block = true
|
139
143
|
block_title = (lm && lm[2])
|
140
144
|
end
|
141
|
-
|
142
145
|
end
|
143
146
|
elsif current
|
144
147
|
current += [line.chomp]
|
145
148
|
end
|
146
149
|
end
|
147
150
|
blocks.tap { |ret| puts "list_blocks_in_file() ret: #{ret.inspect}" if $pdebug }
|
151
|
+
# blocks.map do |block|
|
152
|
+
# next if opts[:exclude_matching_block_names] && block[:name].match(%r{^\(.+\)$})
|
153
|
+
# block
|
154
|
+
# end.compact.tap { |ret| puts "list_blocks_in_file() ret: #{ret.inspect}" if $pdebug }
|
148
155
|
end
|
149
156
|
|
150
157
|
def list_files_per_options(options)
|
@@ -184,6 +191,15 @@ module MarkdownExec
|
|
184
191
|
Dir.glob(File.join(options[:folder], '*.md'))
|
185
192
|
end
|
186
193
|
|
194
|
+
def list_named_blocks_in_file(call_options = {}, &options_block)
|
195
|
+
opts = optsmerge call_options, options_block
|
196
|
+
list_blocks_in_file(opts).map do |block|
|
197
|
+
next if opts[:exclude_matching_block_names] && block[:name].match(/^\(.+\)$/)
|
198
|
+
|
199
|
+
block
|
200
|
+
end.compact.tap { |ret| puts "list_named_blocks_in_file() ret: #{ret.inspect}" if $pdebug }
|
201
|
+
end
|
202
|
+
|
187
203
|
def code(table, block)
|
188
204
|
all = [block[:name]] + recursively_required(table, block[:reqs])
|
189
205
|
all.reverse.map do |req|
|
@@ -217,7 +233,17 @@ module MarkdownExec
|
|
217
233
|
def make_block_labels(call_options = {})
|
218
234
|
opts = options.merge(call_options)
|
219
235
|
list_blocks_in_file(opts).map do |block|
|
236
|
+
# next if opts[:exclude_matching_block_names] && block[:name].match(%r{^:\(.+\)$})
|
237
|
+
|
220
238
|
make_block_label block, opts
|
239
|
+
end.compact.tap { |ret| puts "make_block_labels() ret: #{ret.inspect}" if $pdebug }
|
240
|
+
end
|
241
|
+
|
242
|
+
def option_exclude_blocks(opts, blocks)
|
243
|
+
if opts[:exclude_matching_block_names]
|
244
|
+
blocks.reject { |block| block[:name].match(/^\(.+\)$/) }
|
245
|
+
else
|
246
|
+
blocks
|
221
247
|
end
|
222
248
|
end
|
223
249
|
|
@@ -278,7 +304,7 @@ module MarkdownExec
|
|
278
304
|
executable_name = File.basename($PROGRAM_NAME)
|
279
305
|
opts.banner = [
|
280
306
|
"#{MarkdownExec::APP_NAME} - #{MarkdownExec::APP_DESC} (#{MarkdownExec::VERSION})",
|
281
|
-
"Usage: #{executable_name} [options]"
|
307
|
+
"Usage: #{executable_name} [filename or path] [options]"
|
282
308
|
].join("\n")
|
283
309
|
|
284
310
|
## menu top: items appear in reverse order added
|
@@ -293,7 +319,7 @@ module MarkdownExec
|
|
293
319
|
options[:filename] = value
|
294
320
|
end
|
295
321
|
|
296
|
-
opts.on('-p PATH', '--
|
322
|
+
opts.on('-p PATH', '--path', 'Path to documents') do |value|
|
297
323
|
options[:folder] = value
|
298
324
|
end
|
299
325
|
|
@@ -328,9 +354,17 @@ module MarkdownExec
|
|
328
354
|
end
|
329
355
|
option_parser.load # filename defaults to basename of the program without suffix in a directory ~/.options
|
330
356
|
option_parser.environment # env defaults to the basename of the program.
|
331
|
-
option_parser.parse! # (into: options)
|
357
|
+
rest = option_parser.parse! # (into: options)
|
332
358
|
options_finalize.call options
|
333
359
|
|
360
|
+
if rest.fetch(0, nil)&.present?
|
361
|
+
if Dir.exist?(rest[0])
|
362
|
+
options[:folder] = rest[0]
|
363
|
+
elsif File.exist?(rest[0])
|
364
|
+
options[:filename] = rest[0]
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
334
368
|
## process
|
335
369
|
#
|
336
370
|
options.merge!(
|
@@ -339,6 +373,7 @@ module MarkdownExec
|
|
339
373
|
bash: true,
|
340
374
|
display: true,
|
341
375
|
exclude_expect_blocks: true,
|
376
|
+
exclude_matching_block_names: true,
|
342
377
|
execute: true,
|
343
378
|
prompt: 'Execute',
|
344
379
|
struct: true
|
@@ -375,8 +410,14 @@ module MarkdownExec
|
|
375
410
|
prompt = TTY::Prompt.new(interrupt: :exit)
|
376
411
|
pt = "#{opts.fetch(:prompt, nil) || 'Pick one'}:"
|
377
412
|
|
413
|
+
# blocks.map do |block|
|
414
|
+
# next if opts[:exclude_matching_block_names] && block[:name].match(%r{^\(.+\)$})
|
415
|
+
# block
|
416
|
+
# end.compact.tap { |ret| puts "list_blocks_in_file() ret: #{ret.inspect}" if $pdebug }
|
417
|
+
|
378
418
|
blocks.each { |block| block.merge! label: make_block_label(block, opts) }
|
379
|
-
block_labels = blocks.map { |block| block[:label] }
|
419
|
+
# block_labels = blocks.map { |block| block[:label] }
|
420
|
+
block_labels = option_exclude_blocks(opts, blocks).map { |block| block[:label] }
|
380
421
|
|
381
422
|
if opts[:preview_options]
|
382
423
|
select_per_page = 3
|
@@ -406,8 +447,6 @@ module MarkdownExec
|
|
406
447
|
selected = get_block_by_name blocks, sel
|
407
448
|
if allow && opts[:execute]
|
408
449
|
|
409
|
-
## process in script, to handle line continuations
|
410
|
-
#
|
411
450
|
cmd2 = cbs.flatten.join("\n")
|
412
451
|
|
413
452
|
Open3.popen3(cmd2) do |stdin, stdout, stderr|
|