pre-pane commands: closes GH issue #33

This commit is contained in:
Hedgehog 2011-11-04 14:05:41 +11:00
parent 3d606e273d
commit 7e85899314
4 changed files with 25 additions and 3 deletions

View File

@ -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

View File

@ -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 %>

View File

@ -67,6 +67,10 @@ module Tmuxinator
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 @@ module Tmuxinator
"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 File

@ -38,6 +38,7 @@ describe Tmuxinator::ConfigWriter do
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 @@ describe Tmuxinator::ConfigWriter do
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