Control your terminal windows in iTerm with Ruby -- great for automation scripting!
Go to file
2008-06-06 16:59:27 -05:00
iterm_window.rb Imported first draft of actual files. 2008-06-06 16:59:27 -05:00
README.rdoc Imported first draft of actual files. 2008-06-06 16:59:27 -05:00

= iTermWindow

<em>Developed March 17, 2008 by Chris Powers, Killswitch Collective http://killswitchcollective.com</em>

The ItermWindow class models an iTerm terminal window and allows for full control via Ruby commands.
Under the hood, this class is a wrapper of iTerm's Applescript scripting API. Methods are used to
generate Applescript code which is run as an <tt>osascript</tt> command when the ItermWindow initialization
block is closed.

ItermWindow::Tab models a tab (session) in an iTerm terminal window and allows for it to be controlled by Ruby.
These tabs can be created with either the ItermWindow#open_bookmark method or the ItermWindow#open_tab
method. Each tab is given a name (symbol) by which it can be accessed later in the code using
the ItermWindow's bracket method (ie window[:tab_name]).

== EXAMPLE - Open a new iTerm window, cd to a project and open it in TextMate

  ItermWindow.open do |window|
    window.open_tab :my_tab do |tab|
      tab.write "cd ~/projects/my_project/trunk"
      tab.write "mate ./"
    end
  end

== EXAMPLE - Use the current iTerm window, cd to a project and open in TextMate, launch the server and the console and title them

  ItermWindow.current do |window|
    window.open_tab :project_dir do |tab|
      tab.write "cd ~/projects/my_project/trunk"
      tab.write "mate ./"
      tab.title = "MyProject Dir"
    end
    window.open_tab :server do |tab|
      tab.write "cd ~/projects/my_project/trunk"
      tab.write "script/server -p 3005"
      tab.title = "MyProject Server"
    end
    window.open_tab :console do |tab|
      tab.write "cd ~/projects/my_project/trunk"
      tab.write "script/console"
      tab.title = "MyProject Console"
    end
  end

== EXAMPLE - Same thing, but use bookmarks that were made for the server and console. Also, switch focus back to project dir.

  ItermWindow.current do |window|
    window.open_tab :project_dir do |tab|
      tab.write "cd ~/projects/my_project/trunk"
      tab.write "mate ./"
    end
    window.open_bookmark :server, 'MyProject Server'
    window.open_bookmark :console, 'MyProject Console'
    window[:project_dir].select

== EXAMPLE - Arbitrarily open two tabs, switch between them and run methods/blocks with Tab#select method and Tab#write directly

  ItermWindow.open do |window|
    window.open_tab :first_tab
    window.open_tab :second_tab
    window[:first_tab].select do |tab|
      tab.write 'cd ~/projects'
      tab.write 'ls'
    end
    window[:second_tab].write "echo 'hello there!'"
    window[:first_tab].select # brings first tab back to focus
  end