rubbish 0.2.200128 → 1.1.221208
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +71 -51
- data/lib/rubbish.rb +33 -42
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6a9c2f7befeba1ee6244441d88f39abb7f3f955108913885c4a785d55b325dd
|
4
|
+
data.tar.gz: b7f136c136d7ab3711186afdc2334276432347010ddf899e09a4c85c9790a43c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8d6e4ce9dab28c64dde5a56f91178ad0dba87f2f20087722cad5c988733416f26633c95277bf5b14f6574c78d8537cd27e6fbc1609115bb9a370a9a0557d6e9
|
7
|
+
data.tar.gz: 1c9ba07b399f41aaff250b10fb09b151ce2122a65211b4cb8cc74fa8d9eee540ba06232b1ea0a7b9baeedb00e028df6991ff3420d5533c50f181c14d294dab34
|
data/README.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# rubbish
|
2
2
|
|
3
|
+
* [VERSION 1.1.221208](https://github.com/carlosjhr64/rubbish/releases)
|
4
|
+
* [github](https://www.github.com/carlosjhr64/rubbish)
|
5
|
+
* [rubygems](https://rubygems.org/gems/rubbish)
|
6
|
+
|
7
|
+
## Deprecation notice:
|
8
|
+
|
9
|
+
This is my last `Rubbish` update.
|
10
|
+
I've merged this project with [Helpema](https://www.github.com/carlosjhr64/helpema).
|
11
|
+
|
3
12
|
## DESCRIPTION:
|
4
13
|
|
5
14
|
A ruby-ish way to go to the shell.
|
@@ -10,64 +19,75 @@ Bash and Fish aware.
|
|
10
19
|
|
11
20
|
Although it's easy enough to access the system's default shell from ruby,
|
12
21
|
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
|
-
|
22
|
+
```ruby
|
23
|
+
require 'rubbish'
|
24
|
+
|
25
|
+
# Fish features the double splat...
|
26
|
+
# reads output and returns it:
|
27
|
+
Rubbish.fish('ls lib/**.rb').split #=> ["lib/rubbish.rb"]
|
28
|
+
# The '?' method return weather or not the command succeeded.
|
29
|
+
# Fish's true and false commands:
|
30
|
+
Rubbish.fish?('true') #=> true
|
31
|
+
Rubbish.fish?('false') #=> false
|
32
|
+
|
33
|
+
# Run a bash script, have it output to STDOUT...
|
34
|
+
Rubbish.bash? <<-BASH
|
35
|
+
echo "Date/Time now: "
|
36
|
+
date
|
37
|
+
BASH
|
38
|
+
#=> true
|
39
|
+
|
40
|
+
# Rubbish will accept :fish and :bash calls, but
|
41
|
+
# you can add other shells... say... ruby?
|
42
|
+
# sure, why not:
|
43
|
+
Rubbish::SHELL_VERSION[:ruby] = '3.0' # Ensures it's ruby ~>3.0.
|
44
|
+
answer = Rubbish.ruby <<-RUBY
|
45
|
+
a = 5
|
46
|
+
b = 6
|
47
|
+
puts a+b
|
48
|
+
RUBY
|
49
|
+
#=> "11\n"
|
50
|
+
```
|
36
51
|
## FEATURES:
|
37
52
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
53
|
+
```ruby
|
54
|
+
Rubbish.shell('echo "OK"') #=> "OK\n"
|
55
|
+
Rubbish.shell(shell:'fish'){|p| p.puts 'echo "OK"'} #=> "OK\n"
|
56
|
+
Rubbish.bash('echo "OK"') #=> "OK\n"
|
57
|
+
Rubbish.fish('true') #=> ""
|
58
|
+
```
|
59
|
+
Exit status instead:
|
60
|
+
```ruby
|
61
|
+
Rubbish.shell('true', shell:'fish', read:false) #=> true
|
62
|
+
Rubbish.shell('false', shell:'fish', read:false) #=> false
|
63
|
+
Rubbish.fish?('true') #=> true
|
64
|
+
Rubbish.fish?('false') #=> false
|
65
|
+
```
|
50
66
|
An edge case:
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
67
|
+
```ruby
|
68
|
+
b = nil
|
69
|
+
a = Rubbish.bash do |p|
|
70
|
+
p.puts "echo Good"
|
71
|
+
p.puts "echo Day!"
|
72
|
+
b = p.gets
|
73
|
+
end
|
74
|
+
b #=> "Good\n"
|
75
|
+
a #=> "Day!\n"
|
76
|
+
```
|
77
|
+
Passing options to the "shell":
|
78
|
+
```ruby
|
79
|
+
Rubbish::SHELL_VERSION[:date] = nil
|
80
|
+
Rubbish.date date:'2021-09-21', R:true #=> "Tue, 21 Sep 2021 00:00:00 -0700\n"
|
81
|
+
```
|
62
82
|
## INSTALL:
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
83
|
+
```console
|
84
|
+
$ gem install rubbish
|
85
|
+
```
|
86
|
+
## LICENSE:
|
67
87
|
|
68
88
|
(The MIT License)
|
69
89
|
|
70
|
-
Copyright (c)
|
90
|
+
Copyright (c) 2022 CarlosJHR64
|
71
91
|
|
72
92
|
Permission is hereby granted, free of charge, to any person obtaining
|
73
93
|
a copy of this software and associated documentation files (the
|
data/lib/rubbish.rb
CHANGED
@@ -1,28 +1,10 @@
|
|
1
1
|
module Rubbish
|
2
|
-
VERSION = '
|
2
|
+
VERSION = '1.1.221208'
|
3
3
|
SHELL_VERSION = {bash: nil, fish: nil}
|
4
|
+
# This is a contraction of Shellwords.escape function
|
5
|
+
SHELLWORDS_ESCAPE = lambda{|w|w.gsub(/[^\w\-.,:+\/@\n]/,'\\\\\\&').gsub(/\n/,"'\n'")}
|
4
6
|
|
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)
|
7
|
+
def self.shell(script=nil, shell:'bash', read:true, &block)
|
26
8
|
IO.popen(shell, (read)? 'w+' : 'w') do |pipe|
|
27
9
|
# No matter what, we know we're going to write first.
|
28
10
|
writing = true
|
@@ -32,38 +14,47 @@ module Rubbish
|
|
32
14
|
pipe.close_write
|
33
15
|
writing = false
|
34
16
|
end
|
35
|
-
if block
|
36
|
-
|
37
|
-
|
38
|
-
pipe.close_write if writing
|
39
|
-
end
|
17
|
+
block.call(pipe) if block
|
18
|
+
# close if we were writing
|
19
|
+
pipe.close_write if writing
|
40
20
|
# Read if reading
|
41
21
|
read = pipe.read if read
|
42
22
|
end
|
43
23
|
read || $?.to_i==0
|
44
24
|
end
|
45
25
|
|
46
|
-
def self.method_missing(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
26
|
+
def self.method_missing(cmd, *args, **kw, &block)
|
27
|
+
cmd=cmd[0..-2].to_sym unless read=(cmd[-1]!='?')
|
28
|
+
return super unless SHELL_VERSION.has_key?(cmd) and args.length.between?(0,1)
|
29
|
+
if minimum = SHELL_VERSION[cmd]
|
30
|
+
minimum = Gem::Version.new minimum
|
31
|
+
if version = `#{cmd} --version`.match(/\d+\.\d+\.\d+/)&.match(0)
|
32
|
+
version = Gem::Version.new version
|
33
|
+
bumped = minimum.bump
|
34
|
+
unless version >= minimum and version < bumped
|
35
|
+
raise "Need #{cmd} version ~> #{minimum}"
|
36
|
+
end
|
37
|
+
# need to only check once
|
38
|
+
SHELL_VERSION[cmd] = nil
|
39
|
+
else
|
40
|
+
raise "Could not get the #{cmd} version"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
command = [cmd.to_s]
|
44
|
+
if kw.length > 0
|
45
|
+
kw.each do |k,w|
|
46
|
+
next if not w
|
47
|
+
if w==true
|
48
|
+
command << "#{k.length>1? '--':'-'}#{k}"
|
56
49
|
else
|
57
|
-
|
50
|
+
command << "--#{k}=#{w}"
|
58
51
|
end
|
59
52
|
end
|
60
|
-
script, read = Rubbish.args(*args)
|
61
|
-
return Rubbish.shell(shell.to_s, script, read, &block)
|
62
53
|
end
|
63
|
-
|
54
|
+
script = args[0]
|
55
|
+
return Rubbish.shell(script, shell:command, read:read, &block)
|
64
56
|
end
|
65
57
|
end
|
66
|
-
|
67
58
|
# Requires:
|
68
59
|
#`ruby`
|
69
60
|
#`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:
|
4
|
+
version: 1.1.221208
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- CarlosJHR64
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
A ruby-ish way to go to the shell.
|
@@ -40,10 +40,10 @@ 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.
|
45
|
-
- 'fish: fish, version 3.
|
46
|
-
rubygems_version: 3.
|
43
|
+
- 'ruby: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [aarch64-linux]'
|
44
|
+
- 'bash: GNU bash, version 5.1.4(1)-release (aarch64-unknown-linux-gnu)'
|
45
|
+
- 'fish: fish, version 3.5.1'
|
46
|
+
rubygems_version: 3.3.7
|
47
47
|
signing_key:
|
48
48
|
specification_version: 4
|
49
49
|
summary: A ruby-ish way to go to the shell.
|