ruby-shell 3.4.8 → 3.4.9
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/rsh +31 -9
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c2eadccdac83c394da85a64a138d36cad24de2603aeb2867bce52f4aa00d0568
|
|
4
|
+
data.tar.gz: 0b54ea26c9f82db1f1c29fffbc6e69d19c0c4ad3e5d94d490ba33aaf268be3c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8448bde19ed12fb02b3b28a7295f928ce643caa43ce7045f8693a733729bd8dea2b23c01cbae44fcf3d39f412238a5aa5a17281e9d55cf64f5ec2bf5c56fe38d
|
|
7
|
+
data.tar.gz: bd903733344c8aa9b0d42a2dfbcaf63339861bc7db5a289425881fea0a8c10fcbfc705a0840000ef165a99a843ebdd39c155263fe393fbd09ce8885dad6513c0
|
data/bin/rsh
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
# Web_site: http://isene.com/
|
|
9
9
|
# Github: https://github.com/isene/rsh
|
|
10
10
|
# License: Public domain
|
|
11
|
-
@version = "3.4.
|
|
11
|
+
@version = "3.4.9" # Improved :calc with safer eval, Math sandbox, better error messages
|
|
12
12
|
|
|
13
13
|
# MODULES, CLASSES AND EXTENSIONS
|
|
14
14
|
class String # Add coloring to strings (with escaping for Readline)
|
|
@@ -2515,24 +2515,46 @@ def validate_command(cmd) # Syntax validation before execution
|
|
|
2515
2515
|
end
|
|
2516
2516
|
def calc(*args) # Inline calculator using Ruby's Math library
|
|
2517
2517
|
if args.empty?
|
|
2518
|
-
puts "Usage: calc <expression>"
|
|
2518
|
+
puts "Usage: :calc <expression>"
|
|
2519
2519
|
puts "Examples:"
|
|
2520
|
-
puts " calc 2 + 2"
|
|
2521
|
-
puts " calc
|
|
2522
|
-
puts " calc
|
|
2520
|
+
puts " :calc 2 + 2"
|
|
2521
|
+
puts " :calc Math.sqrt(16)"
|
|
2522
|
+
puts " :calc Math::PI * 2"
|
|
2523
|
+
puts " :calc sin(PI/4)"
|
|
2524
|
+
puts "Available: +, -, *, /, **, %, sqrt, sin, cos, tan, log, exp, abs, PI, E, etc."
|
|
2523
2525
|
return
|
|
2524
2526
|
end
|
|
2525
2527
|
|
|
2526
2528
|
expression = args.join(' ')
|
|
2527
2529
|
|
|
2530
|
+
# Create sandbox with Math module for safer evaluation
|
|
2531
|
+
sandbox = Object.new
|
|
2532
|
+
sandbox.extend(Math)
|
|
2533
|
+
|
|
2528
2534
|
begin
|
|
2529
|
-
|
|
2530
|
-
result = eval(expression, binding, __FILE__, __LINE__)
|
|
2535
|
+
result = sandbox.instance_eval(expression)
|
|
2531
2536
|
puts result
|
|
2537
|
+
rescue ZeroDivisionError
|
|
2538
|
+
puts "Error: Division by zero"
|
|
2539
|
+
rescue NameError => e
|
|
2540
|
+
# Extract the undefined name
|
|
2541
|
+
if e.message =~ /undefined local variable or method `(\w+)'/
|
|
2542
|
+
undefined = $1
|
|
2543
|
+
puts "Error: Unknown function or variable '#{undefined}'"
|
|
2544
|
+
puts "Available Math functions: sqrt, sin, cos, tan, log, exp, abs, ceil, floor, round"
|
|
2545
|
+
puts "Constants: PI, E"
|
|
2546
|
+
else
|
|
2547
|
+
puts "Error: #{e.message}"
|
|
2548
|
+
end
|
|
2532
2549
|
rescue SyntaxError => e
|
|
2533
|
-
puts "
|
|
2550
|
+
puts "Error: Invalid expression syntax"
|
|
2551
|
+
puts "Check parentheses, operators, and spacing"
|
|
2552
|
+
rescue ArgumentError => e
|
|
2553
|
+
puts "Error: Invalid argument - #{e.message}"
|
|
2554
|
+
rescue TypeError => e
|
|
2555
|
+
puts "Error: Type mismatch - #{e.message}"
|
|
2534
2556
|
rescue => e
|
|
2535
|
-
puts "Error
|
|
2557
|
+
puts "Error: #{e.message}"
|
|
2536
2558
|
end
|
|
2537
2559
|
end
|
|
2538
2560
|
def validate(rule_str = nil) # Custom validation rule management
|
metadata
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-shell
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.4.
|
|
4
|
+
version: 3.4.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Geir Isene
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-10-
|
|
11
|
+
date: 2025-10-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: 'A shell written in Ruby with extensive tab completions, aliases/nicks,
|
|
14
14
|
history, syntax highlighting, theming, auto-cd, auto-opening files and more. UPDATE
|
|
15
|
-
v3.4.
|
|
16
|
-
|
|
15
|
+
v3.4.9: Improved :calc with Math sandbox for safer evaluation, better error messages
|
|
16
|
+
(division by zero, unknown functions, syntax errors). Suggested by havenwood from
|
|
17
|
+
#ruby IRC!'
|
|
17
18
|
email: g@isene.com
|
|
18
19
|
executables:
|
|
19
20
|
- rsh
|