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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rsh +31 -9
  3. metadata +5 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35dd4b1b6792ae0a66b0da2efd24bf78af5f2ba268fd933bd0af2b43e7fb0b23
4
- data.tar.gz: 6c1f6026a8870e178788190f702de82f3845364ebaa4e42a9952a8f9b61d9d0e
3
+ metadata.gz: c2eadccdac83c394da85a64a138d36cad24de2603aeb2867bce52f4aa00d0568
4
+ data.tar.gz: 0b54ea26c9f82db1f1c29fffbc6e69d19c0c4ad3e5d94d490ba33aaf268be3c5
5
5
  SHA512:
6
- metadata.gz: e9a950baff3af17ae641fe67a9782b5888c4e1ce93a94354558ec39adecbbe9254710a5719a000254c326eb71d9b91b098edea77dcdedcf773baff269448fa5c
7
- data.tar.gz: a84ce4e143a9237549affdb6befd894adf032737ae949edd4e326fe8858a127158f976760bfb43e41b6e51f8b58cf62e0271ebfec1cfa41e6b8f67763ecbe957
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.8" # Code refactoring: DRY helpers, nick/gnick feedback, bug fixes
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 \"Math.sqrt(16)\""
2522
- puts " calc \"Math::PI * 2\""
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
- # Safe evaluation with Math library
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 "Syntax error in expression: #{e.message}"
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 evaluating expression: #{e.message}"
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.8
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-29 00:00:00.000000000 Z
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.8: Code refactoring with DRY helpers (ensure_type, persist_var), nick/gnick
16
- feedback messages, fixed @plugin_enabled bug. Cleaner, more maintainable codebase!'
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