utils 0.68.0 → 0.69.0
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/README.md +251 -18
- data/bin/ascii7 +28 -0
- data/bin/blameline +17 -0
- data/bin/changes +69 -5
- data/bin/classify +128 -7
- data/bin/code_comment +102 -104
- data/bin/commit_message +26 -2
- data/bin/create_cstags +18 -0
- data/bin/create_tags +10 -0
- data/bin/discover +38 -1
- data/bin/edit +14 -1
- data/bin/edit_wait +14 -0
- data/bin/enum +139 -15
- data/bin/git-empty +50 -0
- data/bin/git-versions +20 -0
- data/bin/json_check +15 -1
- data/bin/long_lines +11 -2
- data/bin/myex +38 -0
- data/bin/on_change +22 -0
- data/bin/path +21 -0
- data/bin/print_method +29 -1
- data/bin/probe +52 -4
- data/bin/rainbow +52 -0
- data/bin/rd2md +15 -0
- data/bin/search +83 -1
- data/bin/sedit +6 -0
- data/bin/serve +18 -3
- data/bin/ssh-tunnel +14 -2
- data/bin/strip_spaces +17 -9
- data/bin/sync_dir +48 -1
- data/bin/untest +19 -1
- data/bin/utils-utilsrc +42 -6
- data/bin/vcf2alias +33 -0
- data/bin/yaml_check +24 -2
- data/lib/utils/config_dir.rb +127 -0
- data/lib/utils/config_file.rb +445 -1
- data/lib/utils/editor.rb +215 -3
- data/lib/utils/finder.rb +127 -16
- data/lib/utils/grepper.rb +90 -1
- data/lib/utils/irb.rb +387 -39
- data/lib/utils/line_blamer.rb +28 -0
- data/lib/utils/line_formatter.rb +198 -0
- data/lib/utils/md5.rb +14 -0
- data/lib/utils/patterns.rb +77 -3
- data/lib/utils/probe_server.rb +302 -23
- data/lib/utils/ssh_tunnel_specification.rb +58 -0
- data/lib/utils/version.rb +1 -1
- data/lib/utils/xt/source_location_extension.rb +18 -6
- data/lib/utils.rb +3 -1
- data/tests/utils_test.rb +7 -1
- data/utils.gemspec +5 -5
- metadata +4 -6
- data/bin/number_files +0 -26
- data/lib/utils/xdg_config.rb +0 -10
- /data/{COPYING → LICENSE} +0 -0
data/bin/enum
CHANGED
@@ -1,25 +1,57 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Range enumerator - Generate combinations from multiple ranges and execute
|
4
|
+
# commands
|
5
|
+
#
|
6
|
+
# Generates cartesian product of ranges and processes each combination.
|
2
7
|
|
3
8
|
require 'tins'
|
4
9
|
include Tins
|
5
10
|
include Tins::GO
|
6
11
|
|
7
12
|
class CompoundRange
|
13
|
+
# Initializes a new instance with an empty ranges array.
|
8
14
|
def initialize
|
9
15
|
@ranges = []
|
10
16
|
end
|
11
17
|
|
18
|
+
# The concat method adds a range to the internal ranges collection and
|
19
|
+
# returns the instance for chaining.
|
20
|
+
#
|
21
|
+
# @param range [ Object ] the range to be added to the collection
|
22
|
+
#
|
23
|
+
# @return [ self ] the instance itself, enabling method chaining
|
12
24
|
def concat(range)
|
13
25
|
@ranges << range
|
14
26
|
self
|
15
27
|
end
|
16
28
|
|
29
|
+
# The each method iterates over each range in the instance's ranges
|
30
|
+
# collection and yields each element to the provided block.
|
31
|
+
#
|
32
|
+
# This method delegates the iteration to each range object in the @ranges
|
33
|
+
# collection, allowing the block to be executed for every element contained
|
34
|
+
# within these ranges.
|
35
|
+
#
|
36
|
+
# @yield [ element ]
|
37
|
+
#
|
38
|
+
# @return [ nil ] returns nil after completing the iteration over all ranges
|
17
39
|
def each(&block)
|
18
40
|
@ranges.each { |r| r.each(&block) }
|
19
41
|
end
|
20
42
|
end
|
21
43
|
|
22
44
|
class Step
|
45
|
+
# Initializes a new Range instance with the specified parameters.
|
46
|
+
#
|
47
|
+
# This method sets up the internal state of a Range object by storing the
|
48
|
+
# start value, end value, step size, and exclusive flag. It also adjusts the
|
49
|
+
# end value when the range is exclusive to ensure proper iteration behavior.
|
50
|
+
#
|
51
|
+
# @param a [ Object ] the starting value of the range
|
52
|
+
# @param b [ Object ] the ending value of the range
|
53
|
+
# @param step [ Object ] the step size for incrementing through the range
|
54
|
+
# @param exclusive [ TrueClass, FalseClass ] whether the range excludes the end value
|
23
55
|
def initialize(a, b, step = 1, exclusive = false)
|
24
56
|
@a = a
|
25
57
|
@b = b
|
@@ -33,12 +65,33 @@ class Step
|
|
33
65
|
end
|
34
66
|
end
|
35
67
|
|
68
|
+
# The each method iterates over a range of values using a step increment.
|
69
|
+
#
|
70
|
+
# This method executes a block for each value in the range from @a to @b,
|
71
|
+
# incrementing by @step each time. It provides a way to perform operations
|
72
|
+
# on a sequence of numbers with a specified increment.
|
73
|
+
#
|
74
|
+
# @param block [ Proc ] the block to be executed for each value in the range
|
75
|
+
#
|
76
|
+
# @return [ Integer ] the final value of the iteration
|
36
77
|
def each(&block)
|
37
78
|
@a.step(@b, @step, &block)
|
38
79
|
end
|
39
80
|
end
|
40
81
|
|
41
82
|
class StringRange
|
83
|
+
# Initializes a new Range instance with the specified bounds and exclusivity.
|
84
|
+
#
|
85
|
+
# This method creates a range object by determining the appropriate bounds
|
86
|
+
# based on the relationship between the first and second parameters. It
|
87
|
+
# handles both inclusive and exclusive range creation, supporting reverse
|
88
|
+
# ordering of bounds.
|
89
|
+
#
|
90
|
+
# @param a [ Integer ] the first boundary value of the range
|
91
|
+
# @param b [ Integer ] the second boundary value of the range
|
92
|
+
# @param exclusive [ TrueClass, FalseClass ] whether the range should be exclusive
|
93
|
+
#
|
94
|
+
# @return [ Range ] a new Range instance with the specified parameters
|
42
95
|
def initialize(a, b, exclusive = false)
|
43
96
|
@range = if a > b
|
44
97
|
if exclusive
|
@@ -51,12 +104,33 @@ class StringRange
|
|
51
104
|
end
|
52
105
|
end
|
53
106
|
|
107
|
+
# The each method iterates over the range and yields each element to the
|
108
|
+
# provided block.
|
109
|
+
#
|
110
|
+
# @yield [ element ]
|
111
|
+
#
|
112
|
+
# @return [ nil ] returns nil after completing the iteration
|
113
|
+
def each(&block)
|
114
|
+
@range.each(&block)
|
115
|
+
end
|
54
116
|
def each(&block)
|
55
117
|
@range.each(&block)
|
56
118
|
end
|
57
119
|
end
|
58
120
|
|
59
121
|
class IntegerRange < Step
|
122
|
+
# Initializes a new instance with the specified parameters and sets up
|
123
|
+
# internal state.
|
124
|
+
#
|
125
|
+
# This method configures the object's internal attributes based on the
|
126
|
+
# provided arguments and initializes the parent class with computed values.
|
127
|
+
# It handles parameter validation and setup for exclusive access scenarios.
|
128
|
+
#
|
129
|
+
# @param a [ Object ] the first parameter used in initialization
|
130
|
+
# @param b [ Object ] the second parameter used in initialization
|
131
|
+
# @param exclusive [ TrueClass, FalseClass ] flag indicating whether exclusive access should be enabled
|
132
|
+
#
|
133
|
+
# @return [ void ] returns nil after initialization is complete
|
60
134
|
def initialize(a, b, exclusive = false)
|
61
135
|
@a = a
|
62
136
|
@b = b
|
@@ -64,6 +138,16 @@ class IntegerRange < Step
|
|
64
138
|
end
|
65
139
|
end
|
66
140
|
|
141
|
+
# The parse_range method converts a range string into a range object.
|
142
|
+
#
|
143
|
+
# This method handles various range formats including single numbers,
|
144
|
+
# number ranges, string ranges, and stepped ranges.
|
145
|
+
# It parses the input string and returns the appropriate range object
|
146
|
+
# based on the format encountered.
|
147
|
+
#
|
148
|
+
# @param range [ String ] the range string to be parsed
|
149
|
+
#
|
150
|
+
# @return [ Object ] a range object corresponding to the parsed string
|
67
151
|
def parse_range(range)
|
68
152
|
case range
|
69
153
|
when /,/
|
@@ -91,21 +175,44 @@ def parse_range(range)
|
|
91
175
|
end
|
92
176
|
end
|
93
177
|
|
178
|
+
# The parse_ranges method processes a pattern string by splitting it on colons
|
179
|
+
# and parsing each resulting range component.
|
180
|
+
#
|
181
|
+
# This method takes a pattern string, splits it into individual range
|
182
|
+
# components using colons as delimiters, and then parses each component into a
|
183
|
+
# structured format using the parse_range helper method.
|
184
|
+
#
|
185
|
+
# @param pattern [ String ] the pattern string containing ranges separated by colons
|
186
|
+
#
|
187
|
+
# @return [ Array<Object> ] an array of parsed range objects resulting from
|
188
|
+
# splitting and parsing the input pattern
|
94
189
|
def parse_ranges(pattern)
|
95
190
|
pattern.split(/:/).map { |range| parse_range(range) }
|
96
191
|
end
|
97
192
|
|
193
|
+
# The execute_command method formats a command string with provided arguments
|
194
|
+
# and executes it.
|
195
|
+
#
|
196
|
+
# This method takes a command template, a format string, and a tuple of values
|
197
|
+
# to be inserted into the command. It processes the format string with the
|
198
|
+
# tuple values, splits the result by colons, and then executes the system
|
199
|
+
# command with the formatted arguments.
|
200
|
+
#
|
201
|
+
# @param command [ String ] the command template string with format placeholders
|
202
|
+
# @param format [ String ] the format string used to process the tuple values
|
203
|
+
# @param tuple [ Array ] the array of values to be inserted into the formatted command
|
204
|
+
#
|
205
|
+
# @return [ Boolean ] returns the result of the system command execution
|
98
206
|
def execute_command(command, format, tuple)
|
99
207
|
formatted = (format % tuple).split(/:/)
|
100
|
-
|
101
|
-
$limited.execute do
|
102
|
-
system sprintf(command, *formatted)
|
103
|
-
end
|
104
|
-
else
|
105
|
-
system sprintf(command, *formatted)
|
106
|
-
end
|
208
|
+
system sprintf(command, *formatted)
|
107
209
|
end
|
108
210
|
|
211
|
+
# The usage method displays the help message and exits the program.
|
212
|
+
#
|
213
|
+
# This method prints a detailed usage message to the standard output,
|
214
|
+
# explaining how to use the command-line tool, including information
|
215
|
+
# about valid range specifications and available options.
|
109
216
|
def usage
|
110
217
|
puts <<EOT
|
111
218
|
Usage: #{File.basename($0)} [OPTIONS] RANGES
|
@@ -146,22 +253,39 @@ EOT
|
|
146
253
|
exit 1
|
147
254
|
end
|
148
255
|
|
256
|
+
argv, rest = ARGV.partition { _1 =~ /\A-\d/ }
|
149
257
|
$opts = {
|
150
|
-
}.update(go('p:e:f:h')) do |o,default,set|
|
258
|
+
}.update(go('p:e:f:h', rest)) do |o,default,set|
|
151
259
|
set || default
|
152
260
|
end
|
153
|
-
|
154
|
-
$ranges
|
261
|
+
ranges = argv + rest
|
262
|
+
usage if $opts[?h] || ranges.size != 1
|
263
|
+
$ranges = ranges.shift
|
155
264
|
$limited = $opts[?p] ? Limited.new($opts[?p]) : nil
|
156
265
|
ranges = parse_ranges($ranges)
|
157
266
|
generator = Generator.new(ranges)
|
158
267
|
$opts[?f] ||= %w[ %s ] * generator.size * ':'
|
159
268
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
269
|
+
if $limited
|
270
|
+
$limited.process do |l|
|
271
|
+
generator.each do |tuple|
|
272
|
+
l.execute do
|
273
|
+
if $opts[?e]
|
274
|
+
execute_command($opts[?e], $opts[?f], tuple)
|
275
|
+
else
|
276
|
+
puts $opts[?f] % tuple
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
$limited.stop
|
281
|
+
end
|
282
|
+
else
|
283
|
+
generator.each do |tuple|
|
284
|
+
if $opts[?e]
|
285
|
+
execute_command($opts[?e], $opts[?f], tuple)
|
286
|
+
else
|
287
|
+
puts $opts[?f] % tuple
|
288
|
+
end
|
165
289
|
end
|
166
290
|
end
|
167
291
|
exit 0
|
data/bin/git-empty
CHANGED
@@ -1,10 +1,60 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# git-empty - Reset git repository to empty state on specified branch
|
4
|
+
#
|
5
|
+
# WARNING: This command permanently deletes ALL commit history and untracked
|
6
|
+
# files from the current repository. Use with extreme caution.
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
# git-empty <branch_name>
|
10
|
+
#
|
11
|
+
# Examples:
|
12
|
+
# git-empty feature/new # Reset to empty feature branch
|
13
|
+
#
|
14
|
+
# This command:
|
15
|
+
# 1. Sets HEAD to point to a new branch reference
|
16
|
+
# 2. Removes the Git index (staging area)
|
17
|
+
# 3. Cleans all untracked files and directories
|
18
|
+
#
|
19
|
+
# The repository will be left in a completely fresh state with no history.
|
2
20
|
|
3
21
|
require 'fileutils'
|
4
22
|
include FileUtils
|
5
23
|
|
6
24
|
name = ARGV.shift or fail 'require a branch name'
|
7
25
|
|
26
|
+
puts <<~EOT
|
27
|
+
WARNING: This will reset the current repository to empty state on branch '#{name}'
|
28
|
+
This will DELETE ALL commit history and untracked files!
|
29
|
+
Are you absolutely sure? (y/N):
|
30
|
+
EOT
|
31
|
+
|
32
|
+
unless gets =~ /\Ay/i
|
33
|
+
puts "Operation cancelled."
|
34
|
+
exit 0
|
35
|
+
end
|
36
|
+
|
37
|
+
system "git symbolic-ref HEAD refs/heads/#{name}"
|
38
|
+
rm '.git/index'
|
39
|
+
system 'git clean -fdx'
|
40
|
+
```
|
41
|
+
|
42
|
+
require 'fileutils'
|
43
|
+
include FileUtils
|
44
|
+
|
45
|
+
name = ARGV.shift or fail 'require a branch name'
|
46
|
+
|
47
|
+
puts <<~EOT
|
48
|
+
WARNING: This will reset the current repository to empty state on branch '#{name}'
|
49
|
+
This will DELETE ALL commit history and untracked files!
|
50
|
+
Are you absolutely sure? (y/N):
|
51
|
+
EOT
|
52
|
+
|
53
|
+
unless gets =~ /\Ay/i
|
54
|
+
puts "Operation cancelled."
|
55
|
+
exit 0
|
56
|
+
end
|
57
|
+
|
8
58
|
system "git symbolic-ref HEAD refs/heads/#{name}"
|
9
59
|
rm '.git/index'
|
10
60
|
system 'git clean -fdx'
|
data/bin/git-versions
CHANGED
@@ -1,4 +1,24 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Git versions - Generate changelog from Git tags
|
4
|
+
#
|
5
|
+
# Usage: git-versions [OPTIONS]
|
6
|
+
#
|
7
|
+
# Displays git log history between version tags in semantic order.
|
8
|
+
# Version tags are matched using regex pattern /^v((?:\d+\.)*\d+)/
|
9
|
+
# by default, or custom pattern via GIT_VERSIONS_REGEXP environment variable.
|
10
|
+
#
|
11
|
+
# Options:
|
12
|
+
# Any git log arguments supported (e.g., --oneline, --stat, --since)
|
13
|
+
#
|
14
|
+
# Examples:
|
15
|
+
# git versions # Show colorized changelog with stats
|
16
|
+
# git versions --oneline # Show compact format
|
17
|
+
# git versions --since="2023-01-01" # Filter by date
|
18
|
+
# GIT_VERSIONS_REGEXP='^release-(\d+\.\d+\.\d+)$' git versions
|
19
|
+
#
|
20
|
+
# Shows version headers in red/bold with git log output between each version
|
21
|
+
# pair.
|
2
22
|
|
3
23
|
require 'tins'
|
4
24
|
require 'term/ansicolor'
|
data/bin/json_check
CHANGED
@@ -1,10 +1,24 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# JSON validator - Check if input is valid JSON
|
4
|
+
#
|
5
|
+
# Usage: json_check [FILE]
|
6
|
+
#
|
7
|
+
# Validates JSON from stdin or specified file. Exits with:
|
8
|
+
# 0 - Valid JSON
|
9
|
+
# 1 - Invalid JSON (with error details on stderr)
|
10
|
+
#
|
11
|
+
# Examples:
|
12
|
+
# echo '{"key": "value"}' | json_check # Validate stdin
|
13
|
+
# json_check data.json # Validate file
|
14
|
+
# json_check < data.json # Validate with input redirection
|
2
15
|
|
3
16
|
require 'json'
|
4
17
|
|
5
18
|
begin
|
6
19
|
JSON.parse(ARGF.read)
|
7
20
|
exit 0
|
8
|
-
rescue JSON::ParserError
|
21
|
+
rescue JSON::ParserError => e
|
22
|
+
STDERR.puts "#{e.class}: #{e}"
|
9
23
|
exit 1
|
10
24
|
end
|
data/bin/long_lines
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Find lines exceeding maximum length threshold with author attribution
|
4
|
+
# Usage: #{File.basename($0)} [OPTIONS] [FILES]
|
5
|
+
# Options:
|
6
|
+
# -m NUM Maximum line length (default: 80)
|
7
|
+
# -h Show this help message
|
8
|
+
#
|
9
|
+
# Outputs tab-separated data: AUTHOR\tLINE_LENGTH\tFILE:LINE_NUMBER
|
10
|
+
# for each line longer than the specified threshold.
|
2
11
|
|
3
12
|
require 'tins/go'
|
4
13
|
include Tins::GO
|
@@ -17,9 +26,9 @@ max = ($opts[?m] || 80).to_i
|
|
17
26
|
|
18
27
|
files = ARGV
|
19
28
|
|
20
|
-
|
29
|
+
files.each do |file|
|
21
30
|
File.open(file) do |f|
|
22
|
-
|
31
|
+
f.each do |line|
|
23
32
|
size = line.size
|
24
33
|
if size > max
|
25
34
|
lineno = f.lineno
|
data/bin/myex
CHANGED
@@ -1,12 +1,41 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# vim: set ft=ruby et sw=2 ts=2:
|
3
3
|
# encoding: ascii-8bit
|
4
|
+
#
|
5
|
+
# MySQL Backup Parser/Processor
|
6
|
+
#
|
7
|
+
# Parses and processes MySQL dump files with various operations including
|
8
|
+
# listing tables, creating table statements, truncating tables, inserting data,
|
9
|
+
# replacing records, and searching patterns.
|
10
|
+
#
|
11
|
+
# Usage:
|
12
|
+
# myex list|create|truncate|insert|replace|search [OPTION] [TABLES]
|
13
|
+
#
|
14
|
+
# Commands:
|
15
|
+
# list Display all tables in the backup
|
16
|
+
# create Display CREATE TABLE statements (use -d to drop tables first)
|
17
|
+
# truncate Truncate tables (use -t to truncate before insert)
|
18
|
+
# insert Extract INSERT statements (use -i to add IGNORE, -t to truncate)
|
19
|
+
# replace Convert INSERT to REPLACE statements
|
20
|
+
# search Search pattern in INSERT statements with context (-p PATTERN -C NUMBER)
|
21
|
+
#
|
22
|
+
# Options:
|
23
|
+
# -d Drop table before creation
|
24
|
+
# -t Truncate table before insert
|
25
|
+
# -i Add IGNORE to INSERT statements
|
26
|
+
# -p PATTERN Pattern for search command
|
27
|
+
# -C NUMBER Context size for search command
|
28
|
+
#
|
29
|
+
#
|
30
|
+
# The script processes stdin as MySQL dump content and outputs processed statements.
|
4
31
|
|
5
32
|
require 'tins/go'
|
6
33
|
include Tins::GO
|
7
34
|
require 'term/ansicolor'
|
8
35
|
include Term::ANSIColor
|
9
36
|
|
37
|
+
# The usage method displays the command-line interface help text and exits the
|
38
|
+
# program.
|
10
39
|
def usage
|
11
40
|
puts <<EOT
|
12
41
|
Usage: #{File.basename($0)} list|create|truncate|insert|replace|search [OPTION] [TABLES]
|
@@ -40,6 +69,15 @@ EOT
|
|
40
69
|
exit 1
|
41
70
|
end
|
42
71
|
|
72
|
+
# The bell method outputs a bell character followed by a backspace character
|
73
|
+
# multiple times. It pauses between each output based on the specified sleep
|
74
|
+
# duration.
|
75
|
+
#
|
76
|
+
# @param n [ Integer ] the number of times to output the bell and backspace
|
77
|
+
# characters @param s [ Float ] the sleep duration in seconds between each
|
78
|
+
# output
|
79
|
+
#
|
80
|
+
# @return [ Integer ] returns the number of iterations performed
|
43
81
|
def bell(n = 1, s = 1)
|
44
82
|
n.times do
|
45
83
|
STDERR.print "\a\b"
|
data/bin/on_change
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Monitor file for changes and execute command when modified
|
4
|
+
#
|
5
|
+
# Usage:
|
6
|
+
# on_change filename [command...] # Watch file and run command on changes
|
7
|
+
#
|
8
|
+
# This script monitors a file for modifications and executes a specified
|
9
|
+
# command whenever the file is changed. It can be used for auto-reloading,
|
10
|
+
# rebuilding, or triggering actions when source files are updated.
|
11
|
+
#
|
12
|
+
# If no command is provided, 'true' is executed by default.
|
13
|
+
#
|
14
|
+
# Special replacement:
|
15
|
+
# %f in command will be replaced with the filename being monitored
|
16
|
+
#
|
17
|
+
# Examples:
|
18
|
+
# on_change Gemfile bundle install
|
19
|
+
# on_change tests/utils_test.rb ruby -I lib:tests %f
|
2
20
|
|
21
|
+
# The execute method runs a command by processing its arguments and displaying
|
22
|
+
# the output.
|
23
|
+
#
|
24
|
+
# @param args [ Array ] the command arguments to be executed
|
3
25
|
def execute(*args)
|
4
26
|
cmd = args.map(&:inspect) * ' '
|
5
27
|
puts "Executing: #{cmd}"
|
data/bin/path
CHANGED
@@ -1,4 +1,25 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# PATH manager - Manipulate environment PATH variable
|
4
|
+
#
|
5
|
+
# Usage: path COMMAND [OPTIONS] [ARGUMENTS]
|
6
|
+
#
|
7
|
+
# Commands:
|
8
|
+
# prefix PATH_PART Add path part to beginning of PATH
|
9
|
+
# postfix PATH_PART Add path part to end of PATH
|
10
|
+
# list Display current PATH
|
11
|
+
# edit Edit PATH in external editor
|
12
|
+
#
|
13
|
+
# Options:
|
14
|
+
# -e Output as 'export PATH=...' for shell integration
|
15
|
+
#
|
16
|
+
# Examples:
|
17
|
+
# path prefix /usr/local/bin # Add to beginning
|
18
|
+
# path postfix ~/bin # Add to end
|
19
|
+
# path list # Show current PATH
|
20
|
+
# path edit # Edit PATH in editor
|
21
|
+
#
|
22
|
+
# Note: PATH entries are automatically expanded and deduplicated.
|
2
23
|
|
3
24
|
require 'tins/go'
|
4
25
|
include Tins::GO
|
data/bin/print_method
CHANGED
@@ -1,4 +1,32 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Method Printer Tool
|
4
|
+
#
|
5
|
+
# Extracts and prints complete method definitions from Ruby source files based
|
6
|
+
# on line number references. Takes filename:line_number input and outputs the
|
7
|
+
# full method body including surrounding whitespace and indentation.
|
8
|
+
#
|
9
|
+
# Usage:
|
10
|
+
# print_method [FILENAME:LINE_NUMBER]...
|
11
|
+
#
|
12
|
+
# Examples:
|
13
|
+
# print_method file.rb:42
|
14
|
+
# echo "file.rb:42" | print_method
|
15
|
+
#
|
16
|
+
# Features:
|
17
|
+
# - Parses Ruby method definitions by line number
|
18
|
+
# - Preserves original indentation and formatting
|
19
|
+
# - Handles nested methods and complex indentation
|
20
|
+
# - Works with both command-line arguments and stdin input
|
21
|
+
# - Uses Tins::LinesFile for efficient line-based file access
|
22
|
+
#
|
23
|
+
# The tool identifies method boundaries by looking for:
|
24
|
+
# - Opening 'def' statement with proper indentation
|
25
|
+
# - Closing 'end' statement at the same indentation level
|
26
|
+
# - Preserves all original formatting including whitespace
|
27
|
+
#
|
28
|
+
# This is particularly useful for extracting method definitions from large
|
29
|
+
# codebases or when debugging specific method implementations.
|
2
30
|
|
3
31
|
require 'utils'
|
4
32
|
|
@@ -7,7 +35,7 @@ inputs = ARGV.empty? ? STDIN : ARGV
|
|
7
35
|
inputs.each do |filename_linenumber|
|
8
36
|
source_location = filename_linenumber.source_location
|
9
37
|
lf = Tins::LinesFile.for_filename(source_location.filename, source_location.linenumber)
|
10
|
-
if spaces = lf.match_backward(/^(\s
|
38
|
+
if spaces = lf.match_backward(/^(\s*?)(\S.*?\s+)?def\s+/)&.first
|
11
39
|
line_number_begin = lf.line_number
|
12
40
|
lf.match_forward(/^#{spaces}end/)
|
13
41
|
line_number_end = lf.line_number
|
data/bin/probe
CHANGED
@@ -1,12 +1,29 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Probe test runner and server management tool
|
4
|
+
#
|
5
|
+
# This utility provides comprehensive testing capabilities with support for
|
6
|
+
# multiple test frameworks (RSpec, Test::Unit, Cucumber) and triggering test
|
7
|
+
# runs via probe -c client.
|
8
|
+
#
|
9
|
+
# Features:
|
10
|
+
# - Run specific tests by name or file
|
11
|
+
# - Start/connect to probe servers for testing/env setting.
|
12
|
+
# - Environment variable management on probe servers
|
13
|
+
# - Automatic framework detection and configuration
|
2
14
|
|
3
|
-
require 'tins/xt'
|
4
|
-
require 'tins/lines_file'
|
5
|
-
include Tins::GO
|
6
15
|
require 'utils'
|
7
16
|
include Utils
|
17
|
+
include Tins::GO
|
8
18
|
require 'shellwords'
|
9
19
|
|
20
|
+
# The usage method displays the command-line interface help text and version
|
21
|
+
# information.
|
22
|
+
#
|
23
|
+
# This method outputs a formatted help message that describes the available
|
24
|
+
# options for the command-line tool, including test execution parameters, probe
|
25
|
+
# server controls, and environment variable management. It also shows the
|
26
|
+
# current version of the tool.
|
10
27
|
def usage
|
11
28
|
puts <<~EOT
|
12
29
|
Usage: #{File.basename($0)} [OPTS] [FILENAME[:LINENO]]
|
@@ -25,21 +42,52 @@ def usage
|
|
25
42
|
exit 1
|
26
43
|
end
|
27
44
|
|
45
|
+
# The cmd method executes a system command with bundle exec prefix.
|
46
|
+
#
|
47
|
+
# This method prepares and runs a system command by prepending 'bundle' and
|
48
|
+
# 'exec' to the provided arguments. It prints the joined command to stdout
|
49
|
+
# before execution and exits the current process with the command's exit status
|
50
|
+
# if it fails.
|
51
|
+
#
|
52
|
+
# @param args [ Array<String> ] the command arguments to be executed
|
28
53
|
def cmd(*args)
|
29
54
|
args.unshift 'bundle', 'exec'
|
30
55
|
puts Shellwords.join(args)
|
31
56
|
system(*args) or exit $?.exitstatus
|
32
57
|
end
|
33
58
|
|
34
|
-
|
59
|
+
# The find_cmd method searches for the first available command in a list of
|
60
|
+
# candidates.
|
61
|
+
#
|
62
|
+
# It attempts to locate executable commands by checking their availability in
|
63
|
+
# the system path. The method returns the first successfully found command or
|
64
|
+
# executes a fallback block if none are found.
|
65
|
+
#
|
66
|
+
# @param cmds [ Array<String> ] an array of command names to search for
|
67
|
+
# @param on_fail [ Proc ] a block to execute if no commands are found
|
68
|
+
#
|
69
|
+
# @return [ String, Object ] the first found command string or the result of the fallback block
|
70
|
+
def find_cmd(*cmds, on_fail: -> *cmds { fail "no #{cmds * '|'} command found" })
|
35
71
|
cmds.map { |c| `which #{c}`.full?(:chomp) }.compact.first or on_fail.(*cmds)
|
36
72
|
end
|
37
73
|
|
74
|
+
# The start_server method initializes and begins operation of a probe server.
|
75
|
+
#
|
76
|
+
# This method configures the environment for server operation by setting the
|
77
|
+
# thread abort behavior based on the debug flag, then creates and starts a new
|
78
|
+
# probe server instance to handle incoming requests and process jobs.
|
38
79
|
def start_server
|
39
80
|
Thread.abort_on_exception = $DEBUG
|
40
81
|
Utils::ProbeServer.new.start
|
41
82
|
end
|
42
83
|
|
84
|
+
# The connect_server method establishes a connection to a probe server and
|
85
|
+
# handles environment variable operations.
|
86
|
+
#
|
87
|
+
# This method initializes a probe client and processes command-line options for
|
88
|
+
# setting or retrieving environment variables.
|
89
|
+
# It also enqueues jobs for execution on the probe server when specified.
|
90
|
+
#
|
43
91
|
def connect_server
|
44
92
|
probe_client = ProbeClient.new
|
45
93
|
if setting = $opts[?C]
|
data/bin/rainbow
CHANGED
@@ -1,10 +1,50 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# rainbow - Create colorful ASCII art with Figlet fonts
|
4
|
+
#
|
5
|
+
# This script generates rainbow-colored ASCII text using Figlet fonts. It
|
6
|
+
# takes input text and converts it to colorful ASCII art by applying
|
7
|
+
# alternating colors (red, yellow, green, cyan, blue, magenta) to each line.
|
8
|
+
#
|
9
|
+
# Usage:
|
10
|
+
# rainbow "Hello World" # Basic usage with text argument
|
11
|
+
# echo "Hello" | rainbow # Read from stdin
|
12
|
+
# rainbow # Defaults to "ruby X.X.X"
|
13
|
+
#
|
14
|
+
# Requirements:
|
15
|
+
# - figlet installed in PATH
|
16
|
+
#
|
17
|
+
# The script automatically discovers Figlet fonts in the system installation
|
18
|
+
# directory and provides helpful error messages when fonts are not found.
|
19
|
+
#
|
20
|
+
# Examples:
|
21
|
+
# rainbow "Welcome" small
|
22
|
+
# rainbow "Ruby" big
|
23
|
+
# echo "World" | rainbow slant
|
2
24
|
|
3
25
|
require 'figlet'
|
4
26
|
require 'term/ansicolor'
|
5
27
|
include Term::ANSIColor
|
6
28
|
|
29
|
+
# The fetch_font method retrieves a Figlet font by name.
|
30
|
+
#
|
31
|
+
# This method attempts to locate and load a Figlet font file based on the
|
32
|
+
# provided font name. It first checks if figlet is available in the system
|
33
|
+
# path, and exits if it's not found.
|
34
|
+
# The method then constructs the appropriate font file path by checking for the
|
35
|
+
# font in the current directory or searching within the figlet installation
|
36
|
+
# directory. If the font cannot be found, it lists all available fonts and
|
37
|
+
# exits with an error message.
|
38
|
+
#
|
39
|
+
# @param font_name [ String ] the name of the font to fetch
|
40
|
+
#
|
41
|
+
# @return [ Figlet::Font ] a new Figlet::Font object initialized with the found
|
42
|
+
# font file path
|
7
43
|
def fetch_font(font_name)
|
44
|
+
if `which figlet`.empty?
|
45
|
+
STDERR.puts "Require figlet to be in path, please install it."
|
46
|
+
exit 1
|
47
|
+
end
|
8
48
|
font_name += ".flf" unless font_name.end_with?(".flf")
|
9
49
|
|
10
50
|
font_path =
|
@@ -24,6 +64,18 @@ def fetch_font(font_name)
|
|
24
64
|
Figlet::Font.new(font_path)
|
25
65
|
end
|
26
66
|
|
67
|
+
# The create_rainbow_ascii method generates colored ASCII art text using a
|
68
|
+
# specified color palette.
|
69
|
+
#
|
70
|
+
# This method takes an input text string and converts it into rainbow-colored
|
71
|
+
# ASCII art by applying different colors to each line of the art. It utilizes a
|
72
|
+
# predefined set of colors that cycle through the available color options to
|
73
|
+
# create a vibrant visual effect.
|
74
|
+
#
|
75
|
+
# @param text [ String ] the input text to be converted into ASCII art
|
76
|
+
#
|
77
|
+
# @return [ String ] the colored ASCII art text with rainbow coloring applied
|
78
|
+
# to each line
|
27
79
|
def create_rainbow_ascii(text)
|
28
80
|
ascii_art = $t[text]
|
29
81
|
|