rubbish 0.0.0 → 0.1.191210
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/{README.rdoc → README.md} +35 -18
- data/lib/rubbish.rb +44 -4
- metadata +9 -17
- data/lib/rubbish/bash.rb +0 -17
- data/lib/rubbish/fish.rb +0 -17
- data/lib/rubbish/rubbish.rb +0 -27
- data/lib/rubbish/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 042fd02674603c2c64373010fa131f5de23e83d677f0439450eb7956275340f0
|
4
|
+
data.tar.gz: 82f9d9dc31a0ab7dcb14c9483f79bbe46d1cd5b002d53e00a9e374032593d5b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6429a13123d6f33359074e9a3ce23b2841b6f64a800a9f2463fd18f5fa7112bd869ceb1d7faa206875dd6f2c03a4d8c248829125de6c8f9fdf28b17a90573fc1
|
7
|
+
data.tar.gz: 9e7d8a4138c34a0c96801cf4f2cf8b97052402d238f8fc2353f0ecf7f0380071a092c70423e2000c020fe946d8c0729563c95af8bff7760476508c5dc378a41d
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,34 +1,51 @@
|
|
1
|
-
|
1
|
+
# rubbish
|
2
2
|
|
3
|
-
|
3
|
+
## DESCRIPTION:
|
4
4
|
|
5
5
|
A ruby-ish way to go to the shell.
|
6
6
|
|
7
7
|
Bash and Fish aware.
|
8
8
|
|
9
|
-
|
9
|
+
## SYNOPSIS:
|
10
|
+
|
11
|
+
Although it's easy enough to access the system's default shell from ruby,
|
12
|
+
you may want to run a specific shell like fish for it's unique features:
|
10
13
|
|
11
14
|
require 'rubbish'
|
12
|
-
extend Rubbish::Fish
|
13
|
-
a = fish <<FISH
|
14
|
-
echo "But why???"
|
15
|
-
FISH
|
16
|
-
puts a+'Because!!!!'
|
17
15
|
|
18
|
-
|
16
|
+
# Fish features the double splat...
|
17
|
+
# reads output and returns it.
|
18
|
+
ls_lib = Rubbish.fish('ls lib/**.rb').split #=> ["lib/good.rb", "lib/good/bad.rb", "lib/good/ugly.rb"]
|
19
|
+
|
20
|
+
# Run a bash script, have it output to STDOUT(read: false)...
|
21
|
+
Rubbish.bash <<-BASH, read: false
|
22
|
+
echo "Date/Time now: "
|
23
|
+
date
|
24
|
+
BASH
|
25
|
+
|
26
|
+
# Rubbish will accept :fish and :bash calls, but
|
27
|
+
# you can add other shells... say... ruby?
|
28
|
+
# sure, why not:
|
29
|
+
Rubbish::SHELL_VERSION[:ruby] = '2.0' # Ensures it's ruby ~>2.0.
|
30
|
+
answer = Rubbish.ruby <<-RUBY #=> "11"
|
31
|
+
a = 5
|
32
|
+
b = 6
|
33
|
+
puts a+b
|
34
|
+
RUBY
|
35
|
+
|
36
|
+
## FEATURES:
|
19
37
|
|
20
|
-
Read by default:
|
38
|
+
Read(read: true) by default:
|
21
39
|
|
22
40
|
* Rubbish.shell('bash','echo "OK"') #=> OK
|
23
|
-
* Rubbish.shell('
|
41
|
+
* Rubbish.shell('fish'){|p| p.puts 'echo "OK"'} #=> OK
|
24
42
|
* Rubbish.bash('echo "OK"') #=> OK
|
25
43
|
* Rubbish.fish('true') #=> ''
|
26
|
-
* Rubbish.fish('false') #=> ''
|
27
44
|
|
28
|
-
|
45
|
+
Exit status instead when not reading(read: false):
|
29
46
|
|
30
|
-
* Rubbish.fish('true', false) #=> true
|
31
|
-
* Rubbish.fish('false', false) #=> false
|
47
|
+
* Rubbish.fish('true', read: false) #=> true
|
48
|
+
* Rubbish.fish('false', read: false) #=> false
|
32
49
|
|
33
50
|
An edge case:
|
34
51
|
|
@@ -42,15 +59,15 @@ An edge case:
|
|
42
59
|
puts b # Good
|
43
60
|
puts a # Day!
|
44
61
|
|
45
|
-
|
62
|
+
## INSTALL:
|
46
63
|
|
47
|
-
|
64
|
+
$ gem install rubbish
|
48
65
|
|
49
66
|
== LICENSE:
|
50
67
|
|
51
68
|
(The MIT License)
|
52
69
|
|
53
|
-
Copyright (c)
|
70
|
+
Copyright (c) 2019 carlosjhr64
|
54
71
|
|
55
72
|
Permission is hereby granted, free of charge, to any person obtaining
|
56
73
|
a copy of this software and associated documentation files (the
|
data/lib/rubbish.rb
CHANGED
@@ -1,7 +1,47 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Rubbish
|
2
|
+
VERSION = '0.1.191210'
|
3
|
+
SHELL_VERSION = {bash: nil, fish: nil}
|
4
|
+
|
5
|
+
def self.shell(sh, script=nil, read: true, &block)
|
6
|
+
IO.popen(sh, (read)? 'w+' : 'w') do |psh|
|
7
|
+
# No matter what, we know we're going to write first.
|
8
|
+
writing = true
|
9
|
+
if script
|
10
|
+
# We were given the script, so we write it and close.
|
11
|
+
psh.write script
|
12
|
+
psh.close_write
|
13
|
+
writing = false
|
14
|
+
end
|
15
|
+
if block
|
16
|
+
block.call(psh)
|
17
|
+
# close if we were writing
|
18
|
+
psh.close_write if writing
|
19
|
+
end
|
20
|
+
# Read if reading
|
21
|
+
read = psh.read if read
|
22
|
+
end
|
23
|
+
read || $?.to_i==0
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.method_missing(shell, *args, &block)
|
27
|
+
if args.length.between?(0,2) and SHELL_VERSION.has_key? shell
|
28
|
+
if minimum = SHELL_VERSION[shell]
|
29
|
+
minimum = Gem::Version.new minimum
|
30
|
+
if version = `#{shell} --version`.scan(/\d+\.\d+\.\d+/).first
|
31
|
+
version = Gem::Version.new version
|
32
|
+
bumped = minimum.bump
|
33
|
+
raise "Need #{shell} version ~> #{minimum}" unless version >= minimum and version < bumped
|
34
|
+
# need to only check once
|
35
|
+
SHELL_VERSION[shell] = nil
|
36
|
+
else
|
37
|
+
raise "Could not get the #{shell} version"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
return Rubbish.shell(shell.to_s, *args, &block)
|
41
|
+
end
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
5
45
|
|
6
46
|
# Requires:
|
7
47
|
#`ruby`
|
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: 0.1.191210
|
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: 2019-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
A ruby-ish way to go to the shell.
|
@@ -17,23 +17,16 @@ description: |
|
|
17
17
|
email: carlosjhr64@gmail.com
|
18
18
|
executables: []
|
19
19
|
extensions: []
|
20
|
-
extra_rdoc_files:
|
21
|
-
- README.rdoc
|
20
|
+
extra_rdoc_files: []
|
22
21
|
files:
|
23
|
-
- README.
|
22
|
+
- README.md
|
24
23
|
- lib/rubbish.rb
|
25
|
-
- lib/rubbish/bash.rb
|
26
|
-
- lib/rubbish/fish.rb
|
27
|
-
- lib/rubbish/rubbish.rb
|
28
|
-
- lib/rubbish/version.rb
|
29
24
|
homepage: https://github.com/carlosjhr64/rubbish
|
30
25
|
licenses:
|
31
26
|
- MIT
|
32
27
|
metadata: {}
|
33
28
|
post_install_message:
|
34
|
-
rdoc_options:
|
35
|
-
- "--main"
|
36
|
-
- README.rdoc
|
29
|
+
rdoc_options: []
|
37
30
|
require_paths:
|
38
31
|
- lib
|
39
32
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -47,11 +40,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
40
|
- !ruby/object:Gem::Version
|
48
41
|
version: '0'
|
49
42
|
requirements:
|
50
|
-
- 'ruby: ruby 2.
|
51
|
-
- 'bash: GNU bash, version
|
52
|
-
- 'fish:
|
53
|
-
|
54
|
-
rubygems_version: 2.4.5.1
|
43
|
+
- 'ruby: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]'
|
44
|
+
- 'bash: GNU bash, version 5.0.11(1)-release (x86_64-redhat-linux-gnu)'
|
45
|
+
- 'fish: fish, version 3.0.2'
|
46
|
+
rubygems_version: 3.0.3
|
55
47
|
signing_key:
|
56
48
|
specification_version: 4
|
57
49
|
summary: A ruby-ish way to go to the shell.
|
data/lib/rubbish/bash.rb
DELETED
data/lib/rubbish/fish.rb
DELETED
data/lib/rubbish/rubbish.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module Rubbish
|
2
|
-
|
3
|
-
def self.shell(sh, a=nil, b=nil, &block)
|
4
|
-
script = [a,b].detect{|c|c.kind_of?(String)}
|
5
|
-
read = [a,b].detect{|c|c==true||c==false}
|
6
|
-
read = true if read.nil?
|
7
|
-
IO.popen(sh, (read)? 'w+' : 'w') do |psh|
|
8
|
-
# No matter what, we know we're going to write first.
|
9
|
-
writing = true
|
10
|
-
if script.class == String
|
11
|
-
# We were given the script, so we write it and close.
|
12
|
-
psh.write script
|
13
|
-
psh.close_write
|
14
|
-
writing = false
|
15
|
-
end
|
16
|
-
if block
|
17
|
-
block.call(psh)
|
18
|
-
# close if we were writing
|
19
|
-
psh.close_write if writing
|
20
|
-
end
|
21
|
-
# Read if reading
|
22
|
-
read = psh.read if read
|
23
|
-
end
|
24
|
-
read || $?.to_i==0
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
data/lib/rubbish/version.rb
DELETED