lib/termup/base.rb in termup-1.1.0 vs lib/termup/base.rb in termup-1.2.0

- old
+ new

@@ -1,53 +1,54 @@ require 'appscript' require 'yaml' module Termup class Base + ITERM1 = /^0\.10/ + ITERM2 = /^0\.20/ + include Appscript def initialize(project) @apps = app("System Events").application_processes @frontmost = @apps.get.select{|i| i.frontmost.get }.map{|i| i.name.get }.first return unless ["Terminal", "iTerm"].include?(@frontmost) @terminal = app(@frontmost) - + @project = YAML.load(File.read("#{TERMUP_DIR}/#{project}.yml")) - - # Split panes for iTerm - split_panes if @frontmost == "iTerm" and @project['options']['iterm'] - + + # Split panes for iTerm 2 + split_panes if iterm2? and @project['options']['iterm'] + @project['tabs'].each do |hash| tabname = hash.keys.first cmds = hash.values.first cmds = [cmds].flatten tab = new_tab cmds.each do |cmd| - case @frontmost - when "Terminal" + if terminal? @terminal.do_script(cmd, :in => tab) - when "iTerm" + else @terminal.current_terminal.current_session.write(:text => "#{cmd}") end end end end def new_tab if @got_first_tab_already - case @frontmost - when "Terminal" - @apps[@frontmost].keystroke("t", :using => :command_down) - when "iTerm" + if iterm2? @apps[@frontmost].keystroke("]", :using => :command_down) + else + @apps[@frontmost].keystroke("t", :using => :command_down) end end @got_first_tab_already = true sleep 0.01 # Allow some time to complete opening a new tab - @terminal.windows[1].tabs.last.get if @frontmost == "Terminal" + @terminal.windows[1].tabs.last.get if terminal? end - + def split_panes # Virtical splits (@project['options']['iterm']['width'] - 1).times do |i| @apps[@frontmost].keystroke("d", :using => :command_down) end @@ -59,8 +60,20 @@ @apps[@frontmost].keystroke("d", :using => [ :command_down, :shift_down ]) end # Move to the right @apps[@frontmost].keystroke("]", :using => :command_down) end + end + + def terminal? + @frontmost == "Terminal" + end + + def iterm1? + @frontmost == "iTerm" and @terminal.version.get =~ ITERM1 + end + + def iterm2? + @frontmost == "iTerm" and @terminal.version.get =~ ITERM2 end end end