bashisms 0.1.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ce103809b00b1eadaa9abe09774a096b5ed73afdb4bddbe348708dc66452ac3
4
- data.tar.gz: 6784e05d427faa209c6bf986e4fd9e59f11744b0edf1dda12c484e8b519cb702
3
+ metadata.gz: 51c82d4b514ae26633dcac5b39b3c83e6f84c253c3bf29ce0a44a672d0afd040
4
+ data.tar.gz: 770d454cc9c29904d3b050ca3724d71c8f604561b2ed6e09a4076ec0d69d713a
5
5
  SHA512:
6
- metadata.gz: 79ebedd71a25a369256d683411d289bc1e12a90135736a2b831fc977492f2eeae82d5584f669db88eb250413101a58c8532e76cd83fa99b7bf6eca69d6b8d870
7
- data.tar.gz: b068f5f2e5913016c94b6ab8b6adca4350bd6447177e386f6973ab0a44957e6d02c5ed3004a43770de95e7098a861486c4c43628b7b4bd31f4ddf945844016c0
6
+ metadata.gz: d6d33c98b6db9055078198f726e1b08f4e12397ec7eec909499f72184235bd61e807c3302308a4da2b2bc61b6a24979fb19beae8ab7aa3d39e53446eded5b168
7
+ data.tar.gz: 7df774f80d46976e83fc2d2a0248fb4d81fbf6668742bba653a45a3f69cebb2b0e9e1cf33975fef9a0c9544acc37746be5baa4355210377ebb047db3a9091d0d
data/README.md CHANGED
@@ -21,20 +21,41 @@ done
21
21
  Now in Ruby, thanks to bashisms:
22
22
 
23
23
  ```ruby
24
- require "bashisms"
25
-
26
- def safe_sleep n
27
- $SECONDS = 0
28
- while $SECONDS != n
29
- end
24
+ #!/usr/bin/env -S ruby -rbashisms
25
+ $SECONDS = 0
26
+ while $SECONDS != $1.to_i
30
27
  end
31
28
  ```
32
29
 
33
- ## Variables
30
+ ```bash
31
+ $ ./safe_sleep 5
32
+ ```
33
+
34
+ OR
35
+
36
+ ```bash
37
+ $ ruby -rbashisms safe_sleep 5
38
+ ```
39
+
40
+ ## Positional Arguments
41
+
42
+ `$0`, `$1`, `$2`, ... `$9` work just like in bash:
34
43
 
35
44
  ```ruby
36
- require "bashisms"
45
+ #!/usr/bin/env -S ruby -rbashisms
46
+ echo "I am #{$0}"
47
+ echo "Hello, #{$1}! You are #{$2} years old."
48
+ ```
49
+
50
+ ```bash
51
+ $ ./greet World 30
52
+ # I am ./greet
53
+ # Hello, World! You are 30 years old.
54
+ ```
55
+
56
+ ## Variables
37
57
 
58
+ ```ruby
38
59
  $RANDOM # => 16838
39
60
  $RANDOM # => 4592
40
61
 
data/examples/greet ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env -S ruby -rbashisms
2
+ echo "I am #{$0}"
3
+ echo "Hello, #{$1}! You are #{$2} years old."
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env -S ruby -rbashisms
2
+ $SECONDS = 0
3
+ echo "#$BASH_VERSION: Sleeping #$1 seconds"
4
+ while $SECONDS != $1.to_i
5
+ end
@@ -149,6 +149,13 @@ bashisms_lines_getter(ID id, VALUE *data)
149
149
  return INT2FIX(24);
150
150
  }
151
151
 
152
+ static VALUE
153
+ bashisms_set_global(VALUE self, VALUE name, VALUE value)
154
+ {
155
+ rb_gv_set(StringValueCStr(name), value);
156
+ return value;
157
+ }
158
+
152
159
  RUBY_FUNC_EXPORTED void
153
160
  Init_bashisms(void)
154
161
  {
@@ -171,4 +178,6 @@ Init_bashisms(void)
171
178
  rb_define_virtual_variable("$MACHTYPE", bashisms_machtype_getter, NULL);
172
179
  rb_define_virtual_variable("$COLUMNS", bashisms_columns_getter, NULL);
173
180
  rb_define_virtual_variable("$LINES", bashisms_lines_getter, NULL);
181
+
182
+ rb_define_module_function(rb_mBashisms, "set_global", bashisms_set_global, 2);
174
183
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bashisms
4
- VERSION = "0.1.0"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/bashisms.rb CHANGED
@@ -7,6 +7,8 @@ module Bashisms
7
7
  class Error < StandardError; end
8
8
  end
9
9
 
10
+ TOPLEVEL_BINDING.eval('ARGV.join("\x00") =~ /\A([^\x00]*)(?:\x00([^\x00]*)(?:\x00([^\x00]*)(?:\x00([^\x00]*)(?:\x00([^\x00]*)(?:\x00([^\x00]*)(?:\x00([^\x00]*)(?:\x00([^\x00]*)(?:\x00([^\x00]*))?)?)?)?)?)?)?)?\z/')
11
+
10
12
  module Kernel
11
13
  def echo(*args)
12
14
  puts(*args)
@@ -19,7 +21,12 @@ module Kernel
19
21
  def export(pair)
20
22
  key, value = pair.to_s.split("=", 2)
21
23
  ENV[key] = value
24
+ Bashisms.set_global("$#{key}", value)
25
+ end
26
+
27
+ def read
28
+ $REPLY = $stdin.gets&.chomp || ""
22
29
  end
23
30
 
24
- private :echo, :source, :export
31
+ private :echo, :source, :export, :read
25
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bashisms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
@@ -21,6 +21,8 @@ files:
21
21
  - LICENSE.txt
22
22
  - README.md
23
23
  - Rakefile
24
+ - examples/greet
25
+ - examples/safe_sleep
24
26
  - ext/bashisms/bashisms.c
25
27
  - ext/bashisms/bashisms.h
26
28
  - ext/bashisms/extconf.rb