easy-screen 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.md +54 -0
- data/Rakefile +46 -0
- data/example/exec_command.rb +13 -0
- data/example/open_windows.rb +13 -0
- data/lib/screen.rb +10 -0
- data/lib/screen/session.rb +29 -0
- data/lib/screen/window.rb +55 -0
- data/spec/session_spec.rb +80 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/window_spec.rb +95 -0
- metadata +98 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 tily
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
EasyScreen
|
2
|
+
======
|
3
|
+
|
4
|
+
Usage
|
5
|
+
-------
|
6
|
+
|
7
|
+
### Open Several Windows
|
8
|
+
|
9
|
+
Screen('Beatles') {
|
10
|
+
['John', 'Paul', 'George', 'Ringo'].each {|member|
|
11
|
+
window(member)
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
ends up like this:
|
16
|
+
|
17
|
+
<img src="http://gyazo.com/a61076d8a6035ea8ed51dd3cc6a7fe13.png" />
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
### Execute Commands for each Window
|
22
|
+
|
23
|
+
Screen('admin') {
|
24
|
+
window('vi') { exec 'vi' }
|
25
|
+
window('top') { exec 'top' }
|
26
|
+
window('tail') { exec 'tail -f /var/log/apache2/error_log' }
|
27
|
+
}
|
28
|
+
|
29
|
+
ends up like this:
|
30
|
+
|
31
|
+
<img src="http://gyazo.com/88d2bf51e72307c33a7b189faf65ebaf.png" />
|
32
|
+
|
33
|
+
Install
|
34
|
+
-------
|
35
|
+
|
36
|
+
gem install screen
|
37
|
+
|
38
|
+
|
39
|
+
Requirements
|
40
|
+
-------
|
41
|
+
|
42
|
+
* ruby 1.8.7 or later
|
43
|
+
* GNU screen
|
44
|
+
|
45
|
+
Links
|
46
|
+
-------
|
47
|
+
|
48
|
+
* Inspired by: [Scripting Screen](http://blog.lathi.net/articles/2008/09/13/scripting-screen)
|
49
|
+
* See also: [RubyScreen](http://ruby-screen.rubyforge.org/), [Screeninator](http://github.com/jondruse/screeninator)
|
50
|
+
* Source code: [http://github.com/tily/ruby-screen](http://github.com/tily/ruby-screen)
|
51
|
+
|
52
|
+
Copyright
|
53
|
+
-------
|
54
|
+
Copyright (c) 2010 tily. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "easy-screen"
|
8
|
+
gem.summary = %Q{easy screen scripting}
|
9
|
+
gem.description = %Q{easy screen scripting}
|
10
|
+
gem.email = "tily05@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/tily/ruby-screen"
|
12
|
+
gem.authors = ["tily"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
spec.rcov_opts = ["--gcc"]
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "easy-screen #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
# exec command sample
|
5
|
+
|
6
|
+
require 'screen'
|
7
|
+
|
8
|
+
Screen('admin') {
|
9
|
+
window('vi') { exec 'vi' }
|
10
|
+
window('top') { exec 'top' }
|
11
|
+
window('tail') { exec 'tail -f /var/log/apache2/error_log' }
|
12
|
+
}
|
13
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
# just open four new windows and set name to each
|
5
|
+
|
6
|
+
require 'screen'
|
7
|
+
|
8
|
+
Screen('Beatles') {
|
9
|
+
['John', 'Paul', 'George', 'Ringo'].each {|member|
|
10
|
+
window(member)
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
data/lib/screen.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
module Screen
|
3
|
+
|
4
|
+
class Session
|
5
|
+
|
6
|
+
def self.create(session, &block)
|
7
|
+
screen_session = new(session)
|
8
|
+
screen_session.instance_eval(&block)
|
9
|
+
Kernel.system "screen -x #{session} -p 0"
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(session)
|
13
|
+
@session = session
|
14
|
+
@first_window = true
|
15
|
+
@window_number = 0
|
16
|
+
Kernel.system "screen -d -m -S #{@session}\n"
|
17
|
+
end
|
18
|
+
|
19
|
+
def window(window="w#{@window_number}", &block)
|
20
|
+
window = Window.new(window, @window_number, @session, @first_window)
|
21
|
+
window.instance_eval(&block) if block_given?
|
22
|
+
@window_number += 1
|
23
|
+
@first_window = false
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
|
2
|
+
module Screen
|
3
|
+
|
4
|
+
class Window
|
5
|
+
|
6
|
+
instance_methods.each do |method|
|
7
|
+
undef_method method unless method[/^(__|instance_eval$)/]
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(window, window_number, session, first)
|
11
|
+
@session = session
|
12
|
+
@window_number = window_number
|
13
|
+
if first
|
14
|
+
Kernel.system "screen -X -S #{@session} title #{window}"
|
15
|
+
else
|
16
|
+
Kernel.system "screen -X -S #{@session} screen -t #{window} #{@window_number}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def exec(*args)
|
21
|
+
if args.all? {|a| a.class == String }
|
22
|
+
stuffed = args
|
23
|
+
elsif args[0].class == Array and args[0].all? {|a| a.class == String }
|
24
|
+
stuffed = args[0]
|
25
|
+
else
|
26
|
+
raise ArgumentError, 'not unix command'
|
27
|
+
end
|
28
|
+
stuffed = %Q|"#{stuffed.join("\n")}\n"|
|
29
|
+
Kernel.system "screen -X -S #{@session} -p #{@window_number} stuff #{stuffed}"
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def ssh(hostname, password=nil)
|
34
|
+
stuffed = %Q|"ssh #{hostname}\r\n"|
|
35
|
+
Kernel.system "screen -X -S #{@session} -p #{@window_number} stuff #{stuffed}"
|
36
|
+
sleep 1
|
37
|
+
if(password)
|
38
|
+
stuffed = %Q|"#{password}\r\n"|
|
39
|
+
Kernel.system "screen -X -S #{@session} -p #{@window_number} stuff #{stuffed}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def method_missing(command, *args)
|
44
|
+
unix_command = "screen -X -S #{@session} -p #{@window_number} #{command}"
|
45
|
+
if !args.size.zero?
|
46
|
+
args = args.map {|a| a.class == String ? a : a.to_s }
|
47
|
+
unix_command << " #{args.join(' ')}"
|
48
|
+
end
|
49
|
+
Kernel.system unix_command
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Screen::Session do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@session_name = 'session_name'
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '.create' do
|
10
|
+
|
11
|
+
it 'create good Screen::Session object' do
|
12
|
+
expect = lambda {}
|
13
|
+
Screen::Session.should_receive(:new).once.and_return(
|
14
|
+
mock.tap {|m| m.should_receive(:instance_eval).once.with(&expect) }
|
15
|
+
)
|
16
|
+
Kernel.should_receive(:system).once.with("screen -x #{@session_name} -p 0")
|
17
|
+
|
18
|
+
Screen::Session.create(@session_name, &expect)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.new' do
|
24
|
+
|
25
|
+
it 'sets default instance variables' do
|
26
|
+
@session = Screen::Session.new(@session_name)
|
27
|
+
@session.instance_variable_get('@session').should == @session_name
|
28
|
+
@session.instance_variable_get('@first_window').should be_true
|
29
|
+
@session.instance_variable_get('@window_number').should == 0
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'and it creates detached io-enabled session with session_name' do
|
33
|
+
Kernel.should_receive(:system).once.with("screen -d -m -S #{@session_name}\n")
|
34
|
+
@session = Screen::Session.new(@session_name)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#window' do
|
40
|
+
|
41
|
+
before do
|
42
|
+
@session = Screen::Session.new(@session_name)
|
43
|
+
@window_name = 'new_window'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'when only name is given' do
|
47
|
+
Screen::Window.should_receive(:new).once.with(@window_name, 0, @session_name, true)
|
48
|
+
@session.window(@window_name)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'when only block is given' do
|
52
|
+
expect = lambda {}
|
53
|
+
Screen::Window.should_receive(:new).once.with('w0', 0, @session_name, true).and_return(
|
54
|
+
mock {|m| m.should_receive(:instance_eval).once.with(&expect) }
|
55
|
+
)
|
56
|
+
@session.window(&expect)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'when name and block are given' do
|
60
|
+
expect = lambda {}
|
61
|
+
Screen::Window.should_receive(:new).once.with(@window_name, 0, @session_name, true).and_return(
|
62
|
+
mock {|m| m.should_receive(:instance_eval).once.with(&expect) }
|
63
|
+
)
|
64
|
+
@session.window(@window_name, &expect)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'when called two times' do
|
68
|
+
Screen::Window.should_receive(:new).once.with(@window_name, 0, @session_name, true)
|
69
|
+
@session.window(@window_name)
|
70
|
+
|
71
|
+
Screen::Window.should_receive(:new).once.with(@window_name, 1, @session_name, false).and_return(
|
72
|
+
mock {|m| m.should_receive(:instance_eval).once.with(&expect) }
|
73
|
+
)
|
74
|
+
@session.window(@window_name)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-fs -color
|
data/spec/spec_helper.rb
ADDED
data/spec/window_spec.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Screen::Window do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@window_name = 'window_name'
|
7
|
+
@session_name = 'session_name'
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.new' do
|
11
|
+
|
12
|
+
it 'when called with first=true' do
|
13
|
+
Kernel.should_receive(:system).once.with("screen -X -S #{@session_name} title #{@window_name}")
|
14
|
+
Screen::Window.new(@window_name, 0, @session_name, true)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'when called with first=false' do
|
18
|
+
Kernel.should_receive(:system).once.with("screen -X -S #{@session_name} screen -t #{@window_name} 1")
|
19
|
+
Screen::Window.new(@window_name, 1, @session_name, false)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#exec' do
|
25
|
+
|
26
|
+
before do
|
27
|
+
Kernel.stub!(:system => 'stubbed')
|
28
|
+
@window_number = 1
|
29
|
+
@first_window = false
|
30
|
+
@window = Screen::Window.new(@window_name, @window_number, @session_name, @first_window)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'when called with one string' do
|
34
|
+
Kernel.should_receive(:system).with(
|
35
|
+
%Q|screen -X -S #{@session_name} -p #{@window_number} stuff "ls\n"|
|
36
|
+
)
|
37
|
+
@window.exec('ls')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'when called with array of strings' do
|
41
|
+
Kernel.should_receive(:system).with(
|
42
|
+
%Q|screen -X -S #{@session_name} -p #{@window_number} stuff "ls\nwc\n"|
|
43
|
+
)
|
44
|
+
@window.exec('ls', 'wc')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'when called with one array of strings' do
|
48
|
+
Kernel.should_receive(:system).with(
|
49
|
+
%Q|screen -X -S #{@session_name} -p #{@window_number} stuff "ls\nwc\nps\n"|
|
50
|
+
)
|
51
|
+
@window.exec(['ls', 'wc', 'ps'])
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'when called with unpredictables' do
|
55
|
+
lambda {
|
56
|
+
@window.exec(1, {}, [])
|
57
|
+
}.should raise_error(ArgumentError, 'not unix command')
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#method_missing' do
|
63
|
+
|
64
|
+
before do
|
65
|
+
Kernel.stub!(:system => 'stubbed')
|
66
|
+
@window_number = 1
|
67
|
+
@first_window = false
|
68
|
+
@window = Screen::Window.new(@window_name, @window_number, @session_name, @first_window)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'called with no args' do
|
72
|
+
Kernel.should_receive(:system).with(
|
73
|
+
%Q|screen -X -S #{@session_name} -p #{@window_number} hoge|
|
74
|
+
)
|
75
|
+
@window.method_missing('hoge')
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'called with string' do
|
79
|
+
Kernel.should_receive(:system).with(
|
80
|
+
%Q|screen -X -S #{@session_name} -p #{@window_number} hoge fuga|
|
81
|
+
)
|
82
|
+
@window.method_missing('hoge', 'fuga')
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'called with strings and numbers' do
|
86
|
+
Kernel.should_receive(:system).with(
|
87
|
+
%Q|screen -X -S #{@session_name} -p #{@window_number} hoge 1|
|
88
|
+
)
|
89
|
+
@window.method_missing('hoge', 1)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easy-screen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 0.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- tily
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-18 00:00:00 +09:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
34
|
+
version: 1.2.9
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: easy screen scripting
|
38
|
+
email: tily05@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.md
|
46
|
+
files:
|
47
|
+
- .document
|
48
|
+
- .gitignore
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- example/exec_command.rb
|
53
|
+
- example/open_windows.rb
|
54
|
+
- lib/screen.rb
|
55
|
+
- lib/screen/session.rb
|
56
|
+
- lib/screen/window.rb
|
57
|
+
- spec/session_spec.rb
|
58
|
+
- spec/spec.opts
|
59
|
+
- spec/spec_helper.rb
|
60
|
+
- spec/window_spec.rb
|
61
|
+
has_rdoc: true
|
62
|
+
homepage: http://github.com/tily/ruby-screen
|
63
|
+
licenses: []
|
64
|
+
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options:
|
67
|
+
- --charset=UTF-8
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
requirements: []
|
89
|
+
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.3.7
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: easy screen scripting
|
95
|
+
test_files:
|
96
|
+
- spec/window_spec.rb
|
97
|
+
- spec/session_spec.rb
|
98
|
+
- spec/spec_helper.rb
|