rubbish 0.2.200128 → 1.0.210921
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +65 -50
- data/lib/rubbish.rb +18 -33
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0f0bcdd58cb0bd08f604b7acaee9cadb5ccabaa022a5a8db7d85f64f7e50580
|
4
|
+
data.tar.gz: b51390309a1af812676a37d1631c6cdddc73a96f7b94875f4a41ee4984414698
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ae8609febdeaadf67a15e250124cc3491aa2f4e9c9f6646b0edb179fef9424fbcdfad7e0d91d124ec3903efa181139c6e71ad91d26f2dff71e9d9f71f4c86c6
|
7
|
+
data.tar.gz: 85c409b26548537d4ecebd7b6845bc1c5245b5fca28cb0f0c7ff90ff04f75b8e89161a4e057a825995bf614c41192615c0fde8e4800e0dc622e441bebb881c93
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# rubbish
|
2
2
|
|
3
|
+
* [VERSION 1.0.210921](https://github.com/author/rubbish/releases)
|
4
|
+
* [github](https://www.github.com/author/rubbish)
|
5
|
+
* [rubygems](https://rubygems.org/gems/rubbish)
|
6
|
+
|
3
7
|
## DESCRIPTION:
|
4
8
|
|
5
9
|
A ruby-ish way to go to the shell.
|
@@ -10,64 +14,75 @@ Bash and Fish aware.
|
|
10
14
|
|
11
15
|
Although it's easy enough to access the system's default shell from ruby,
|
12
16
|
you may want to run a specific shell like fish for it's unique features:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
17
|
+
```ruby
|
18
|
+
require 'rubbish'
|
19
|
+
|
20
|
+
# Fish features the double splat...
|
21
|
+
# reads output and returns it:
|
22
|
+
Rubbish.fish('ls lib/**.rb').split #=> ["lib/rubbish.rb"]
|
23
|
+
# The '?' method return weather or not the command succeeded.
|
24
|
+
# Fish's true and false commands:
|
25
|
+
Rubbish.fish?('true') #=> true
|
26
|
+
Rubbish.fish?('false') #=> false
|
27
|
+
|
28
|
+
# Run a bash script, have it output to STDOUT...
|
29
|
+
Rubbish.bash? <<-BASH
|
30
|
+
echo "Date/Time now: "
|
31
|
+
date
|
32
|
+
BASH
|
33
|
+
#=> true
|
34
|
+
|
35
|
+
# Rubbish will accept :fish and :bash calls, but
|
36
|
+
# you can add other shells... say... ruby?
|
37
|
+
# sure, why not:
|
38
|
+
Rubbish::SHELL_VERSION[:ruby] = '3.0' # Ensures it's ruby ~>3.0.
|
39
|
+
answer = Rubbish.ruby <<-RUBY
|
40
|
+
a = 5
|
41
|
+
b = 6
|
42
|
+
puts a+b
|
43
|
+
RUBY
|
44
|
+
#=> "11\n"
|
45
|
+
```
|
36
46
|
## FEATURES:
|
37
47
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
```ruby
|
49
|
+
Rubbish.shell('echo "OK"') #=> "OK\n"
|
50
|
+
Rubbish.shell(shell:'fish'){|p| p.puts 'echo "OK"'} #=> "OK\n"
|
51
|
+
Rubbish.bash('echo "OK"') #=> "OK\n"
|
52
|
+
Rubbish.fish('true') #=> ""
|
53
|
+
```
|
54
|
+
Exit status instead:
|
55
|
+
```ruby
|
56
|
+
Rubbish.shell('true', shell:'fish', read:false) #=> true
|
57
|
+
Rubbish.shell('false', shell:'fish', read:false) #=> false
|
58
|
+
Rubbish.fish?('true') #=> true
|
59
|
+
Rubbish.fish?('false') #=> false
|
60
|
+
```
|
50
61
|
An edge case:
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
+
```ruby
|
63
|
+
b = nil
|
64
|
+
a = Rubbish.bash do |p|
|
65
|
+
p.puts "echo Good"
|
66
|
+
p.puts "echo Day!"
|
67
|
+
b = p.gets
|
68
|
+
end
|
69
|
+
b #=> "Good\n"
|
70
|
+
a #=> "Day!\n"
|
71
|
+
```
|
72
|
+
Passing options to the "shell":
|
73
|
+
```ruby
|
74
|
+
Rubbish::SHELL_VERSION[:date] = nil
|
75
|
+
Rubbish.date date:'2021-09-21' #=> "Tue Sep 21 12:00:00 AM PDT 2021\n"
|
76
|
+
```
|
62
77
|
## INSTALL:
|
63
|
-
|
64
|
-
|
65
|
-
|
78
|
+
```console
|
79
|
+
$ gem install rubbish
|
80
|
+
```
|
66
81
|
== LICENSE:
|
67
82
|
|
68
83
|
(The MIT License)
|
69
84
|
|
70
|
-
Copyright (c)
|
85
|
+
Copyright (c) 2021 CarlosJHR64
|
71
86
|
|
72
87
|
Permission is hereby granted, free of charge, to any person obtaining
|
73
88
|
a copy of this software and associated documentation files (the
|
data/lib/rubbish.rb
CHANGED
@@ -1,28 +1,8 @@
|
|
1
1
|
module Rubbish
|
2
|
-
VERSION = '0.
|
2
|
+
VERSION = '1.0.210921'
|
3
3
|
SHELL_VERSION = {bash: nil, fish: nil}
|
4
4
|
|
5
|
-
|
6
|
-
# Let there be Rubbish.args!!!
|
7
|
-
def self.args(*args)
|
8
|
-
script, read = nil, true
|
9
|
-
until args.empty?
|
10
|
-
arg = args.shift
|
11
|
-
case arg
|
12
|
-
when String
|
13
|
-
script = arg
|
14
|
-
when TrueClass, FalseClass
|
15
|
-
read = arg
|
16
|
-
when Hash
|
17
|
-
script = arg[:script] if arg.has_key? :script
|
18
|
-
read = arg[:read] if arg.has_key? :read
|
19
|
-
end
|
20
|
-
end
|
21
|
-
return script, read
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.shell(shell, *args, &block)
|
25
|
-
script, read = Rubbish.args(*args)
|
5
|
+
def self.shell(script=nil, shell:'bash', read:true, &block)
|
26
6
|
IO.popen(shell, (read)? 'w+' : 'w') do |pipe|
|
27
7
|
# No matter what, we know we're going to write first.
|
28
8
|
writing = true
|
@@ -32,38 +12,43 @@ module Rubbish
|
|
32
12
|
pipe.close_write
|
33
13
|
writing = false
|
34
14
|
end
|
35
|
-
if block
|
36
|
-
|
37
|
-
|
38
|
-
pipe.close_write if writing
|
39
|
-
end
|
15
|
+
block.call(pipe) if block
|
16
|
+
# close if we were writing
|
17
|
+
pipe.close_write if writing
|
40
18
|
# Read if reading
|
41
19
|
read = pipe.read if read
|
42
20
|
end
|
43
21
|
read || $?.to_i==0
|
44
22
|
end
|
45
23
|
|
46
|
-
def self.method_missing(shell, *args, &block)
|
47
|
-
|
24
|
+
def self.method_missing(shell, *args, **kw, &block)
|
25
|
+
shell=shell[0..-2].to_sym unless read=(shell[-1]!='?')
|
26
|
+
if SHELL_VERSION.has_key?(shell) and args.length.between?(0,1)
|
48
27
|
if minimum = SHELL_VERSION[shell]
|
49
28
|
minimum = Gem::Version.new minimum
|
50
29
|
if version = `#{shell} --version`.scan(/\d+\.\d+\.\d+/).first
|
51
30
|
version = Gem::Version.new version
|
52
31
|
bumped = minimum.bump
|
53
|
-
|
32
|
+
unless version >= minimum and version < bumped
|
33
|
+
raise "Need #{shell} version ~> #{minimum}"
|
34
|
+
end
|
54
35
|
# need to only check once
|
55
36
|
SHELL_VERSION[shell] = nil
|
56
37
|
else
|
57
38
|
raise "Could not get the #{shell} version"
|
58
39
|
end
|
59
40
|
end
|
60
|
-
|
61
|
-
|
41
|
+
shell = shell.to_s
|
42
|
+
if kw.length > 0
|
43
|
+
shell << ' ' + kw.select{_2}.map{
|
44
|
+
"--#{_1}=#{_2}".sub(/=(true)?$/,'').sub(/^--(\w)$/, '-\1')}.join(' ')
|
45
|
+
end
|
46
|
+
script = args[0]
|
47
|
+
return Rubbish.shell(script, shell:shell, read:read, &block)
|
62
48
|
end
|
63
49
|
super
|
64
50
|
end
|
65
51
|
end
|
66
|
-
|
67
52
|
# Requires:
|
68
53
|
#`ruby`
|
69
54
|
#`bash`
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubbish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.210921
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- CarlosJHR64
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
A ruby-ish way to go to the shell.
|
@@ -25,7 +25,7 @@ homepage: https://github.com/carlosjhr64/rubbish
|
|
25
25
|
licenses:
|
26
26
|
- MIT
|
27
27
|
metadata: {}
|
28
|
-
post_install_message:
|
28
|
+
post_install_message:
|
29
29
|
rdoc_options: []
|
30
30
|
require_paths:
|
31
31
|
- lib
|
@@ -40,11 +40,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
requirements:
|
43
|
-
- 'ruby: ruby
|
44
|
-
- 'bash: GNU bash, version 5.0
|
45
|
-
- 'fish: fish, version 3.
|
46
|
-
rubygems_version: 3.
|
47
|
-
signing_key:
|
43
|
+
- 'ruby: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]'
|
44
|
+
- 'bash: GNU bash, version 5.1.0(1)-release (x86_64-redhat-linux-gnu)'
|
45
|
+
- 'fish: fish, version 3.3.1'
|
46
|
+
rubygems_version: 3.2.22
|
47
|
+
signing_key:
|
48
48
|
specification_version: 4
|
49
49
|
summary: A ruby-ish way to go to the shell.
|
50
50
|
test_files: []
|