Skip to content

Commit

Permalink
added rudimentary iTerm support
Browse files Browse the repository at this point in the history
  • Loading branch information
erithmetic committed Jul 8, 2011
1 parent 344aa66 commit c96d04d
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/tmuxinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
require 'tmuxinator/helper'
require 'tmuxinator/cli'
require 'tmuxinator/config_writer'
require 'tmuxinator/iterm_config_writer'

TMUX_TEMPLATE = "#{File.dirname(__FILE__)}/tmuxinator/assets/tmux_config.tmux"
ITERM_TEMPLATE = "#{File.dirname(__FILE__)}/tmuxinator/assets/iterm.AppleScript"

module Tmuxinator
end
46 changes: 46 additions & 0 deletions lib/tmuxinator/assets/iterm.AppleScript
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
tell application "iTerm"
activate

set myterm to (make new terminal)

set the name of the first window to "<%= @project_name %>"

tell myterm
set number of columns to 100
set number of rows to 50

-- set up tabs and panes
<% @tabs.each_with_index do |tab, i| %>
<% session = "session#{i}" %>

-- tab "<%= tab.name %>"
set <%= session %> to (launch session "<%= tab.name %>")

tell <%= session %>
<% if tab.command %>
write text "<%= tab.command %>"
<% elsif tab.panes %>
-- tmux select-layout -t <%= window(i+1) %> <%=s tab.layout %>
write text "<%= tab.panes.shift %>"
<% tab.panes.each do |pane| %>
tell application "System Events" to keystroke "d" using command down
write text "<%= pane %>"
<% end %>
<% end %>
end tell
<% end %>

<% if @pre %>
set pre_session to (launch session "pre")
tell pre_session
-- run the pre stuff
write text "<%= @pre.kind_of?(Array) ? @pre.join(" && ") : @pre %>"
end tell
terminate pre_session
<% end %>

end tell

-- select window 1
select the first session of myterm
end tell
8 changes: 8 additions & 0 deletions lib/tmuxinator/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,19 @@ def version

def update_scripts
Dir["#{root_dir}*.tmux"].each {|p| FileUtils.rm(p) }
Dir["#{root_dir}*.AppleScript"].each {|p| FileUtils.rm(p) }

aliases = []
Dir["#{root_dir}*.yml"].each do |path|
aliases << Tmuxinator::ConfigWriter.new(path).write!
end
Tmuxinator::ConfigWriter.write_aliases(aliases)

iterm_aliases = []
Dir["#{root_dir}*.yml"].each do |path|
iterm_aliases << Tmuxinator::ITermConfigWriter.new(path).write!
end
Tmuxinator::ITermConfigWriter.write_aliases(iterm_aliases)
end

def doctor
Expand Down
49 changes: 49 additions & 0 deletions lib/tmuxinator/iterm_config_writer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module Tmuxinator

class ITermConfigWriter < ConfigWriter
attr_accessor :file_name, :file_path, :project_name, :project_root, :rvm, :tabs, :pre

include Tmuxinator::Helper

def self.write_aliases(aliases)
File.open("#{ENV["HOME"]}/.tmuxinator/scripts/tmuxinator", 'w') {|f| f.write(aliases.join("\n")) }
end

def initialize(this_full_path=nil)
self.file_path = this_full_path if this_full_path
end

def file_path= full_path
@file_path = full_path
@file_name = File.basename full_path, '.yml'
process_config! if full_path && File.exist?(full_path)
end

def write!
raise "Unable to write with out a file_name defined" unless file_name
erb = ERB.new(IO.read(ITERM_TEMPLATE)).result(binding)
tmp = File.open(config_path, 'w') {|f| f.write(erb) }

"alias start_#{file_name}='$SHELL #{config_path}'"
end

def config_path
"#{root_dir}#{file_name}.AppleScript" if file_name
end

private

def write_alias(stuff)
File.open("#{root_dir}scripts/#{@filename}", 'w') {|f| f.write(stuff) }
end

def send_keys(cmd, window_number)
return '' unless cmd
"tmux send-keys -t #{window(window_number)} #{s cmd} C-m"
return <<-APPLESCRIPT
tell item <%= window_number %> of
%Q{tell application "System Events" to keystroke "#{cmd}"}
APPLESCRIPT
end
end
end

0 comments on commit c96d04d

Please sign in to comment.