markdown_exec 1.8.7 → 1.8.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +33 -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/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 +6 -8
- data/lib/find_files.rb +99 -0
- data/lib/hash_delegator.rb +1001 -768
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/mdoc.rb +27 -28
- data/lib/menu.src.yml +129 -17
- data/lib/menu.yml +94 -7
- metadata +8 -6
- 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/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 'v'
|
19
|
-
verbose(content)
|
20
|
-
when 'q'
|
21
|
-
quiet(content)
|
22
|
-
else
|
23
|
-
raise "Invalid option. Please choose 'v' or 'q'."
|
24
|
-
end
|
25
|
-
File.write(@file_path, modified_content)
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
# Replacement for pattern 'v'
|
31
|
-
def verbose(content)
|
32
|
-
regexp = /^( *)# (&\w+) ('.+)/
|
33
|
-
substitution = '\1;;pp [__LINE__,\3] #\2'
|
34
|
-
content.gsub(regexp, substitution)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Replacement for pattern 'q'
|
38
|
-
def quiet(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 ('v' or 'q')]"
|
48
|
-
exit
|
49
|
-
end
|
50
|
-
|
51
|
-
file_path, option = ARGV
|
52
|
-
replacer = RegexpReplacer.new(file_path)
|
53
|
-
begin
|
54
|
-
replacer.perform_replacement(option)
|
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)
|