From ca7a6853bea8539770eee74c76ab86ea2817a168 Mon Sep 17 00:00:00 2001 From: Arthur Chiu Date: Thu, 7 Apr 2011 11:16:18 -0700 Subject: [PATCH] [dsl] add ( ) if background operator exists --- lib/terminitor/dsl.rb | 6 ++++-- test/dsl_test.rb | 12 ++++++------ test/fixtures/bar.term | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/terminitor/dsl.rb b/lib/terminitor/dsl.rb index 0c9274f..9fd8b56 100644 --- a/lib/terminitor/dsl.rb +++ b/lib/terminitor/dsl.rb @@ -45,12 +45,14 @@ def window(options = {}, &block) # run 'brew update' def run(*commands) # if we are in a window context, append commands to default tab. - if @_context.is_a?(Hash) && @_context[:tabs] + if @_context.is_a?(Hash) && @_context[:tabs] current = @_context[:tabs]['default'][:commands] else current = @_context end - current << commands.map { |c| "#{c}" }.join(" && ") + current << commands.map do |c| + c =~ /&$/ ? "(#{c})" : c + end.join(" && ") end # runs commands before each tab in window context diff --git a/test/dsl_test.rb b/test/dsl_test.rb index d8c1848..e6e43e9 100644 --- a/test/dsl_test.rb +++ b/test/dsl_test.rb @@ -22,7 +22,7 @@ setup { topic[:tabs] } asserts([:[], 'tab2']).equivalent_to({ - :commands=>["(echo 'named tab')", "(ls)"], + :commands=>["echo 'named tab'", "ls"], :options => { :name => "named tab", :settings=>"Grass" @@ -30,11 +30,11 @@ }) asserts([:[], 'tab1']).equivalent_to({ - :commands=>["echo 'first tab'", "echo 'of window'", "echo 'than now'"] + :commands=>["echo 'first tab'", "motion &", "echo 'than now'"] }) asserts([:[],'tab3']).equivalent_to({ - :commands=>["(top)"], + :commands=>["top","(mate &) && (gitx &) && cd /this"], :options =>{ :name => "a tab", :settings => "Pro" @@ -42,7 +42,7 @@ }) asserts([:[],'tab4']).equivalent_to({ - :commands=>["(ls)"], + :commands=>["ls"], :options =>{ :name => "another named tab", :settings => "Grass" @@ -50,7 +50,7 @@ }) asserts([:[],'default']).equivalent_to({ - :commands=>['(whoami) && (who) && (ls)'] + :commands=>['whoami && who && ls'] }) end @@ -59,7 +59,7 @@ context "with 'window2' key" do setup { topic['window2'] } - asserts([:[],:before]).equals ['(whoami)'] + asserts([:[],:before]).equals ['whoami'] context "with :tabs" do setup { topic[:tabs] } diff --git a/test/fixtures/bar.term b/test/fixtures/bar.term index b0b5a88..eef1cf8 100644 --- a/test/fixtures/bar.term +++ b/test/fixtures/bar.term @@ -10,7 +10,7 @@ window :size => [70,30] do before 'cd /path' run "whoami","who", "ls" - tab "echo 'first tab'", "echo 'of window'", "echo 'than now'" + tab "echo 'first tab'", "motion &", "echo 'than now'" tab :name => "named tab", :settings => "Grass" do run "echo 'named tab'" @@ -19,6 +19,7 @@ window :size => [70,30] do tab "a tab", :settings => "Pro" do run "top" + run "mate &", "gitx &", "cd /this" end tab("another named tab", :settings => 'Grass') { run "ls" }