terminitor 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +30 -5
- data/Termfile +4 -8
- data/lib/terminitor.rb +3 -0
- data/lib/terminitor/abstract_capture.rb +1 -1
- data/lib/terminitor/abstract_core.rb +5 -3
- data/lib/terminitor/cores/mac_core.rb +2 -1
- data/lib/terminitor/dsl.rb +12 -5
- data/lib/terminitor/version.rb +1 -1
- data/test/abstract_capture_test.rb +9 -16
- data/test/abstract_core_test.rb +33 -0
- data/test/cores/mac_core_test.rb +1 -1
- data/test/dsl_test.rb +3 -1
- data/test/fixtures/bar.term +4 -2
- data/test/teststrap.rb +16 -20
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -9,6 +9,29 @@ Installation
|
|
9
9
|
$ gem install terminitor
|
10
10
|
$ terminitor init
|
11
11
|
|
12
|
+
Development Setup
|
13
|
+
---------------------
|
14
|
+
|
15
|
+
To begin development on Terminitor, run bundler:
|
16
|
+
|
17
|
+
$ gem install bundler
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
The test suite uses ([Riot](https://www.github.com/thumblemonks/riot/)).
|
21
|
+
to run the test run:
|
22
|
+
|
23
|
+
$ rake test
|
24
|
+
|
25
|
+
or use watchr:
|
26
|
+
|
27
|
+
$ watchr test.watchr
|
28
|
+
|
29
|
+
or if you have terminitor installed,
|
30
|
+
|
31
|
+
$ terminitor fetch achiu terminitor
|
32
|
+
|
33
|
+
this will git clone the repo and bundle install.
|
34
|
+
|
12
35
|
Usage
|
13
36
|
-------
|
14
37
|
|
@@ -30,7 +53,7 @@ This will open your default editor (set through the $TERM_EDITOR or $EDITOR vari
|
|
30
53
|
- cd ~/foo/bar
|
31
54
|
- gitx
|
32
55
|
- tab2:
|
33
|
-
- mysql -u root
|
56
|
+
- mysql -u root)
|
34
57
|
- use test;
|
35
58
|
- show tables;
|
36
59
|
- tab3: echo "hello world"
|
@@ -306,10 +329,12 @@ Contributors
|
|
306
329
|
|
307
330
|
Thanks to the following people for their contributions so far:
|
308
331
|
|
309
|
-
* Pat George
|
310
|
-
* Flavio Castelli ([flavio](
|
311
|
-
* Alexey Kuleshov ([kulesa](
|
312
|
-
|
332
|
+
* Pat George ([pcg79](https://github.com/pcg79)) for contributing a patch for when a project is not found.
|
333
|
+
* Flavio Castelli ([flavio](https://github.com/flavio)) for contributing Konsole(KDE) core.
|
334
|
+
* Alexey Kuleshov ([kulesa](https://github.com/kulesa)) for contributing the terminal settings and terminal settings capture functionality
|
335
|
+
* Arthur Gunn ([gunn](https://github.com/gunn)) for contributing a path to support tab syntax and load path.
|
336
|
+
* Elliot Winkler ([mcmire](https://github.com/mcmire)) for adding 1.8.6 compatiblity and ensuring tabs open in order.
|
337
|
+
|
313
338
|
Acknowledgements
|
314
339
|
-----------------
|
315
340
|
|
data/Termfile
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
# Terminitor Termfile
|
2
2
|
|
3
|
-
setup
|
4
|
-
run 'bundle install'
|
5
|
-
end
|
3
|
+
setup 'bundle install'
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
tab "open 'http://www.github.com/achiu/terminitor/issues'"
|
11
|
-
end
|
5
|
+
run 'watchr test.watchr'
|
6
|
+
tab "irb"
|
7
|
+
tab "open 'http://www.github.com/achiu/terminitor/issues'"
|
data/lib/terminitor.rb
CHANGED
@@ -29,15 +29,17 @@ module Terminitor
|
|
29
29
|
def run_in_window(window_name, window_content, options = {})
|
30
30
|
window_options = window_content[:options]
|
31
31
|
first_tab = true
|
32
|
-
window_content[:tabs].
|
32
|
+
window_content[:tabs].keys.sort.each do |tab_key|
|
33
|
+
tab_content = window_content[:tabs][tab_key]
|
33
34
|
# Open window on first 'tab' statement
|
34
35
|
# first tab is already opened in the new window, so first tab should be
|
35
36
|
# opened as a new tab in default window only
|
36
37
|
tab_options = tab_content[:options]
|
37
38
|
tab_name = tab_options[:name] if tab_options
|
38
39
|
if first_tab && !options[:default]
|
39
|
-
first_tab = false
|
40
|
-
|
40
|
+
first_tab = false
|
41
|
+
combined_options = (window_options.to_a + tab_options.to_a).inject([]) {|arr, pair| arr += pair }
|
42
|
+
window_options = Hash[*combined_options] # safe merge
|
41
43
|
tab = window_options.empty? ? open_window(nil) : open_window(window_options)
|
42
44
|
else
|
43
45
|
tab = ( tab_key == 'default' ? active_window : open_tab(tab_options) ) # give us the current window if its default, else open a tab.
|
@@ -128,7 +128,8 @@ module Terminitor
|
|
128
128
|
|
129
129
|
# selects options allowed for window or tab
|
130
130
|
def allowed_options(object_type, options)
|
131
|
-
|
131
|
+
pairs = options.select {|option, value| ALLOWED_OPTIONS[object_type].include?(option) }.inject([]) {|arr, pair| arr += pair }
|
132
|
+
Hash[*pairs]
|
132
133
|
end
|
133
134
|
|
134
135
|
# Add option to the list of delayed options
|
data/lib/terminitor/dsl.rb
CHANGED
@@ -34,12 +34,13 @@ module Terminitor
|
|
34
34
|
|
35
35
|
# stores command in context
|
36
36
|
# run 'brew update'
|
37
|
-
def run(
|
37
|
+
def run(*commands)
|
38
38
|
if @_context.is_a?(Hash) && @_context[:tabs] # if we are in a window context, append commands to default tab.
|
39
|
-
@_context[:tabs]['default'][:commands]
|
39
|
+
current = @_context[:tabs]['default'][:commands]
|
40
40
|
else
|
41
|
-
@_context
|
41
|
+
current = @_context
|
42
42
|
end
|
43
|
+
current << commands.join(" && ")
|
43
44
|
end
|
44
45
|
|
45
46
|
# runs commands before each tab in window context
|
@@ -58,15 +59,21 @@ module Terminitor
|
|
58
59
|
# sets command context to be run inside specific tab
|
59
60
|
# tab(:name => 'new tab', :settings => 'Grass') { run 'mate .' }
|
60
61
|
# tab 'ls', 'gitx'
|
61
|
-
def tab(
|
62
|
+
def tab(*args, &block)
|
62
63
|
tabs = @_context[:tabs]
|
63
64
|
tab_name = "tab#{tabs.keys.size}"
|
64
65
|
if block_given?
|
65
66
|
tab_contents = tabs[tab_name] = {:commands => []}
|
67
|
+
|
68
|
+
options = {}
|
69
|
+
options = args.pop if args.last.is_a? Hash
|
70
|
+
options[:name] = args.first if args.first.is_a?(String) || args.first.is_a?(Symbol)
|
71
|
+
|
66
72
|
tab_contents[:options] = options unless options.empty?
|
73
|
+
|
67
74
|
in_context tab_contents[:commands], &block
|
68
75
|
else
|
69
|
-
tabs[tab_name] = { :commands =>
|
76
|
+
tabs[tab_name] = { :commands => args}
|
70
77
|
end
|
71
78
|
end
|
72
79
|
|
data/lib/terminitor/version.rb
CHANGED
@@ -17,20 +17,13 @@ context "AbstractCapture" do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
setup { @capture.capture_settings() }
|
20
|
-
asserts_topic.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
tab :settings => "Yello" do
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
OUTPUT
|
34
|
-
|
20
|
+
asserts_topic.matches %r{window .* do}
|
21
|
+
asserts_topic.matches %r{tab .* do\s+end}
|
22
|
+
asserts_topic.matches %r{\:name \=\> "main window"}
|
23
|
+
asserts_topic.matches %r{\:size \=\> \[10\, 20\]}
|
24
|
+
asserts_topic.matches %r{\:settings \=\> "Grass"}
|
25
|
+
asserts_topic.matches %r{\:name \=\> "another window"}
|
26
|
+
asserts_topic.matches %r{\:size \=\> \[14, 30\]}
|
27
|
+
asserts_topic.matches %r{\:settings \=\> "Yello"}
|
35
28
|
end
|
36
|
-
end
|
29
|
+
end
|
data/test/abstract_core_test.rb
CHANGED
@@ -164,6 +164,39 @@ context "AbstractCore" do
|
|
164
164
|
core.process!
|
165
165
|
end
|
166
166
|
end
|
167
|
+
|
168
|
+
should "execute tabs in order" do
|
169
|
+
any_instance_of(Terminitor::AbstractCore) do |core|
|
170
|
+
stub(core).load_termfile('/path/to') {
|
171
|
+
{:windows => {'default' => {:tabs => {'tab1' => {:commands => ['ls']},
|
172
|
+
'tab2' => {:commands => ['ps']},
|
173
|
+
'tab3' => {:commands => ['whoami']},
|
174
|
+
'tab4' => {:commands => ['cd']},
|
175
|
+
'tab5' => {:commands => ['clear']},
|
176
|
+
'tab6' => {:commands => ['nmap']}}
|
177
|
+
}
|
178
|
+
}
|
179
|
+
}
|
180
|
+
}
|
181
|
+
end
|
182
|
+
stub(Dir).pwd { nil }
|
183
|
+
core = Terminitor::AbstractCore.new('/path/to')
|
184
|
+
|
185
|
+
mock(core).
|
186
|
+
open_tab(nil) { "first" }.then.
|
187
|
+
execute_command('ls', :in => "first").then.
|
188
|
+
open_tab(nil) { "second" }.then.
|
189
|
+
execute_command('ps', :in => "second").then.
|
190
|
+
open_tab(nil) { "third" }.then.
|
191
|
+
execute_command('whoami', :in => "third").then.
|
192
|
+
open_tab(nil) { "fourth" }.then.
|
193
|
+
execute_command('cd', :in => "fourth").then.
|
194
|
+
open_tab(nil) { "fifth" }.then.
|
195
|
+
execute_command('clear', :in => "fifth").then.
|
196
|
+
open_tab(nil) { "sixth" }.then.
|
197
|
+
execute_command('nmap', :in => "sixth")
|
198
|
+
core.process!
|
199
|
+
end
|
167
200
|
end
|
168
201
|
|
169
202
|
|
data/test/cores/mac_core_test.rb
CHANGED
@@ -81,7 +81,7 @@ if platform?("darwin") # Only run test if it's darwin
|
|
81
81
|
|
82
82
|
context "set_options" do
|
83
83
|
setup do
|
84
|
-
@object, @terminal, @windows= 3
|
84
|
+
@object, @terminal, @windows = Array.new(3) { Object.new }
|
85
85
|
stub(@terminal).windows { @windows }
|
86
86
|
any_instance_of(Terminitor::MacCore) do |core|
|
87
87
|
stub(core).app('Terminal') { @terminal }
|
data/test/dsl_test.rb
CHANGED
@@ -16,7 +16,9 @@ context "Dsl" do
|
|
16
16
|
"tab1"=>{:commands=>["echo 'first tab'", "echo 'of window'", "echo 'than now'"]},
|
17
17
|
"tab3"=>{:commands=>["top"],
|
18
18
|
:options =>{:name => "a tab", :settings => "Pro"}},
|
19
|
-
"
|
19
|
+
"tab4"=>{:commands=>["ls"],
|
20
|
+
:options =>{:name => "another named tab", :settings => "Grass"}},
|
21
|
+
"default"=>{:commands=>['whoami && who && ls']}
|
20
22
|
},
|
21
23
|
:before => ['cd /path'],
|
22
24
|
:options => {:size=>[70,30]}},
|
data/test/fixtures/bar.term
CHANGED
@@ -9,7 +9,7 @@ window :size => [70,30] do
|
|
9
9
|
|
10
10
|
before 'cd /path'
|
11
11
|
|
12
|
-
run "whoami"
|
12
|
+
run "whoami","who", "ls"
|
13
13
|
tab "echo 'first tab'", "echo 'of window'", "echo 'than now'"
|
14
14
|
|
15
15
|
tab :name => "named tab", :settings => "Grass" do
|
@@ -17,9 +17,11 @@ window :size => [70,30] do
|
|
17
17
|
run "ls"
|
18
18
|
end
|
19
19
|
|
20
|
-
tab
|
20
|
+
tab "a tab", :settings => "Pro" do
|
21
21
|
run "top"
|
22
22
|
end
|
23
|
+
|
24
|
+
tab("another named tab", :settings => 'Grass') { run "ls" }
|
23
25
|
end
|
24
26
|
|
25
27
|
window :name => 'server' do
|
data/test/teststrap.rb
CHANGED
@@ -18,32 +18,28 @@ end
|
|
18
18
|
|
19
19
|
module Kernel
|
20
20
|
def capture(stream)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
ensure
|
27
|
-
eval("$#{stream} = #{stream.upcase}")
|
28
|
-
end
|
29
|
-
result
|
21
|
+
eval "$#{stream} = StringIO.new"
|
22
|
+
yield
|
23
|
+
eval("$#{stream}").string
|
24
|
+
ensure
|
25
|
+
eval("$#{stream} = #{stream.to_s.upcase}")
|
30
26
|
end
|
31
27
|
end
|
32
28
|
|
33
29
|
# This is to silence the 'task' warning for the mocks.
|
34
30
|
class Thor
|
35
31
|
class << self
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
32
|
+
def create_task(meth) #:nodoc:
|
33
|
+
if @usage && @desc
|
34
|
+
base_class = @hide ? Thor::HiddenTask : Thor::Task
|
35
|
+
tasks[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)
|
36
|
+
@usage, @desc, @long_desc, @method_options, @hide = nil
|
37
|
+
true
|
38
|
+
elsif self.all_tasks[meth] || meth == "method_missing"
|
39
|
+
true
|
40
|
+
else
|
41
|
+
false
|
47
42
|
end
|
43
|
+
end
|
48
44
|
end
|
49
45
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Arthur Chiu
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-11 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|