terminitor 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ *.swp
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- terminitor (0.2.1)
4
+ terminitor (0.2.2)
5
5
  github (~> 0.4.5)
6
6
  rb-appscript
7
7
  thor (~> 0.14.0)
@@ -17,15 +17,15 @@ GEM
17
17
  highline (1.5.2)
18
18
  json (1.4.6)
19
19
  rb-appscript (0.5.3)
20
- riot (0.11.4)
20
+ riot (0.12.0)
21
21
  rr
22
22
  term-ansicolor
23
- rr (1.0.0)
23
+ rr (1.0.2)
24
24
  term-ansicolor (1.0.5)
25
25
  text-format (1.0.0)
26
26
  text-hyphen (~> 1.0.0)
27
27
  text-hyphen (1.0.0)
28
- thor (0.14.4)
28
+ thor (0.14.6)
29
29
 
30
30
  PLATFORMS
31
31
  ruby
@@ -35,7 +35,7 @@ DEPENDENCIES
35
35
  fakefs
36
36
  github (~> 0.4.5)
37
37
  rb-appscript
38
- riot (~> 0.11.0)
39
- rr (= 1.0.0)
38
+ riot (~> 0.12.0)
39
+ rr (~> 1.0.0)
40
40
  terminitor!
41
41
  thor (~> 0.14.0)
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Terminitor
2
2
  ===========
3
3
 
4
- Terminitor automates your development workflow by allowing you to script the commands to run in your terminal to begin working on a given project.
4
+ Terminitor automates your development workflow setup. Less time setting up, more time getting things done.
5
5
 
6
6
  Installation
7
7
  ------------
@@ -47,16 +47,24 @@ To use the legacy syntax, you can invoke it with terminitor like so:
47
47
 
48
48
  $ terminitor edit foo --syntax yml
49
49
 
50
+ It is recommended that you move over to the newer Ruby DSL Syntax as it
51
+ provides more robust features, however terminitor will still support the older
52
+ YAML syntax.
53
+
50
54
 
51
55
  #### Ruby DSL Syntax ####
52
56
 
53
- setup 'echo "setup"'
57
+ setup 'echo "setup"' # code to run during setup
54
58
 
59
+ # open a tab in current window with these commands
55
60
  tab "echo 'default'", "echo 'default tab'"
56
61
 
57
62
  window do
58
- tab "echo 'first tab'", "echo 'of window'"
59
-
63
+ before { run 'cd /path' } # run this command before each command.
64
+
65
+ run 'padrino start' # run in new window
66
+
67
+ tab "echo 'first tab'", "echo 'of window'" # create a new tab in window and run it.
60
68
  tab "named tab" do
61
69
  run "echo 'named tab'"
62
70
  run "ls"
@@ -83,13 +91,40 @@ or even pass it a block:
83
91
  to create windows, we can simply invoke the window command with a block containing additional commands like:
84
92
 
85
93
  window do
86
- tab "echo 'hi'"
87
- tab "mate ."
88
- tab do
94
+
95
+ run "whoami" # Runs the command in the current window.
96
+
97
+ tab "echo 'hi'" # Creates another tab
98
+ tab "mate ." # And another
99
+ tab do # Last hoorah
89
100
  run "open http://www.google.com"
90
101
  end
91
102
  end
92
103
 
104
+
105
+ ##### Before #####
106
+
107
+ Sometimes you'll want to create a few commands that you want to run in each tab instance. You can do that with 'before':
108
+
109
+ before { run "cd /path" } # execute this command before other commands in the default window
110
+ run "whoami"
111
+ tab 'uptime'
112
+
113
+ # In this instance, "cd /path" wil be executed in the default window before 'whoami'
114
+ # and also in the tab before 'uptime'.
115
+ # You can also use this inside a specific window context:
116
+
117
+ window do
118
+ before 'cd /tmp'
119
+ run 'watchr test.watchr' # "cd /tmp" first than run watchr
120
+
121
+ tab do
122
+ run 'padrino start' # "cd /tmp" is ran beforehand and then padrino start is executed
123
+ end
124
+ end
125
+
126
+
127
+
93
128
  ##### Setup #####
94
129
 
95
130
  The setup block allows you to store commands that can be ran specifically before a project and can be defined with:
@@ -103,20 +138,29 @@ or with a block:
103
138
  setup do
104
139
  run "echo 'hi'"
105
140
  run "bundle install"
141
+ run 'git remote add upstream git://github.com/achiu/terminitor.git'
106
142
  end
107
143
 
108
144
 
145
+ Once defined, you can invoke your projects setup with:
146
+
147
+ terminitor setup my_project
148
+
109
149
  ##### Settings #####
150
+ _currently only available for Mac OSX Terminal_
110
151
 
111
152
  You can also set settings on each of your tabs and windows. for example, this is possible:
112
153
 
113
154
  Open a tab with terminal settings "Grass"
114
155
 
115
- tab "named tab", :settings => "Grass" do
156
+ tab :name => "named tab", :settings => "Grass" do
116
157
  run "echo 'named tab'"
117
158
  run "ls"
118
159
  end
119
160
 
161
+ This will create a tab with a title of 'named tab' using Terminals 'Grass' setting.
162
+
163
+
120
164
  How about a window with a specific size:
121
165
 
122
166
  window :bounds => [10,20,300,200] do
@@ -187,7 +231,7 @@ Now, when you or another developer clones a project, you could simply:
187
231
 
188
232
  $ git clone git://path/to/my/foo/project.git
189
233
  $ cd project
190
- $ bundle install
234
+ $ terminitor setup
191
235
  $ terminitor start
192
236
 
193
237
  This would clone the project repo, and then install all dependencies and then launch the ideal development environment for the project. Clearly
@@ -201,7 +245,7 @@ In addition, you are in the project folder and you wish to remove the Termfile,
201
245
  This will clear the `Termfile` for the particular project.
202
246
 
203
247
  ### Capturing Terminal Settings with Terminitor ###
204
-
248
+ _Currently Mac OSX Terminal only_
205
249
  Terminitor has the ability to also capture your terminal setup and settings simply with:
206
250
 
207
251
  $ terminitor edit my_project --capture
@@ -211,10 +255,10 @@ this will open up a new terminitor project with the captured settings for you to
211
255
 
212
256
  ### Fetching Github Projects with Terminitor ###
213
257
 
214
- Terminitor can also fetch code repositories off Skynet, I mean Github. This will have terminitor clone the repo into the current directory:
258
+ Terminitor can also fetch code repositories off Github. This will have terminitor clone the repo into the current directory:
215
259
 
216
260
  $ terminitor fetch achiu terminitor
217
-
261
+
218
262
  After the repo has been fetched, terminitor will go ahead and run the setup block from the Termfile included in the repository. In the event you wouldn't want the setup block to be executed, simply set setup to false:
219
263
 
220
264
  $ terminitor fetch achiu terminitor --setup=false
@@ -278,4 +322,4 @@ Finally, we decided the time had come to release this code back to the world as
278
322
 
279
323
  Also, we didn't take any code from [Project](http://github.com/joshnesbitt/project) by Josh but that project did inspire us to setup terminit
280
324
  as a gem. Basically, project is a great gem but there were a couple issues with the fact that the terminal doesn't save the session state in some cases.
281
- I had already been using terminit for years so we decided to package this up for easy use.
325
+ I had already been using terminit for years so we decided to package this up for easy use.
@@ -11,14 +11,15 @@ module Terminitor
11
11
  # Run the setup block in Termfile
12
12
  def setup!
13
13
  @working_dir = Dir.pwd
14
- commands = @termfile[:setup].insert(0, "cd #{working_dir}")
14
+ commands = @termfile[:setup].insert(0, "cd #{@working_dir}")
15
15
  commands.each { |cmd| execute_command(cmd, :in => active_window) }
16
16
  end
17
17
 
18
18
  # Executes the Termfile
19
19
  def process!
20
+ @working_dir = Dir.pwd
20
21
  term_windows = @termfile[:windows]
21
- run_in_window('default', term_windows['default'], :default => true) unless term_windows['default'].to_s.empty?
22
+ run_in_window('default', term_windows['default'], :default => true) unless term_windows['default'][:tabs].empty?
22
23
  term_windows.delete('default')
23
24
  term_windows.each_pair { |window_name, window_content| run_in_window(window_name, window_content) }
24
25
  end
@@ -26,21 +27,25 @@ module Terminitor
26
27
  # this command will run commands in the designated window
27
28
  # run_in_window 'window1', {:tab1 => ['ls','ok']}
28
29
  def run_in_window(window_name, window_content, options = {})
29
- window_options = window_content[:options]
30
+ window_options = window_content[:options]
30
31
  first_tab = true
31
- window_content[:tabs].each_pair do |tab_name, tab_content|
32
+ window_content[:tabs].each_pair do |tab_key, tab_content|
32
33
  # Open window on first 'tab' statement
33
34
  # first tab is already opened in the new window, so first tab should be
34
35
  # opened as a new tab in default window only
35
36
  tab_options = tab_content[:options]
37
+ tab_name = tab_options[:name] if tab_options
36
38
  if first_tab && !options[:default]
37
39
  first_tab = false
38
40
  window_options = Hash[window_options.to_a + tab_options.to_a] # safe merge
39
41
  tab = window_options.empty? ? open_window(nil) : open_window(window_options)
40
42
  else
41
- tab = open_tab(tab_options)
43
+ tab = ( tab_key == 'default' ? active_window : open_tab(tab_options) ) # give us the current window if its default, else open a tab.
42
44
  end
43
- tab_content[:commands].insert(0, "cd \"#{@working_dir}\"") unless @working_dir.to_s.empty?
45
+ tab_content[:commands].insert(0, 'clear') if tab_name || !@working_dir.to_s.empty? # clean up prompt
46
+ tab_content[:commands].insert(0, "PS1=$PS1\"\\e]2;#{tab_name}\\a\"") if tab_name # add title to tab
47
+ tab_content[:commands].insert(0, "cd \"#{@working_dir}\"") unless @working_dir.to_s.empty?
48
+ tab_content[:commands].insert(0, window_content[:before]).flatten! if window_content[:before] # append our before block commands.
44
49
  tab_content[:commands].each do |cmd|
45
50
  execute_command(cmd, :in => tab)
46
51
  end
@@ -59,7 +64,8 @@ module Terminitor
59
64
  # yay.
60
65
 
61
66
  # Executes the Command
62
- # execute_command 'cd /path/to', {}
67
+ # should use the :in key to interact with terminal object.
68
+ # execute_command 'cd /path/to', {:in => #<TerminalObject>}
63
69
  def execute_command(cmd, options = {})
64
70
  end
65
71
 
@@ -6,7 +6,7 @@ module Terminitor
6
6
 
7
7
  ALLOWED_OPTIONS = {
8
8
  :window => [:bounds, :visible, :miniaturized],
9
- :tab => [:settings, :selected, :miniaturized, :visible]
9
+ :tab => [:settings, :selected]
10
10
  }
11
11
 
12
12
  # Initialize @terminal with Terminal.app, Load the Windows, store the Termfile
@@ -82,12 +82,15 @@ module Terminitor
82
82
  object.position.set(value)
83
83
  when :selected # works for tabs, for example tab :active => true
84
84
  delayed_option(option, value, object)
85
+ when :miniaturized # works for windows only
86
+ delayed_option(option, value, object)
87
+ when :name
88
+ # ignore it.
85
89
  else # trying to apply any other option
86
90
  begin
87
91
  object.instance_eval(option.to_s).set(value)
88
- rescue Appscript::CommandError => e
89
- puts "Error setting '#{option} = #{value}' on #{object.inspect}"
90
- puts e.message
92
+ rescue
93
+ puts "Error setting #{option} = #{value} on #{object.inspect}"
91
94
  end
92
95
  end
93
96
  end
@@ -4,9 +4,9 @@ module Terminitor
4
4
 
5
5
  def initialize(path)
6
6
  file = File.read(path)
7
- @setup = []
8
- @windows = { 'default' => {:tabs => {}}}
9
- @_context = @windows['default'][:tabs]
7
+ @setup = []
8
+ @windows = { 'default' => {:tabs => {'default' =>{:commands=>[]}}}}
9
+ @_context = @windows['default']
10
10
  instance_eval(file)
11
11
  end
12
12
 
@@ -15,51 +15,58 @@ module Terminitor
15
15
  # setup "bundle install", "brew update"
16
16
  # setup { run('bundle install') }
17
17
  def setup(*commands, &block)
18
- setup_tasks = @setup
19
18
  if block_given?
20
- @_context, @_old_context = setup_tasks, @_context
21
- instance_eval(&block)
22
- @_context = @_old_context
19
+ in_context @setup, &block
23
20
  else
24
- setup_tasks.concat(commands)
21
+ @setup.concat(commands)
25
22
  end
26
23
  end
27
24
 
28
25
  # sets command context to be run inside a specific window
29
26
  # window(:name => 'new window', :size => [80,30], :position => [9, 100]) { tab('ls','gitx') }
30
27
  # window { tab('ls', 'gitx') }
31
- def window(name =nil, options = nil, &block)
32
- options ||= {}
33
- options, name = name, nil if name.is_a?(Hash)
34
- window_name = name || "window#{@windows.keys.size}"
35
- window_contents = @windows[window_name] = {:tabs => {}}
28
+ def window(options = {}, &block)
29
+ window_name = "window#{@windows.keys.size}"
30
+ window_contents = @windows[window_name] = {:tabs => {'default' => {:commands =>[]}}}
36
31
  window_contents[:options] = options unless options.empty?
37
- @_context, @_old_context = window_contents[:tabs], @_context
38
- instance_eval(&block)
39
- @_context = @_old_context
32
+ in_context window_contents, &block
40
33
  end
41
34
 
42
35
  # stores command in context
43
36
  # run 'brew update'
44
37
  def run(command)
45
- @_context << command
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]<<(command)
40
+ else
41
+ @_context<<(command)
42
+ end
43
+ end
44
+
45
+ # runs commands before each tab in window context
46
+ # window do
47
+ # before { run 'whoami' }
48
+ # end
49
+ def before(*commands, &block)
50
+ @_context[:before] ||= []
51
+ if block_given?
52
+ in_context @_context[:before], &block
53
+ else
54
+ @_context[:before].concat(commands)
55
+ end
46
56
  end
47
57
 
48
58
  # sets command context to be run inside specific tab
49
59
  # tab(:name => 'new tab', :settings => 'Grass') { run 'mate .' }
50
60
  # tab 'ls', 'gitx'
51
- def tab(name = nil, options = nil, *commands, &block)
52
- options ||= {}
61
+ def tab(options = {}, *commands, &block)
62
+ tabs = @_context[:tabs]
63
+ tab_name = "tab#{tabs.keys.size}"
53
64
  if block_given?
54
- options, name = name, nil if name.is_a?(Hash)
55
- tab_name = name || "tab#{@_context.keys.size}"
56
- tab_contents = @_context[tab_name] = {:commands => []}
65
+ tab_contents = tabs[tab_name] = {:commands => []}
57
66
  tab_contents[:options] = options unless options.empty?
58
- @_context, @_old_context = tab_contents[:commands], @_context
59
- instance_eval(&block)
60
- @_context = @_old_context
67
+ in_context tab_contents[:commands], &block
61
68
  else
62
- tab_tasks = @_context["tab#{@_context.keys.size}"] = { :commands => [name] + [options] +commands}
69
+ tabs[tab_name] = { :commands => [options] + commands}
63
70
  end
64
71
  end
65
72
 
@@ -70,17 +77,12 @@ module Terminitor
70
77
 
71
78
  private
72
79
 
73
- #
74
- # in_context @setup, commands, &block
75
- # in_context @tabs["name"], commands, &block
76
- def in_context(tasks_instance,*commands, &block)
77
- if block_given?
78
- @_context, @_old_context = instance_variable_get(name), @_context
79
- instance_eval(&block)
80
- @_context = @_old_context
81
- else
82
- @setup << commands
83
- end
80
+ # in_context @setup, &block
81
+ # in_context @tabs["name"], &block
82
+ def in_context(context, &block)
83
+ @_context, @_old_context = context, @_context
84
+ instance_eval(&block)
85
+ @_context = @_old_context
84
86
  end
85
87
 
86
88
 
@@ -1,3 +1,3 @@
1
1
  module Terminitor
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
data/terminitor.gemspec CHANGED
@@ -24,8 +24,8 @@ Gem::Specification.new do |s|
24
24
  s.add_dependency "thor", "~>0.14.0"
25
25
  s.add_dependency "github", "~>0.4.5"
26
26
  s.add_development_dependency "bundler", "~>1.0.0"
27
- s.add_development_dependency "riot", "~>0.11.0"
28
- s.add_development_dependency "rr", "=1.0.0"
27
+ s.add_development_dependency "riot", "~>0.12.0"
28
+ s.add_development_dependency "rr", "~>1.0.0"
29
29
  s.add_development_dependency "fakefs"
30
30
  s.post_install_message = %q{********************************************************************************
31
31
 
@@ -2,37 +2,36 @@ require File.expand_path('../teststrap', __FILE__)
2
2
 
3
3
  context "AbstractCore" do
4
4
 
5
- context "setup!" do
6
- setup do
7
- any_instance_of(Terminitor::AbstractCore) do |core|
8
- stub(core).load_termfile('/path/to') { { :setup => ['ls','ok'] } }
9
- mock(core).active_window { true }.times 3
10
- end
5
+ asserts "#setup! executes setup block" do
6
+ any_instance_of(Terminitor::AbstractCore) do |core|
7
+ stub(core).load_termfile('/path/to') { { :setup => ['ls','ok'] } }
8
+ mock(core).active_window { true }.times 3
11
9
  end
12
- setup { @core = Terminitor::AbstractCore.new('/path/to') }
13
- setup { mock(@core).execute_command("cd #{Dir.pwd}", :in => true)}
14
- setup { mock(@core).execute_command('ls', :in => true) }
15
- setup { mock(@core).execute_command('ok', :in => true) }
16
- asserts("ok") { @core.setup! }
10
+ core = Terminitor::AbstractCore.new('/path/to')
11
+ mock(core).execute_command("cd #{Dir.pwd}", :in => true)
12
+ mock(core).execute_command('ls', :in => true)
13
+ mock(core).execute_command('ok', :in => true)
14
+ core.setup!
17
15
  end
18
16
 
19
- context "process!" do
20
- context "without default" do
21
- setup do
22
- any_instance_of(Terminitor::AbstractCore) do |core|
17
+ context "#process!" do
18
+
19
+ should "execute without default" do
20
+ any_instance_of(Terminitor::AbstractCore) do |core|
23
21
  stub(core).load_termfile('/path/to') do
24
- {:windows => {'window1' => {:tabs => {'tab1' => ['ls', 'ok']}}, 'default' => [] }}
22
+ {:windows => {'window1' => {:tabs => {'tab1' => ['ls', 'ok']}},
23
+ 'default' => {:tabs => {}}
24
+ }
25
+ }
25
26
  end
26
- end
27
27
  end
28
- setup { @core = Terminitor::AbstractCore.new('/path/to') }
29
- setup { mock(@core).run_in_window('window1', {:tabs => {'tab1' => ['ls', 'ok']}}) }
30
- asserts("ok") { @core.process! }
28
+ core = Terminitor::AbstractCore.new('/path/to')
29
+ mock(core).run_in_window('window1', {:tabs => {'tab1' => ['ls', 'ok']}})
30
+ core.process!
31
31
  end
32
32
 
33
- context "with default" do
34
- setup do
35
- any_instance_of(Terminitor::AbstractCore) do |core|
33
+ should "execute with default" do
34
+ any_instance_of(Terminitor::AbstractCore) do |core|
36
35
  stub(core).load_termfile('/path/to') do
37
36
  {:windows => {'window1' => {:tabs => {'tab1' => ['ls', 'ok']} },
38
37
  'default' => {:tabs => {'tab0' => ['echo']} }
@@ -40,45 +39,63 @@ context "AbstractCore" do
40
39
  }
41
40
  end
42
41
  end
43
- end
44
- setup { @core = Terminitor::AbstractCore.new('/path/to') }
45
- setup { mock(@core).run_in_window('default',{:tabs => {'tab0'=>['echo']}}, :default => true) }
46
- setup { mock(@core).run_in_window('window1', {:tabs => {'tab1' => ['ls', 'ok']}}) }
47
- asserts("ok") { @core.process! }
42
+ core = Terminitor::AbstractCore.new('/path/to')
43
+ mock(core).run_in_window('default',{:tabs => {'tab0'=>['echo']}}, :default => true)
44
+ mock(core).run_in_window('window1', {:tabs => {'tab1' => ['ls', 'ok']}})
45
+ core.process!
48
46
  end
49
47
 
50
48
  end
51
49
 
52
- context "run_in_window" do
50
+ context "#run_in_window" do
51
+
53
52
  context "without options" do
54
53
  setup do
55
54
  any_instance_of(Terminitor::AbstractCore) do |core|
56
- stub(core).load_termfile('/path/to') { {:windows => {'window1' => {:tabs => {'tab1' => {:commands => ['ls', 'ok']}, 'tab2' => {:commands => ['ps']}}}}} }
55
+ stub(core).load_termfile('/path/to') {
56
+ {:windows => {'window1' => {:tabs => {'tab1' => {:commands => ['ls', 'ok']},
57
+ 'tab2' => {:commands => ['ps']}}},
58
+ 'default' => {:tabs => {}}
59
+ }
60
+ }
61
+ }
57
62
  end
58
- @core = Terminitor::AbstractCore.new('/path/to')
63
+ stub(Dir).pwd { nil }
64
+ Terminitor::AbstractCore.new('/path/to')
65
+ end
66
+
67
+ should "execute without default" do
68
+ core = topic.dup
69
+ mock(core).open_window(nil) { "first" }
70
+ mock(core).open_tab(nil) { "second" }
71
+ mock(core).set_delayed_options { true }
72
+ mock(core).execute_command('ls', :in => "first")
73
+ mock(core).execute_command('ok', :in => "first")
74
+ mock(core).execute_command('ps', :in => "second")
75
+ core.process!
59
76
  end
60
77
 
61
- context "without default" do
62
- setup { mock(@core).open_window(nil) { "first" } }
63
- setup { mock(@core).open_tab(nil) { "second" } }
64
- setup { mock(@core).set_delayed_options { true } }
65
- setup { mock(@core).execute_command('ls', :in => "first") }
66
- setup { mock(@core).execute_command('ok', :in => "first") }
67
- setup { mock(@core).execute_command('ps', :in => "second") }
68
- asserts("ok") { @core.process! }
78
+ should "execute with default window" do
79
+ core = topic.dup
80
+ mock(core).open_tab(nil) { true }
81
+ mock(core).execute_command('echo', :in => true)
82
+ core.run_in_window('default',{:tabs => {'tab0'=>{:commands => ['echo']}}}, :default => true)
69
83
  end
70
84
 
71
- context "with default" do
72
- setup { mock(@core).open_tab(nil) { true } }
73
- setup { mock(@core).execute_command('echo', :in => true) }
74
- asserts("ok") { @core.run_in_window('default',{:tabs => {'tab0'=>{:commands => ['echo']}}}, :default => true)}
85
+ should "execute with default tab" do
86
+ core = topic.dup
87
+ mock(core).active_window { true }
88
+ mock(core).execute_command('uptime', :in => true)
89
+ core.run_in_window('default',{:tabs => {'default'=>{:commands=>['uptime']}}}, :default => true)
75
90
  end
76
91
 
77
- context "with working_dir" do
78
- setup { stub(Dir).pwd { '/tmp/path' } }
79
- setup { mock(@core).execute_command("cd \"/tmp/path\"", :in => '/tmp/path') }
80
- setup { mock(@core).execute_command('ls', :in => '/tmp/path') }
81
- asserts("ok") { @core.run_in_window('window1', {:tabs => {'tab1' => {:commands => ['ls']}}}) }
92
+ should "execute with working_dir" do
93
+ core = topic.dup
94
+ stub(Dir).pwd { '/tmp/path' }
95
+ mock(core).execute_command("cd \"/tmp/path\"", :in => '/tmp/path')
96
+ mock(core).execute_command('clear', :in => '/tmp/path')
97
+ mock(core).execute_command('ls', :in => '/tmp/path')
98
+ core.run_in_window('window1', {:tabs => {'tab1' => {:commands => ['ls']}}})
82
99
  end
83
100
  end
84
101
 
@@ -86,24 +103,66 @@ context "AbstractCore" do
86
103
  setup do
87
104
  any_instance_of(Terminitor::AbstractCore) do |core|
88
105
  stub(core).load_termfile('/path/to') do
89
- {:windows => {'window1' => {:tabs => {'tab1' => {:commands => ['ls', 'ok'], :options => {:settings => 'cool', :name => 'first tab'}},
90
- 'tab2' => {:commands => ['ps'], :options => {:settings => 'grass', :name => 'second tab'}},
106
+ {:windows => {'window1' => {:tabs => {'tab1' => {:commands => ['ls', 'ok'],
107
+ :options => {:settings => 'cool', :name => 'first tab'}},
108
+ 'tab2' => {:commands => ['ps'],
109
+ :options => {:settings => 'grass', :name => 'second tab'}},
91
110
  },
92
- :options => {:bounds => [10,10]}}}
111
+ :options => {:bounds => [10,10]}},
112
+ 'default' => {:tabs => {}}
113
+ }
93
114
  }
94
115
  end
95
116
  end
96
- @core = Terminitor::AbstractCore.new('/path/to')
117
+ stub(Dir).pwd { nil }
118
+ Terminitor::AbstractCore.new('/path/to')
97
119
  end
98
120
 
99
- setup { mock(@core).open_window(:bounds => [10,10], :settings => 'cool', :name => "first tab") { "first" } }
100
- setup { mock(@core).open_tab(:settings => 'grass', :name => 'second tab') { "second" } }
101
- setup { mock(@core).set_delayed_options { true } }
102
- setup { mock(@core).execute_command('ls', :in => "first") }
103
- setup { mock(@core).execute_command('ok', :in => "first") }
104
- setup { mock(@core).execute_command('ps', :in => "second") }
105
-
106
- asserts("ok") { @core.process! }
121
+ should "execute" do
122
+ core = topic.dup
123
+ mock(core).open_window(:bounds => [10,10], :settings => 'cool', :name => "first tab") { "first" }
124
+ mock(core).open_tab(:settings => 'grass', :name => 'second tab') { "second" }
125
+ mock(core).set_delayed_options { true }
126
+ mock(core).execute_command('PS1=$PS1"\e]2;first tab\a"', :in => 'first')
127
+ mock(core).execute_command('clear', :in => 'first')
128
+ mock(core).execute_command('ls', :in => "first")
129
+ mock(core).execute_command('ok', :in => "first")
130
+ mock(core).execute_command('PS1=$PS1"\e]2;second tab\a"', :in => 'second')
131
+ mock(core).execute_command('clear', :in => 'second')
132
+ mock(core).execute_command('ps', :in => "second")
133
+ core.process!
134
+ end
135
+ end
136
+
137
+
138
+ context "with before" do
139
+ setup do
140
+ any_instance_of(Terminitor::AbstractCore) do |core|
141
+ stub(core).load_termfile('/path/to') {
142
+ {:windows => {'window1' => {:tabs => {'tab1' => {:commands => ['ls']},
143
+ 'tab2' => {:commands => ['ps']}},
144
+ :before => ['whoami']
145
+ },
146
+ 'default' => {:tabs => {}}
147
+ }
148
+ }
149
+ }
150
+ end
151
+ stub(Dir).pwd { nil }
152
+ Terminitor::AbstractCore.new('/path/to')
153
+ end
154
+
155
+ should "execute without default" do
156
+ core = topic.dup
157
+ mock(core).open_window(nil) { "first" }
158
+ mock(core).open_tab(nil) { "second" }
159
+ mock(core).set_delayed_options { true }
160
+ mock(core).execute_command('whoami', :in => 'first')
161
+ mock(core).execute_command('ls', :in => "first")
162
+ mock(core).execute_command('whoami', :in => "second")
163
+ mock(core).execute_command('ps', :in => "second")
164
+ core.process!
165
+ end
107
166
  end
108
167
  end
109
168