markdown_exec 1.8.6 → 1.8.8
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/.pryrc +0 -1
- data/.rubocop.yml +3 -2
- data/CHANGELOG.md +45 -3
- data/Gemfile +1 -0
- data/Gemfile.lock +7 -1
- data/Rakefile +1 -0
- data/bin/bmde +1 -1
- data/bin/tab_completion.sh +4 -4
- data/examples/colors.md +2 -1
- data/examples/indent.md +66 -0
- data/examples/linked.md +20 -1
- data/examples/load1.sh +5 -0
- data/examples/load2.sh +5 -0
- data/examples/nickname.md +26 -0
- data/examples/opts.md +2 -0
- data/lib/ansi_formatter.rb +1 -5
- data/lib/array.rb +4 -0
- data/lib/cached_nested_file_reader.rb +47 -43
- data/lib/ce_get_cost_and_usage.rb +22 -0
- data/lib/constants.rb +7 -0
- data/lib/exceptions.rb +6 -4
- data/lib/fcb.rb +5 -2
- data/lib/filter.rb +21 -11
- data/lib/find_files.rb +99 -0
- data/lib/hash_delegator.rb +1358 -1179
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/mdoc.rb +59 -39
- data/lib/menu.src.yml +201 -21
- data/lib/menu.yml +155 -11
- data/lib/saved_assets.rb +10 -8
- metadata +10 -8
- data/lib/method_sorter.rb +0 -78
- data/lib/pty1.rb +0 -26
- data/lib/regexp_replacer.rb +0 -58
- data/lib/sort_yaml_gpt4.rb +0 -32
data/lib/menu.yml
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# MDE - Markdown Executor (1.8.
|
1
|
+
# MDE - Markdown Executor (1.8.8)
|
2
2
|
---
|
3
3
|
- :description: Show current configuration values
|
4
4
|
:procname: show_config
|
5
5
|
:short_name: '0'
|
6
6
|
- :arg_name: BOOL
|
7
|
-
:default:
|
7
|
+
:default: true
|
8
8
|
:description: Display only blocks of type "bash"
|
9
9
|
:env_var: MDE_BASH_ONLY
|
10
10
|
:opt_name: bash_only
|
@@ -26,7 +26,7 @@
|
|
26
26
|
:env_var: MDE_BLOCK_NAME_HIDDEN_MATCH
|
27
27
|
:opt_name: block_name_hidden_match
|
28
28
|
:procname: val_as_str
|
29
|
-
- :default: "
|
29
|
+
- :default: "^\\(.*\\)$"
|
30
30
|
:description: Pattern for blocks to hide from user-selection
|
31
31
|
:env_var: MDE_BLOCK_NAME_INCLUDE_MATCH
|
32
32
|
:opt_name: block_name_include_match
|
@@ -35,6 +35,11 @@
|
|
35
35
|
:env_var: MDE_BLOCK_NAME_MATCH
|
36
36
|
:opt_name: block_name_match
|
37
37
|
:procname: val_as_str
|
38
|
+
- :default: "^\\[.*\\]$"
|
39
|
+
:description: Pattern for block nicknames (name is not used in menu)
|
40
|
+
:env_var: MDE_BLOCK_NAME_NICK_MATCH
|
41
|
+
:opt_name: block_name_nick_match
|
42
|
+
:procname: val_as_str
|
38
43
|
- :default: "^{.+}$"
|
39
44
|
:description: Pattern for block names to use as wrappers
|
40
45
|
:env_var: MDE_BLOCK_NAME_WRAPPER_MATCH
|
@@ -61,6 +66,12 @@
|
|
61
66
|
:description: Read configuration file
|
62
67
|
:long_name: config
|
63
68
|
:procname: path
|
69
|
+
- :arg_name: BOOL
|
70
|
+
:default: true
|
71
|
+
:description: debounce_execution
|
72
|
+
:env_var: MDE_debounce_execution
|
73
|
+
:opt_name: debounce_execution
|
74
|
+
:procname: val_as_bool
|
64
75
|
- :arg_name: BOOL
|
65
76
|
:default: false
|
66
77
|
:description: Debug output
|
@@ -152,6 +163,46 @@
|
|
152
163
|
:env_var: MDE_EXCLUDE_EXPECT_BLOCKS
|
153
164
|
:opt_name: exclude_expect_blocks
|
154
165
|
:procname: val_as_bool
|
166
|
+
- :default: "osascript -e '\n tell application \"iTerm\"\n tell application
|
167
|
+
\"System Events\"\n tell application \"Finder\"\n set
|
168
|
+
{posx, posy, screenWidth, screenHeight} to bounds of window of desktop\n end
|
169
|
+
tell\n tell application process \"Finder\"\n set {missing
|
170
|
+
value, menubarHeight} to the size of menu bar 1\n end tell\n end
|
171
|
+
tell\n\n set winHeight to (screenHeight * 2 / 3)\n set winWidth
|
172
|
+
to (screenWidth / 2)\n set xoff to menubarHeight * %{batch_index}\n set
|
173
|
+
yoff to xoff mod (screenHeight - winHeight)\n \n create window with
|
174
|
+
default profile\n tell the first window\n set bounds to {xoff,
|
175
|
+
yoff, xoff + winWidth, yoff + winHeight}\n tell the current session\n
|
176
|
+
\ write text \"alias cat_script=\\\"cat -n \\\\\\\"%{script_filespec}\\\\\\\"\\\"\"\n
|
177
|
+
\ write text \"alias less_script=\\\"less \\\\\\\"%{script_filespec}\\\\\\\"\\\"\"\n
|
178
|
+
\ write text \"alias run_script=\\\"%{script_filespec}\\\"\"\n write
|
179
|
+
text \"alias vim_script=\\\"vim \\\\\\\"%{script_filespec}\\\\\\\"\\\"\"\n delay
|
180
|
+
1\n\n write text \"alias cat_output=\\\"cat -n \\\\\\\"%{output_filespec}\\\\\\\"\\\"\"\n
|
181
|
+
\ write text \"alias grep_output=\\\"read -p Pattern: pattern &&
|
182
|
+
grep \\\\\\\"\\\\$pattern\\\\\\\" \\\\\\\"%{output_filespec}\\\\\\\"\\\"\"\n write
|
183
|
+
text \"alias less_output=\\\"less \\\\\\\"%{output_filespec}\\\\\\\"\\\"\"\n delay
|
184
|
+
1\n\n write text \"alias menu=\\\"select cmd in cat_script less_script
|
185
|
+
run_script vim_script cat_output grep_output less_output exit; do eval \\\\\\\"\\\\$cmd\\\\\\\";
|
186
|
+
done\\\"\"\n delay 1\n\n write text \"echo -ne \\\"\\\\033];
|
187
|
+
%{started_at} - %{document_filename} - %{block_name} \\\\007\\\"\"\n write
|
188
|
+
text \"cd \\\"%{home}\\\"\"\n write text \"\\\"%{script_filename}\\\"
|
189
|
+
| tee \\\"%{output_filespec}\\\"\"\n delay 2\n\n write
|
190
|
+
text \"menu\"\n end tell\n end tell\n end tell'\n"
|
191
|
+
:description: execute_command_format
|
192
|
+
:env_var: MDE_EXECUTE_COMMAND_FORMAT
|
193
|
+
:opt_name: execute_command_format
|
194
|
+
:procname: val_as_str
|
195
|
+
- :default: "%T"
|
196
|
+
:description: Format for time in window title
|
197
|
+
:env_var: MDE_EXECUTE_COMMAND_TITLE_TIME_FORMAT
|
198
|
+
:opt_name: execute_command_title_time_format
|
199
|
+
:procname: val_as_str
|
200
|
+
- :arg_name: BOOL
|
201
|
+
:default: true
|
202
|
+
:description: Execute script in own window
|
203
|
+
:env_var: MDE_EXECUTE_IN_OWN_WINDOW
|
204
|
+
:opt_name: execute_in_own_window
|
205
|
+
:procname: val_as_bool
|
155
206
|
- :default: fg_rgbh_7f_ff_00
|
156
207
|
:description: execution_report_preview_frame_color
|
157
208
|
:env_var: MDE_EXECUTION_REPORT_PREVIEW_FRAME_COLOR
|
@@ -205,15 +256,15 @@
|
|
205
256
|
:long_name: find-path
|
206
257
|
:opt_name: find_path
|
207
258
|
:procname: val_as_str
|
208
|
-
- :default: "^# *(?<
|
259
|
+
- :default: "^# *(?<line>[^#]*?) *$"
|
209
260
|
:env_var: MDE_HEADING1_MATCH
|
210
261
|
:opt_name: heading1_match
|
211
262
|
:procname: val_as_str
|
212
|
-
- :default: "^## *(?<
|
263
|
+
- :default: "^## *(?<line>[^#]*?) *$"
|
213
264
|
:env_var: MDE_HEADING2_MATCH
|
214
265
|
:opt_name: heading2_match
|
215
266
|
:procname: val_as_str
|
216
|
-
- :default: "^### *(?<
|
267
|
+
- :default: "^### *(?<line>.+?) *$"
|
217
268
|
:env_var: MDE_HEADING3_MATCH
|
218
269
|
:opt_name: heading3_match
|
219
270
|
:procname: val_as_str
|
@@ -243,6 +294,10 @@
|
|
243
294
|
:long_name: how
|
244
295
|
:procname: how
|
245
296
|
:short_name: "?"
|
297
|
+
- :default:
|
298
|
+
:env_var: MDE_IMPORT_PATHS
|
299
|
+
:opt_name: import_paths
|
300
|
+
:procname: val_as_str
|
246
301
|
- :default: "^ *@import +(?<name>.+?) *$"
|
247
302
|
:env_var: MDE_IMPORT_PATTERN
|
248
303
|
:opt_name: import_pattern
|
@@ -308,7 +363,7 @@
|
|
308
363
|
:opt_name: menu_blocks_with_docname
|
309
364
|
:procname: val_as_bool
|
310
365
|
- :arg_name: BOOL
|
311
|
-
:default:
|
366
|
+
:default: true
|
312
367
|
:description: Controls whether headings(levels 1,2,3) are displayed in the block
|
313
368
|
selection menu
|
314
369
|
:env_var: MDE_MENU_BLOCKS_WITH_HEADINGS
|
@@ -356,6 +411,36 @@
|
|
356
411
|
:env_var: MDE_MENU_FINAL_DIVIDER
|
357
412
|
:opt_name: menu_final_divider
|
358
413
|
:procname: val_as_str
|
414
|
+
- :default: fg_rgbh_80_80_c0
|
415
|
+
:description: Color for heading 1 in menu
|
416
|
+
:env_var: MDE_MENU_HEADING1_COLOR
|
417
|
+
:opt_name: menu_heading1_color
|
418
|
+
:procname: val_as_str
|
419
|
+
- :default: "# %{line}"
|
420
|
+
:description: format for menu heading1 in menu
|
421
|
+
:env_var: MDE_MENU_HEADING1_FORMAT
|
422
|
+
:opt_name: menu_heading1_format
|
423
|
+
:procname: val_as_str
|
424
|
+
- :default: fg_rgbh_60_60_c0
|
425
|
+
:description: Color for heading 2 in menu
|
426
|
+
:env_var: MDE_MENU_HEADING2_COLOR
|
427
|
+
:opt_name: menu_heading2_color
|
428
|
+
:procname: val_as_str
|
429
|
+
- :default: "## %{line}"
|
430
|
+
:description: format for menu heading2 in menu
|
431
|
+
:env_var: MDE_MENU_HEADING2_FORMAT
|
432
|
+
:opt_name: menu_heading2_format
|
433
|
+
:procname: val_as_str
|
434
|
+
- :default: fg_rgbh_40_40_c0
|
435
|
+
:description: Color for heading 3 in menu
|
436
|
+
:env_var: MDE_MENU_HEADING3_COLOR
|
437
|
+
:opt_name: menu_heading3_color
|
438
|
+
:procname: val_as_str
|
439
|
+
- :default: "### %{line}"
|
440
|
+
:description: format for menu heading3 in menu
|
441
|
+
:env_var: MDE_MENU_HEADING3_FORMAT
|
442
|
+
:opt_name: menu_heading3_format
|
443
|
+
:procname: val_as_str
|
359
444
|
- :default: '0'
|
360
445
|
:description: Import levels for blocks to appear in menu. Empty is all.
|
361
446
|
:env_var: MDE_MENU_IMPORT_LEVEL_MATCH
|
@@ -373,6 +458,22 @@
|
|
373
458
|
:env_var: MDE_MENU_INCLUDE_IMPORTED_NOTES
|
374
459
|
:opt_name: menu_include_imported_notes
|
375
460
|
:procname: val_as_bool
|
461
|
+
- :arg_name: BOOL
|
462
|
+
:default: true
|
463
|
+
:description: Display inherited lines at top of menu (vs bottom)
|
464
|
+
:env_var: MDE_MENU_INHERITED_LINES_AT_TOP
|
465
|
+
:opt_name: menu_inherited_lines_at_top
|
466
|
+
:procname: val_as_bool
|
467
|
+
- :default: fg_rgbh_94_00_D3
|
468
|
+
:description: Color of inherited lines in menu
|
469
|
+
:env_var: MDE_MENU_INHERITED_LINES_COLOR
|
470
|
+
:opt_name: menu_inherited_lines_color
|
471
|
+
:procname: val_as_str
|
472
|
+
- :default: "%{line}"
|
473
|
+
:description: format for inherited lines in menu
|
474
|
+
:env_var: MDE_MENU_INHERITED_LINES_FORMAT
|
475
|
+
:opt_name: menu_inherited_lines_format
|
476
|
+
:procname: val_as_str
|
376
477
|
- :default:
|
377
478
|
:line: ''
|
378
479
|
:description: opening demarcation for menu
|
@@ -431,6 +532,11 @@
|
|
431
532
|
:env_var: MDE_MENU_OPTS_SET_FORMAT
|
432
533
|
:opt_name: menu_opts_set_format
|
433
534
|
:procname: val_as_str
|
535
|
+
- :default: "."
|
536
|
+
:description: Block name to display menu
|
537
|
+
:env_var: MDE_MENU_PERSIST_BLOCK_NAME
|
538
|
+
:opt_name: menu_persist_block_name
|
539
|
+
:procname: val_as_str
|
434
540
|
- :default: fg_rgbh_ff_ff_ff
|
435
541
|
:description: Color of menu task
|
436
542
|
:env_var: MDE_MENU_TASK_COLOR
|
@@ -478,12 +584,38 @@
|
|
478
584
|
:env_var: MDE_MENU_WITH_EXIT
|
479
585
|
:opt_name: menu_with_exit
|
480
586
|
:procname: val_as_bool
|
587
|
+
- :arg_name: BOOL
|
588
|
+
:default: true
|
589
|
+
:description: Display inherited lines in menu
|
590
|
+
:env_var: MDE_MENU_WITH_INHERITED_LINES
|
591
|
+
:opt_name: menu_with_inherited_lines
|
592
|
+
:procname: val_as_bool
|
481
593
|
- :arg_name: BOOL
|
482
594
|
:default: false
|
483
595
|
:description: Hide decorative menu entries
|
484
596
|
:env_var: MDE_NO_CHROME
|
485
597
|
:opt_name: no_chrome
|
486
598
|
:procname: val_as_bool
|
599
|
+
- :default:
|
600
|
+
:description: Expression to match to start collecting lines
|
601
|
+
:env_var: MDE_OUTPUT_ASSIGNMENT_BEGIN
|
602
|
+
:opt_name: output_assignment_begin
|
603
|
+
:procname: val_as_str
|
604
|
+
- :default:
|
605
|
+
:description: Expression to match to stop collecting lines
|
606
|
+
:env_var: MDE_OUTPUT_ASSIGNMENT_END
|
607
|
+
:opt_name: output_assignment_begin
|
608
|
+
:procname: val_as_str
|
609
|
+
- :default: "%{line} # !!!"
|
610
|
+
:description: Format for assignments from output
|
611
|
+
:env_var: MDE_OUTPUT_ASSIGNMENT_FORMAT
|
612
|
+
:opt_name: output_assignment_format
|
613
|
+
:procname: val_as_str
|
614
|
+
- :default: "^ *(\\w+=.*?) *$"
|
615
|
+
:description: Pattern for assignments from output
|
616
|
+
:env_var: MDE_OUTPUT_ASSIGNMENT_MATCH
|
617
|
+
:opt_name: output_assignment_match
|
618
|
+
:procname: val_as_str
|
487
619
|
- :arg_name: BOOL
|
488
620
|
:default: false
|
489
621
|
:description: Display summary for execution
|
@@ -539,7 +671,7 @@
|
|
539
671
|
:procname: val_as_str
|
540
672
|
:short_name: p
|
541
673
|
- :arg_name: BOOL
|
542
|
-
:default:
|
674
|
+
:default: false
|
543
675
|
:description: Wheter to pause after manually executing a block and the next menu
|
544
676
|
:env_var: MDE_PAUSE_AFTER_SCRIPT_EXECUTION
|
545
677
|
:opt_name: pause_after_script_execution
|
@@ -563,6 +695,13 @@
|
|
563
695
|
:env_var: MDE_PROMPT_COLOR_AFTER_SCRIPT_EXECUTION
|
564
696
|
:opt_name: prompt_color_after_script_execution
|
565
697
|
:procname: val_as_str
|
698
|
+
- :default: |2-
|
699
|
+
|
700
|
+
Repeat this block?
|
701
|
+
:description: Prompt to debounce
|
702
|
+
:env_var: MDE_PROMPT_DEBOUNCE
|
703
|
+
:opt_name: prompt_debounce
|
704
|
+
:procname: val_as_str
|
566
705
|
- :default: Exit
|
567
706
|
:description: Prompt to exit app
|
568
707
|
:env_var: MDE_PROMPT_EXIT
|
@@ -604,6 +743,11 @@
|
|
604
743
|
:env_var: MDE_PROMPT_SELECT_OUTPUT
|
605
744
|
:opt_name: prompt_select_output
|
606
745
|
:procname: val_as_str
|
746
|
+
- :default: Uninterrupted
|
747
|
+
:description: Uninterrupted execution
|
748
|
+
:env_var: MDE_PROMPT_UNINTERRUPTED
|
749
|
+
:opt_name: prompt_uninterrupted
|
750
|
+
:procname: val_as_str
|
607
751
|
- :default: 'Yes'
|
608
752
|
:description: Prompt for yes
|
609
753
|
:env_var: MDE_PROMPT_YES
|
@@ -754,12 +898,12 @@
|
|
754
898
|
:env_var: MDE_SHELL
|
755
899
|
:opt_name: shell
|
756
900
|
:procname: val_as_str
|
757
|
-
- :default: "# -^-
|
901
|
+
- :default: "# -^-"
|
758
902
|
:description: shell_code_label_format_above
|
759
903
|
:env_var: MDE_SHELL_CODE_LABEL_FORMAT_ABOVE
|
760
904
|
:opt_name: shell_code_label_format_above
|
761
905
|
:procname: val_as_str
|
762
|
-
- :default: "# -v- +%{block_name} -v-"
|
906
|
+
- :default: "# -v- +%{block_name} -o- %{document_filename} -v-"
|
763
907
|
:description: shell_code_label_format_below
|
764
908
|
:env_var: MDE_SHELL_CODE_LABEL_FORMAT_BELOW
|
765
909
|
:opt_name: shell_code_label_format_below
|
@@ -769,7 +913,7 @@
|
|
769
913
|
:opt_name: tab_completions
|
770
914
|
:procname: val_as_bool
|
771
915
|
- :arg_name: BOOL
|
772
|
-
:default:
|
916
|
+
:default: false
|
773
917
|
:description: Requires user approval before executing a script
|
774
918
|
:env_var: MDE_USER_MUST_APPROVE
|
775
919
|
:long_name: user-must-approve
|
data/lib/saved_assets.rb
CHANGED
@@ -12,18 +12,20 @@ module MarkdownExec
|
|
12
12
|
# method derives a name for stdout redirection.
|
13
13
|
#
|
14
14
|
class SavedAsset
|
15
|
-
FNR11 =
|
16
|
-
FNR12 = '
|
15
|
+
FNR11 = %r{/|:}.freeze
|
16
|
+
FNR12 = '_'
|
17
|
+
DEFAULT_FTIME = '%F-%H-%M-%S'
|
17
18
|
|
18
19
|
# Generates a formatted script name based on the provided parameters.
|
19
|
-
def self.script_name(filename:, prefix:, time:, blockname:)
|
20
|
-
fne = filename.gsub(
|
21
|
-
"#{[prefix, time.strftime(
|
20
|
+
def self.script_name(filename:, prefix:, time:, blockname:, ftime: DEFAULT_FTIME, join_str: '_', pattern: FNR11, replace: FNR12, exts: '.sh')
|
21
|
+
fne = filename.gsub(pattern, replace)
|
22
|
+
"#{[prefix, time.strftime(ftime), fne, ',', blockname].join(join_str)}#{exts}"
|
22
23
|
end
|
23
24
|
|
24
25
|
# Generates a formatted stdout name based on the provided parameters.
|
25
|
-
def self.stdout_name(filename:, prefix:, time:, blockname:)
|
26
|
-
|
26
|
+
def self.stdout_name(filename:, prefix:, time:, blockname:, ftime: DEFAULT_FTIME, join_str: '_', pattern: FNR11, replace: FNR12, exts: '.out.txt')
|
27
|
+
fne = filename.gsub(pattern, replace)
|
28
|
+
"#{[prefix, time.strftime(ftime), fne, ',', blockname].join(join_str)}#{exts}"
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -50,7 +52,7 @@ if $PROGRAM_NAME == __FILE__
|
|
50
52
|
time = Time.new(2023, 1, 1, 12, 0, 0)
|
51
53
|
blockname = 'block1'
|
52
54
|
|
53
|
-
expected_name = 'test_2023-01-01-12-00-00_sample.
|
55
|
+
expected_name = 'test_2023-01-01-12-00-00_sample.txt_,_block1.out.txt'
|
54
56
|
assert_equal expected_name,
|
55
57
|
MarkdownExec::SavedAsset.stdout_name(filename: filename, prefix: prefix, time: time,
|
56
58
|
blockname: blockname)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markdown_exec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fareed Stevenson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clipboard
|
@@ -81,8 +81,8 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.2.0
|
83
83
|
description: Interactively select and execute fenced code blocks in markdown files.
|
84
|
-
Build complex scripts by
|
85
|
-
|
84
|
+
Build complex scripts by naming and requiring blocks. Log resulting scripts and
|
85
|
+
output. Re-run scripts.
|
86
86
|
email:
|
87
87
|
- fareed@phomento.com
|
88
88
|
executables:
|
@@ -118,11 +118,15 @@ files:
|
|
118
118
|
- examples/import0.md
|
119
119
|
- examples/import1.md
|
120
120
|
- examples/include.md
|
121
|
+
- examples/indent.md
|
121
122
|
- examples/infile_config.md
|
122
123
|
- examples/linked.md
|
123
124
|
- examples/linked1.md
|
124
125
|
- examples/linked2.md
|
125
126
|
- examples/linked3.md
|
127
|
+
- examples/load1.sh
|
128
|
+
- examples/load2.sh
|
129
|
+
- examples/nickname.md
|
126
130
|
- examples/opts.md
|
127
131
|
- examples/pass-through.md
|
128
132
|
- examples/plant.md
|
@@ -135,6 +139,7 @@ files:
|
|
135
139
|
- lib/block_label.rb
|
136
140
|
- lib/block_types.rb
|
137
141
|
- lib/cached_nested_file_reader.rb
|
142
|
+
- lib/ce_get_cost_and_usage.rb
|
138
143
|
- lib/cli.rb
|
139
144
|
- lib/colorize.rb
|
140
145
|
- lib/constants.rb
|
@@ -143,6 +148,7 @@ files:
|
|
143
148
|
- lib/exceptions.rb
|
144
149
|
- lib/fcb.rb
|
145
150
|
- lib/filter.rb
|
151
|
+
- lib/find_files.rb
|
146
152
|
- lib/fout.rb
|
147
153
|
- lib/hash.rb
|
148
154
|
- lib/hash_delegator.rb
|
@@ -152,17 +158,13 @@ files:
|
|
152
158
|
- lib/mdoc.rb
|
153
159
|
- lib/menu.src.yml
|
154
160
|
- lib/menu.yml
|
155
|
-
- lib/method_sorter.rb
|
156
161
|
- lib/object_present.rb
|
157
162
|
- lib/option_value.rb
|
158
|
-
- lib/pty1.rb
|
159
163
|
- lib/regexp.rb
|
160
|
-
- lib/regexp_replacer.rb
|
161
164
|
- lib/rspec_helpers.rb
|
162
165
|
- lib/saved_assets.rb
|
163
166
|
- lib/saved_files_matcher.rb
|
164
167
|
- lib/shared.rb
|
165
|
-
- lib/sort_yaml_gpt4.rb
|
166
168
|
- lib/string_util.rb
|
167
169
|
- lib/tap.rb
|
168
170
|
homepage: https://rubygems.org/gems/markdown_exec
|
data/lib/method_sorter.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'ripper'
|
4
|
-
require 'parser/current'
|
5
|
-
|
6
|
-
class MethodSorter
|
7
|
-
def initialize(file_path)
|
8
|
-
@file_path = file_path
|
9
|
-
end
|
10
|
-
|
11
|
-
def sort
|
12
|
-
file_contents = File.read(@file_path)
|
13
|
-
|
14
|
-
ast = Parser::CurrentRuby.parse(file_contents)
|
15
|
-
|
16
|
-
# Find the class node
|
17
|
-
class_node = ast.children.find { |node| node.type == :class }
|
18
|
-
|
19
|
-
method_nodes = []
|
20
|
-
|
21
|
-
# Look for method def nodes within each child node
|
22
|
-
class_node.children.compact.each do |child|
|
23
|
-
if child.type == :begin
|
24
|
-
method_nodes += child.children.select { |n| n.type == :def }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# Sort and process method nodes
|
29
|
-
# class_node = ast.children.find { |node| node.type == :class }
|
30
|
-
# unless class_node
|
31
|
-
# puts "No class node found in #{@file_path}"
|
32
|
-
# return
|
33
|
-
# end
|
34
|
-
|
35
|
-
# method_nodes = class_node.children.compact.select { |node|
|
36
|
-
# node.type == :def
|
37
|
-
# }
|
38
|
-
|
39
|
-
sorted_methods = method_nodes.sort_by { |n| n.children[0].to_s }
|
40
|
-
ripper = Ripper.sexp(file_contents)
|
41
|
-
lines = ripper.each_with_index.map { |sexp, index| [sexp, index] }
|
42
|
-
|
43
|
-
method_ranges = get_method_ranges(lines, method_nodes)
|
44
|
-
|
45
|
-
result = replace_method_ranges(lines, method_ranges, sorted_methods)
|
46
|
-
|
47
|
-
puts result.compact.select { |v| v.is_a? String }.join("\n")
|
48
|
-
# File.write(@file_path, result.join)
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def get_method_ranges(lines, method_nodes)
|
54
|
-
method_nodes.map do |method_node|
|
55
|
-
start_line = method_node.loc.line - 1
|
56
|
-
end_line = start_line
|
57
|
-
|
58
|
-
while end_line < lines.size && lines[end_line][0] !~ /^end/
|
59
|
-
end_line += 1
|
60
|
-
end
|
61
|
-
|
62
|
-
(start_line..end_line)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def replace_method_ranges(lines, ranges, sorted_methods)
|
67
|
-
result = lines.dup
|
68
|
-
|
69
|
-
ranges.each_with_index do |range, index|
|
70
|
-
result[range] = sorted_methods[index].loc.expression.source.split("\n")
|
71
|
-
end
|
72
|
-
|
73
|
-
result
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
sorter = MethodSorter.new(ARGV[0])
|
78
|
-
sorter.sort
|
data/lib/pty1.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'pty'
|
4
|
-
|
5
|
-
def launch_and_interact_with_terminal
|
6
|
-
PTY.spawn('bash') do |stdout, stdin, _pid|
|
7
|
-
# Send a command to the terminal
|
8
|
-
stdin.puts "echo 'Hello from Ruby!'"
|
9
|
-
|
10
|
-
# Read the output of the command
|
11
|
-
stdout.each do |line|
|
12
|
-
puts line
|
13
|
-
break if line.include?('Hello from Ruby!')
|
14
|
-
end
|
15
|
-
|
16
|
-
# You can continue to interact with the terminal here
|
17
|
-
# ...
|
18
|
-
|
19
|
-
# Ensure to exit the spawned shell
|
20
|
-
stdin.puts 'exit'
|
21
|
-
end
|
22
|
-
rescue PTY::ChildExited
|
23
|
-
puts 'The child process exited!'
|
24
|
-
end
|
25
|
-
|
26
|
-
launch_and_interact_with_terminal
|
data/lib/regexp_replacer.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
# encoding=utf-8
|
5
|
-
|
6
|
-
require 'find'
|
7
|
-
|
8
|
-
class RegexpReplacer
|
9
|
-
# Constructor to initialize with file path
|
10
|
-
def initialize(file_path)
|
11
|
-
@file_path = file_path
|
12
|
-
end
|
13
|
-
|
14
|
-
# Perform the replacement based on the specified option
|
15
|
-
def perform_replacement(option)
|
16
|
-
content = File.read(@file_path)
|
17
|
-
modified_content = case option
|
18
|
-
when 1
|
19
|
-
replace_pattern1(content)
|
20
|
-
when 2
|
21
|
-
replace_pattern2(content)
|
22
|
-
else
|
23
|
-
raise "Invalid option. Please choose 1 or 2."
|
24
|
-
end
|
25
|
-
File.write(@file_path, modified_content)
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
# Replacement for pattern 1
|
31
|
-
def replace_pattern1(content)
|
32
|
-
regexp = /^( *)# (@\w+) ('.+)/
|
33
|
-
substitution = '\1;;pp __LINE__,\3 #\2'
|
34
|
-
content.gsub(regexp, substitution)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Replacement for pattern 2
|
38
|
-
def replace_pattern2(content)
|
39
|
-
regexp = /^( *);;pp __LINE__,(.+) #(@\w+)/
|
40
|
-
substitution = '\1# \3 \2'
|
41
|
-
content.gsub(regexp, substitution)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Running the script with command line arguments
|
46
|
-
if ARGV.length != 2
|
47
|
-
puts "Usage: ruby regexp_replacer.rb [file_path] [option (1 or 2)]"
|
48
|
-
exit
|
49
|
-
end
|
50
|
-
|
51
|
-
file_path, option = ARGV
|
52
|
-
replacer = RegexpReplacer.new(file_path)
|
53
|
-
begin
|
54
|
-
replacer.perform_replacement(option.to_i)
|
55
|
-
puts "Replacement performed successfully."
|
56
|
-
rescue StandardError => e
|
57
|
-
puts "Error: #{e.message}"
|
58
|
-
end
|
data/lib/sort_yaml_gpt4.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'yaml'
|
4
|
-
|
5
|
-
def sort_yaml(input_yaml)
|
6
|
-
# Parse the input YAML
|
7
|
-
data = YAML.load(input_yaml)
|
8
|
-
|
9
|
-
# Ensure data is an array of hashes
|
10
|
-
unless data.is_a?(Array) && data.all? { |item| item.is_a?(Hash) }
|
11
|
-
raise ArgumentError, 'Input YAML must be an array of hashes.'
|
12
|
-
end
|
13
|
-
|
14
|
-
# Sort items by 'opt_name' values
|
15
|
-
sorted_data = data.sort_by do |item|
|
16
|
-
(item[:opt_name] || item[:long_name] || item[:short_name]).to_s
|
17
|
-
end
|
18
|
-
|
19
|
-
# Sort keys in each item
|
20
|
-
sorted_data.each do |item|
|
21
|
-
item.replace(item.sort.to_h)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Convert the sorted data back to YAML and write to stdout
|
25
|
-
puts YAML.dump(sorted_data).gsub("\n-", "\n\n-")
|
26
|
-
end
|
27
|
-
|
28
|
-
# Read YAML from stdin
|
29
|
-
input_yaml = $stdin.read
|
30
|
-
|
31
|
-
# Call the function with input YAML
|
32
|
-
sort_yaml(input_yaml)
|