open_terms 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.travis.yml +1 -0
- data/Gemfile +2 -0
- data/README.md +2 -2
- data/Rakefile +9 -0
- data/lib/open_terms/osx_terminal.rb +4 -37
- data/lib/open_terms/version.rb +1 -1
- data/open_terms.gemspec +1 -1
- data/spec/appscript.rb +9 -0
- data/spec/open_terms/gnome_terminal_spec.rb +47 -0
- data/spec/open_terms/osx_iterm_spec.rb +33 -0
- data/spec/open_terms/osx_terminal_spec.rb +33 -0
- data/spec/spec_helper.rb +14 -0
- metadata +27 -4
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm: 1.9.2
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -14,7 +14,7 @@ To use on a Rails project, add these two lines on your Gemfile:
|
|
14
14
|
|
15
15
|
```ruby
|
16
16
|
gem 'open_terms'
|
17
|
-
gem 'rb-appscript'
|
17
|
+
gem 'rb-appscript' if RUBY_PLATFORM =~ /darwin/
|
18
18
|
```
|
19
19
|
|
20
20
|
Now you can run:
|
@@ -27,7 +27,7 @@ If you want to run it without Rake:
|
|
27
27
|
|
28
28
|
```ruby
|
29
29
|
require 'open_terms'
|
30
|
-
require 'appscript' if RUBY_PLATFORM =~ /darwin/
|
30
|
+
require 'rb-appscript' if RUBY_PLATFORM =~ /darwin/
|
31
31
|
OpenTerms.rails_defaults
|
32
32
|
```
|
33
33
|
|
data/Rakefile
CHANGED
@@ -5,61 +5,28 @@ module OpenTerms
|
|
5
5
|
require 'appscript'
|
6
6
|
extend Appscript
|
7
7
|
@term = app('Terminal')
|
8
|
-
|
9
|
-
@set_titles = (@term.version.get.to_f < 2.1) && tab.properties.include?("custom_title")
|
8
|
+
@term.activate
|
10
9
|
end
|
11
10
|
|
12
11
|
def open commands
|
13
12
|
run commands
|
14
|
-
#set_tab_titles commands
|
15
|
-
@term.windows.first.tabs.first.selected.set true
|
16
13
|
end
|
17
14
|
|
18
15
|
protected
|
19
16
|
|
20
17
|
def run commands
|
21
|
-
commands.each do |command|
|
22
|
-
if command.class == Array
|
23
|
-
(title, command) = command
|
24
|
-
else
|
25
|
-
title = command
|
26
|
-
end
|
18
|
+
commands.each do |title,command|
|
27
19
|
tab = make_tab title
|
28
|
-
@term.do_script(
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def set_tab_titles titles
|
33
|
-
tabs = @term.windows.first.tabs.get
|
34
|
-
offset = tabs.length - titles.length
|
35
|
-
titles.each_with_index do |title, i|
|
36
|
-
tabs[i+offset].selected.set true
|
37
|
-
set_selected_tab_title title
|
20
|
+
@term.do_script(command, :in => tab)
|
38
21
|
end
|
39
22
|
end
|
40
23
|
|
41
|
-
def from_project_root(cmd)
|
42
|
-
"cd #{Dir.pwd} && #{cmd}"
|
43
|
-
end
|
44
|
-
|
45
|
-
def make_window
|
46
|
-
@term.activate
|
47
|
-
app("System Events").application_processes[ "Terminal.app" ].keystroke("n", :using => :command_down)
|
48
|
-
end
|
49
|
-
|
50
24
|
def make_tab(title=nil)
|
51
25
|
@term.activate app("System Events").application_processes[ "Terminal.app" ].keystroke("t", :using => :command_down)
|
52
26
|
tab = @term.windows.first.tabs.last
|
53
|
-
tab.
|
54
|
-
set_selected_tab_title title if @set_titles && title
|
27
|
+
tab.custom_title.set title
|
55
28
|
tab
|
56
29
|
end
|
57
30
|
|
58
|
-
def set_selected_tab_title(title)
|
59
|
-
@term.activate app("System Events").application_processes[ "Terminal.app" ].keystroke("T", :using => :command_down)
|
60
|
-
@term.activate app("System Events").application_processes[ "Terminal.app" ].keystroke(title)
|
61
|
-
@term.activate app("System Events").application_processes[ "Terminal.app" ].key_code(36)
|
62
|
-
end
|
63
|
-
|
64
31
|
end
|
65
32
|
end
|
data/lib/open_terms/version.rb
CHANGED
data/open_terms.gemspec
CHANGED
data/spec/appscript.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'open_terms/gnome_terminal'
|
3
|
+
module Kernel
|
4
|
+
def `(args)
|
5
|
+
$executor.run(args)
|
6
|
+
end
|
7
|
+
def system(args)
|
8
|
+
$executor.run(args)
|
9
|
+
1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
describe OpenTerms::GnomeTerminal do
|
13
|
+
it "should get the pid for the active terminal" do
|
14
|
+
$executor = mock("kernel")
|
15
|
+
$executor.should_receive(:run).with('xdotool getactivewindow').and_return(2)
|
16
|
+
OpenTerms::GnomeTerminal.new.term_pid.should == 2
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should run commands when asked" do
|
20
|
+
commands = [
|
21
|
+
["title1", "command1"],
|
22
|
+
["title2", "command2"]
|
23
|
+
]
|
24
|
+
$executor = mock("kernel")
|
25
|
+
$executor.should_receive(:run).with('xdotool getactivewindow').and_return(2)
|
26
|
+
execs = ["xdotool windowfocus 2",
|
27
|
+
"xdotool key ctrl+shift+t",
|
28
|
+
"xdotool key ctrl+shift+alt+t",
|
29
|
+
"xdotool type title1",
|
30
|
+
"xdotool key Return",
|
31
|
+
"xdotool type command1",
|
32
|
+
"xdotool key space",
|
33
|
+
"xdotool key Return",
|
34
|
+
"xdotool windowfocus 2",
|
35
|
+
"xdotool key ctrl+shift+t",
|
36
|
+
"xdotool key ctrl+shift+alt+t",
|
37
|
+
"xdotool type title2",
|
38
|
+
"xdotool key Return",
|
39
|
+
"xdotool type command2",
|
40
|
+
"xdotool key space",
|
41
|
+
"xdotool key Return"].each do |cmd|
|
42
|
+
$executor.should_receive(:run).with(cmd)
|
43
|
+
end
|
44
|
+
automator = OpenTerms::GnomeTerminal.new
|
45
|
+
automator.open commands
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'appscript'
|
3
|
+
describe OpenTerms::OsxIterm do
|
4
|
+
it "should require appscript" do
|
5
|
+
$term_mock = mock("iTerm")
|
6
|
+
$term_mock.should_receive(:activate)
|
7
|
+
OpenTerms::OsxIterm.new
|
8
|
+
end
|
9
|
+
it "should execute commands" do
|
10
|
+
commands = [
|
11
|
+
["title1", "command1"],
|
12
|
+
["title2", "command2"]
|
13
|
+
]
|
14
|
+
$term_mock = mock("iTerm")
|
15
|
+
$term_mock.should_receive(:activate)
|
16
|
+
session_creator = mock("session_creator")
|
17
|
+
session1 = mock("session")
|
18
|
+
name_mock = mock("name")
|
19
|
+
name_mock.should_receive(:set).with("title1")
|
20
|
+
name_mock.should_receive(:set).with("title2")
|
21
|
+
session_creator.should_receive(:make).twice.with(new: :session).and_return(session1)
|
22
|
+
session1.should_receive(:name).and_return(name_mock)
|
23
|
+
session1.should_receive(:exec).with(:command => "/bin/bash -l")
|
24
|
+
session1.should_receive(:write).with(:text => "command1")
|
25
|
+
session1.should_receive(:name).and_return(name_mock)
|
26
|
+
session1.should_receive(:exec).with(:command => "/bin/bash -l")
|
27
|
+
session1.should_receive(:write).with(:text => "command2")
|
28
|
+
session_array = [session_creator, session_creator]
|
29
|
+
$term_mock.should_receive(:terminals).twice.and_return(session_array)
|
30
|
+
automator = OpenTerms::OsxIterm.new
|
31
|
+
automator.open commands
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'appscript'
|
3
|
+
describe OpenTerms::OsxTerminal do
|
4
|
+
it "should require appscript" do
|
5
|
+
$term_mock = mock("Terminal")
|
6
|
+
$term_mock.should_receive(:activate)
|
7
|
+
OpenTerms::OsxIterm.new
|
8
|
+
end
|
9
|
+
it "should execute commands" do
|
10
|
+
commands = [
|
11
|
+
["title1", "command1"],
|
12
|
+
["title2", "command2"]
|
13
|
+
]
|
14
|
+
$term_mock = mock("Terminal")
|
15
|
+
$system_mock = mock("System Events")
|
16
|
+
$term_mock.should_receive :activate
|
17
|
+
commands.each do |title,command|
|
18
|
+
$term_mock.should_receive :activate
|
19
|
+
$system_mock.should_receive(:application_processes).and_return({"Terminal.app" => $term_mock})
|
20
|
+
$term_mock.should_receive(:keystroke).with("t", using: :command_down)
|
21
|
+
tab = mock("tab #{title}")
|
22
|
+
$term_mock.should_receive(:windows).and_return($term_mock)
|
23
|
+
$term_mock.should_receive(:first).and_return($term_mock)
|
24
|
+
$term_mock.should_receive(:tabs).and_return($term_mock)
|
25
|
+
$term_mock.should_receive(:last).and_return(tab)
|
26
|
+
tab.should_receive(:custom_title).and_return(tab)
|
27
|
+
tab.should_receive(:set).with(title)
|
28
|
+
$term_mock.should_receive(:do_script).with(command, in: tab)
|
29
|
+
end
|
30
|
+
automator = OpenTerms::OsxTerminal.new
|
31
|
+
automator.open commands
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rspec/autorun'
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start do
|
6
|
+
add_filter "/spec/"
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'open_terms' # and any other gems you need
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
# some (optional) config here
|
13
|
+
end
|
14
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_terms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
13
|
-
dependencies:
|
12
|
+
date: 2011-12-23 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70329381258340 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70329381258340
|
14
25
|
description: Easy way to open many terminals for OSX and Linux
|
15
26
|
email:
|
16
27
|
- rodrigo@urubatan.com.br
|
@@ -19,6 +30,8 @@ extensions: []
|
|
19
30
|
extra_rdoc_files: []
|
20
31
|
files:
|
21
32
|
- .gitignore
|
33
|
+
- .rspec
|
34
|
+
- .travis.yml
|
22
35
|
- Gemfile
|
23
36
|
- README.md
|
24
37
|
- Rakefile
|
@@ -30,6 +43,11 @@ files:
|
|
30
43
|
- lib/open_terms/version.rb
|
31
44
|
- lib/rake/open_terms.rake
|
32
45
|
- open_terms.gemspec
|
46
|
+
- spec/appscript.rb
|
47
|
+
- spec/open_terms/gnome_terminal_spec.rb
|
48
|
+
- spec/open_terms/osx_iterm_spec.rb
|
49
|
+
- spec/open_terms/osx_terminal_spec.rb
|
50
|
+
- spec/spec_helper.rb
|
33
51
|
homepage: http://www.urubatan.com.br
|
34
52
|
licenses: []
|
35
53
|
post_install_message:
|
@@ -54,4 +72,9 @@ rubygems_version: 1.8.10
|
|
54
72
|
signing_key:
|
55
73
|
specification_version: 3
|
56
74
|
summary: Easy way to open many terminal windows for OSX and Linux
|
57
|
-
test_files:
|
75
|
+
test_files:
|
76
|
+
- spec/appscript.rb
|
77
|
+
- spec/open_terms/gnome_terminal_spec.rb
|
78
|
+
- spec/open_terms/osx_iterm_spec.rb
|
79
|
+
- spec/open_terms/osx_terminal_spec.rb
|
80
|
+
- spec/spec_helper.rb
|