Skip to content

Commit

Permalink
Merge 28e5ba6 into fdd2664
Browse files Browse the repository at this point in the history
  • Loading branch information
athal7 committed Mar 19, 2014
2 parents fdd2664 + 28e5ba6 commit 01847e6
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/tmuxinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

require "tmuxinator/util"
require "tmuxinator/deprecations"
require "tmuxinator/wemux_support"
require "tmuxinator/cli"
require "tmuxinator/config"
require "tmuxinator/pane"
Expand Down
54 changes: 54 additions & 0 deletions lib/tmuxinator/assets/wemux_template.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!<%= ENV["SHELL"] || "/bin/bash" %>
wemux ls 2>/dev/null

if [ "$?" -eq 127 ]; then
cd <%= root || "." %>

# Run pre command.
<%= pre %>

# Create the session and the first window.
TMUX= <%= tmux %> new-session -d -s <%= name %> -n <%= windows.first.name %>

# Set the default path.
<%= tmux %> set-option -t <%= name %> default-path <%= root.shellescape -%> 1>/dev/null

# Create other windows.
<%- windows.drop(1).each do |window| -%>
<%= window.tmux_new_window_command %>
<%- end -%>
<%- windows.each do |window| -%>

# Window "<%= window.name %>"
<%- unless window.panes? -%>
<%= window.tmux_pre_window_command %>
<%- window.commands.each do |command| -%>
<%= command %>
<%- end -%>
<%- else -%>
<%- window.panes.each do |pane| -%>
<%= pane.tmux_pre_window_command %>
<%= pane.tmux_pre_command %>
<%- if pane.multiple_commands? %>
<%- pane.commands.each do |command| -%>
<%= pane.tmux_main_command(command) %>
<%- end -%>
<%- else -%>
<%= pane.tmux_main_command(commands.first) %>
<%- end -%>
<%- unless pane.last? -%>
<%= pane.tmux_split_command %>
<%- end -%>
<%= window.tmux_layout_command %>
<%- end -%>
<%= window.tmux_select_first_pane %>
<%- end -%>
<%- end -%>
<%= tmux %> select-window -t <%= base_index %>
fi

wemux attach
4 changes: 4 additions & 0 deletions lib/tmuxinator/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def template
"#{File.dirname(__FILE__)}/assets/template.erb"
end

def wemux_template
"#{File.dirname(__FILE__)}/assets/wemux_template.erb"
end

def configs
Dir["#{Tmuxinator::Config.root}/*.yml"].sort.map do |path|
path.gsub("#{Tmuxinator::Config.root}/", "").gsub(".yml", "")
Expand Down
2 changes: 2 additions & 0 deletions lib/tmuxinator/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ module Tmuxinator
class Project
include Tmuxinator::Util
include Tmuxinator::Deprecations
include Tmuxinator::WemuxSupport

attr_reader :yaml

def initialize(yaml)
@yaml = yaml
load_wemux_overrides if wemux?
end

def render
Expand Down
24 changes: 24 additions & 0 deletions lib/tmuxinator/wemux_support.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Tmuxinator
module WemuxSupport
def wemux?
yaml["tmux_command"] == "wemux"
end

def load_wemux_overrides
self.instance_eval do
def render
template = File.read(Tmuxinator::Config.wemux_template)
Erubis::Eruby.new(template).result(binding)
end

def name
"wemux"
end

def tmux
"wemux"
end
end
end
end
end
8 changes: 8 additions & 0 deletions spec/factories/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@

initialize_with { Tmuxinator::Project.new(file) }
end

factory :wemux_project, :class => Tmuxinator::Project do
ignore do
file { YAML.load(File.read("#{File.expand_path("spec/fixtures/sample_wemux.yml")}")) }
end

initialize_with { Tmuxinator::Project.new(file) }
end
end
37 changes: 37 additions & 0 deletions spec/fixtures/sample_wemux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ~/.tmuxinator/sample_wemux.yml
# you can make as many tabs as you wish...

name: sample
root: ~/test
pre: sudo /etc/rc.d/mysqld start # Runs before everything
pre_window: rbenv shell 2.0.0-p247 # Runs in each tab and pane
tmux_options: -f ~/.tmux.mac.conf # Pass arguments to tmux
tmux_command: wemux
windows:
- 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
- git merge
- guard:
layout: tiled
pre:
- echo "I get run in each pane."
- echo "Before each pane command!"
panes:
-
- #empty, will just run plain bash
-
- database: bundle exec rails db
- server: bundle exec rails s
- logs: tail -f log/development.log
- console: bundle exec rails c
- capistrano:
- server: ssh user@example.com
13 changes: 13 additions & 0 deletions spec/lib/tmuxinator/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
describe Tmuxinator::Project do
let(:project) { FactoryGirl.build(:project) }
let(:project_with_deprecations) { FactoryGirl.build(:project_with_deprecations) }
let(:wemux_project) { FactoryGirl.build(:wemux_project) }

describe "#initialize" do
context "valid yaml" do
Expand All @@ -16,6 +17,12 @@
it "renders the tmux config" do
expect(project.render).to_not be_empty
end

context "wemux" do
it "renders the wemux config" do
expect(wemux_project.render).to_not be_empty
end
end
end

describe "#windows" do
Expand Down Expand Up @@ -58,6 +65,12 @@
expect(project_with_deprecations.name).to eq "sample"
end
end

context "wemux" do
it "is wemux" do
expect(wemux_project.name).to eq "wemux"
end
end
end

describe "#pre_window" do
Expand Down

0 comments on commit 01847e6

Please sign in to comment.