Permalink
Browse files

pre-pane commands: closes GH issue #33

  • Loading branch information...
1 parent 3d606e2 commit 7e85899314430b85f8b38b7507a93057826ecea5 @hedgehog hedgehog committed Nov 4, 2011
@@ -8,12 +8,22 @@ rvm: 1.9.2@rails_project
pre: sudo /etc/rc.d/mysqld start
tabs:
- editor:
+ pre: echo 'I get run in each pane. Before each pane command!'
layout: main-vertical
panes:
- vim
- #empty, will just run plain bash
- top
- shell: git pull
+ - guard:
+ layout: tiled
+ pre:
+ - echo 'I get run in each pane.'
+ - echo 'Before each pane command!'
+ panes:
+ -
+ - #empty, will just run plain bash
+ -
- database: rails db
- server: rails s
- logs: tail -f logs/development.log
@@ -20,6 +20,7 @@ tmux <%= socket %> new-window -t <%= window(i+2) %> -n <%=s tab.name %>
<%= send_keys(tab.panes.shift, i+1) %>
<% tab.panes.each do |pane| %>
tmux <%= socket %> splitw -t <%= window(i+1) %>
+<%= send_keys(pane.pre, i+1) if pane.pre %>
<%= send_keys(pane, i+1) %>
<% end %>
tmux <%= socket %> select-layout -t <%= window(i+1) %> <%=s tab.layout %>
@@ -67,6 +67,10 @@ def process_config!
build_command(pane)
end
t.layout = value["layout"]
+ str = ( ( value["pre"] if value["pre"] && value["pre"].kind_of?(Array) ) || ([value["pre"]] if value["pre"] && value["pre"].kind_of?(String)) || ['']).map do |cmds|
+ build_command(cmds, false)
+ end.join ' && '
+ t.pre = build_command(str)
else
t.command = build_command(value)
end
@@ -91,12 +95,11 @@ def send_keys cmd, window_number
"tmux #{socket} send-keys -t #{window(window_number)} #{s cmd} C-m"
end
- def build_command(value)
+ def build_command(value, rvm_prepend=true)
commands = [value].flatten.compact.reject { |c| c.strip.empty? }
- if @rvm
+ if @rvm && rvm_prepend
commands.unshift "rvm use #{@rvm}"
end
-
commands.join ' && '
end
end
View
@@ -38,6 +38,7 @@
specify{ first_tab.name.should eql "editor" }
specify{ first_tab.layout.should eql "main-vertical" }
specify{ first_tab.panes.should be_an Array }
+ specify{ first_tab.pre.should eql "rvm use 1.9.2@rails_project && echo 'I get run in each pane. Before each pane command!'" }
it "should prepend each pane with the rvm string" do
first_tab.panes.map{|p| p.split(/ && /)[0] }.should eql ["rvm use 1.9.2@rails_project"] * 3
@@ -50,5 +51,12 @@
let(:second_tab){ subject.tabs[1] }
specify{ second_tab.name.should eql "shell" }
specify{ second_tab.command.should eql "rvm use 1.9.2@rails_project && git pull"}
+
+ let(:third_tab){ subject.tabs[2] }
+ specify{ third_tab.should be_an OpenStruct }
+ specify{ third_tab.name.should eql "guard" }
+ specify{ third_tab.layout.should eql "tiled" }
+ specify{ third_tab.panes.should be_an Array }
+ specify{ third_tab.pre.should eql "rvm use 1.9.2@rails_project && echo 'I get run in each pane.' && echo 'Before each pane command!'"}
end
end

0 comments on commit 7e85899

Please sign in to comment.