mux 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +31 -0
- data/bin/mux +34 -0
- data/lib/mux.rb +123 -0
- metadata +48 -0
data/README
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
mux - tee(1) on crack.
|
2
|
+
|
3
|
+
mux is a multiplexing analogue of the output redirection operators provided
|
4
|
+
by /bin/sh on UNIX-like systems (>, >>, and |). Any number of pipes, funnels,
|
5
|
+
and appends can be opened in a single run, with stdin optionally being sent
|
6
|
+
to stdout as well.
|
7
|
+
|
8
|
+
Author: Jerome Harrington <jharrington@awk-fu.com>
|
9
|
+
Homepage: http://www.awk-fu.com/software/mux
|
10
|
+
|
11
|
+
mux is made available under the MIT License.
|
12
|
+
|
13
|
+
Copyright (c) 2006 Jerome Harrington <jharrington@awk-fu.com>
|
14
|
+
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
16
|
+
of this software and associated documentation files (the "Software"), to deal
|
17
|
+
in the Software without restriction, including without limitation the rights
|
18
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
19
|
+
copies of the Software, and to permit persons to whom the Software is
|
20
|
+
furnished to do so, subject to the following conditions:
|
21
|
+
|
22
|
+
The above copyright notice and this permission notice shall be included in
|
23
|
+
all copies or substantial portions of the Software.
|
24
|
+
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
31
|
+
SOFTWARE.
|
data/bin/mux
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# mux - tee(1) on crack
|
4
|
+
# mux is a multiplexing analogue of the output redirection operators provided
|
5
|
+
# by /bin/sh on UNIX-like systems (>, >>, and |). Any number of pipes, funnels,
|
6
|
+
# and appends can be opened in a single run, with stdin optionally being sent
|
7
|
+
# to stdout as well.
|
8
|
+
#
|
9
|
+
# Author: Jerome Harrington <jharrington@awk-fu.com>
|
10
|
+
# Homepage: http://www.awk-fu.com/software/mux
|
11
|
+
#
|
12
|
+
# Copyright (c) 2006 Jerome Harrington <jharrington@awk-fu.com>
|
13
|
+
#
|
14
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
15
|
+
# of this software and associated documentation files (the "Software"), to deal
|
16
|
+
# in the Software without restriction, including without limitation the rights
|
17
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
18
|
+
# copies of the Software, and to permit persons to whom the Software is
|
19
|
+
# furnished to do so, subject to the following conditions:
|
20
|
+
#
|
21
|
+
# The above copyright notice and this permission notice shall be included in
|
22
|
+
# all copies or substantial portions of the Software.
|
23
|
+
#
|
24
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
25
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
26
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
27
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
28
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
29
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
30
|
+
# SOFTWARE.
|
31
|
+
require 'rubygems'
|
32
|
+
require 'mux'
|
33
|
+
|
34
|
+
Mux.run(ARGV)
|
data/lib/mux.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# mux - tee(1) on crack
|
2
|
+
# mux is a multiplexing analogue of the output redirection operators provided
|
3
|
+
# by /bin/sh on UNIX-like systems (>, >>, and |). Any number of pipes, funnels,
|
4
|
+
# and appends can be opened in a single run, with stdin optionally being sent
|
5
|
+
# to stdout as well.
|
6
|
+
#
|
7
|
+
# Author: Jerome Harrington <jharrington@awk-fu.com>
|
8
|
+
# Homepage: http://www.awk-fu.com/software/mux
|
9
|
+
#
|
10
|
+
# Copyright (c) 2006 Jerome Harrington <jharrington@awk-fu.com>
|
11
|
+
#
|
12
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
13
|
+
# of this software and associated documentation files (the "Software"), to deal
|
14
|
+
# in the Software without restriction, including without limitation the rights
|
15
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
16
|
+
# copies of the Software, and to permit persons to whom the Software is
|
17
|
+
# furnished to do so, subject to the following conditions:
|
18
|
+
#
|
19
|
+
# The above copyright notice and this permission notice shall be included in
|
20
|
+
# all copies or substantial portions of the Software.
|
21
|
+
#
|
22
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
23
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
24
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
25
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
26
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
27
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
28
|
+
# SOFTWARE.
|
29
|
+
|
30
|
+
require 'optparse'
|
31
|
+
require 'ostruct'
|
32
|
+
|
33
|
+
class Mux
|
34
|
+
def self.run(args)
|
35
|
+
options = Mux::Options.parse(args)
|
36
|
+
|
37
|
+
streams = []
|
38
|
+
|
39
|
+
if options.to_stdout
|
40
|
+
streams << $stdout
|
41
|
+
end
|
42
|
+
|
43
|
+
streams.concat(open_streams(options.pipes, 'pipe'))
|
44
|
+
streams.concat(open_streams(options.funnels, 'funnel'))
|
45
|
+
streams.concat(open_streams(options.appends, 'append'))
|
46
|
+
|
47
|
+
while buffer = $stdin.gets
|
48
|
+
streams.each do |stream|
|
49
|
+
stream.puts buffer
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
streams.each do |stream|
|
54
|
+
stream.close
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.open_streams(targets, type)
|
60
|
+
handles = []
|
61
|
+
targets.each do |target|
|
62
|
+
case type
|
63
|
+
when 'pipe'
|
64
|
+
handles << IO.popen(target, 'w')
|
65
|
+
when 'funnel'
|
66
|
+
handles << File.open(target, 'w')
|
67
|
+
when 'append'
|
68
|
+
handles << File.open(target, 'a')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
handles
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
class Mux::Options
|
77
|
+
def self.parse(args)
|
78
|
+
options = OpenStruct.new
|
79
|
+
options.verbose = false
|
80
|
+
options.to_stdout = false
|
81
|
+
options.pipes = []
|
82
|
+
options.appends = []
|
83
|
+
options.funnels = []
|
84
|
+
|
85
|
+
opts = OptionParser.new do |opts|
|
86
|
+
opts.banner = "Usage: mux [options]"
|
87
|
+
|
88
|
+
opts.separator ""
|
89
|
+
opts.separator "General options:"
|
90
|
+
|
91
|
+
opts.on("-s", "Pass stdin to stdout (like tee)") do |s|
|
92
|
+
options.to_stdout = true
|
93
|
+
end
|
94
|
+
|
95
|
+
opts.on("-h", "Show this help message") do
|
96
|
+
puts opts
|
97
|
+
exit
|
98
|
+
end
|
99
|
+
|
100
|
+
opts.separator ""
|
101
|
+
opts.separator "Target specification options:"
|
102
|
+
|
103
|
+
opts.on("-p target1,target2...targetN", Array,
|
104
|
+
"List of processes to pipe to") do |pipes|
|
105
|
+
options.pipes = pipes
|
106
|
+
end
|
107
|
+
|
108
|
+
opts.on("-f target1,target2...targetN", Array,
|
109
|
+
"List of files to funnel to") do |funnels|
|
110
|
+
options.funnels = funnels
|
111
|
+
end
|
112
|
+
|
113
|
+
opts.on("-a target1,target2...targetN", Array,
|
114
|
+
"List of files to append to") do |appends|
|
115
|
+
options.appends = appends
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
opts.parse!(args)
|
121
|
+
options
|
122
|
+
end
|
123
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: mux
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2006-11-05 00:00:00 -05:00
|
8
|
+
summary: tee(1) on crack
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: jharrington@awk-fu.com
|
12
|
+
homepage: http://www.awk-fu.com/software/mux
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: mux
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Jerome Harrington
|
31
|
+
files:
|
32
|
+
- bin/mux
|
33
|
+
- lib/mux.rb
|
34
|
+
- README
|
35
|
+
test_files: []
|
36
|
+
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
extra_rdoc_files: []
|
40
|
+
|
41
|
+
executables:
|
42
|
+
- mux
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
requirements: []
|
46
|
+
|
47
|
+
dependencies: []
|
48
|
+
|