2008-06-06 21:59:27 +00:00
|
|
|
= iTermWindow
|
|
|
|
|
2010-03-27 15:29:57 +00:00
|
|
|
<em>Developed March 17, 2008 by Chris Powers</em>
|
2008-06-06 21:59:27 +00:00
|
|
|
|
|
|
|
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
|
2008-08-12 22:08:02 +00:00
|
|
|
the tab name as an ItermWindow method.
|
2008-06-06 21:59:27 +00:00
|
|
|
|
|
|
|
== EXAMPLE - Open a new iTerm window, cd to a project and open it in TextMate
|
|
|
|
|
2009-02-20 14:43:47 +00:00
|
|
|
require 'rubygems'
|
|
|
|
require 'chrisjpowers-iterm_window'
|
|
|
|
|
2008-08-12 22:08:02 +00:00
|
|
|
ItermWindow.open do
|
|
|
|
open_tab :my_tab do
|
|
|
|
write "cd ~/projects/my_project/trunk"
|
|
|
|
write "mate ./"
|
2008-06-06 21:59:27 +00:00
|
|
|
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
|
|
|
|
|
2008-08-12 22:08:02 +00:00
|
|
|
ItermWindow.current do
|
|
|
|
open_tab :project_dir do
|
|
|
|
write "cd ~/projects/my_project/trunk"
|
|
|
|
write "mate ./"
|
|
|
|
set_title "MyProject Dir"
|
2008-06-06 21:59:27 +00:00
|
|
|
end
|
2008-08-12 22:08:02 +00:00
|
|
|
open_tab :server do
|
|
|
|
write "cd ~/projects/my_project/trunk"
|
|
|
|
write "script/server -p 3005"
|
|
|
|
set_title "MyProject Server"
|
2008-06-06 21:59:27 +00:00
|
|
|
end
|
2008-08-12 22:08:02 +00:00
|
|
|
open_tab :console do
|
|
|
|
write "cd ~/projects/my_project/trunk"
|
|
|
|
write "script/console"
|
|
|
|
set_title "MyProject Console"
|
2008-06-06 21:59:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
== EXAMPLE - Same thing, but use bookmarks that were made for the server and console. Also, switch focus back to project dir.
|
|
|
|
|
2008-08-12 22:08:02 +00:00
|
|
|
ItermWindow.current do
|
|
|
|
open_tab :project_dir do
|
|
|
|
write "cd ~/projects/my_project/trunk"
|
|
|
|
write "mate ./"
|
2008-06-06 21:59:27 +00:00
|
|
|
end
|
2008-08-12 22:08:02 +00:00
|
|
|
open_bookmark :server, 'MyProject Server'
|
|
|
|
open_bookmark :console, 'MyProject Console'
|
|
|
|
project_dir.select
|
2008-06-06 21:59:27 +00:00
|
|
|
|
|
|
|
== EXAMPLE - Arbitrarily open two tabs, switch between them and run methods/blocks with Tab#select method and Tab#write directly
|
|
|
|
|
2008-08-12 22:08:02 +00:00
|
|
|
ItermWindow.open do
|
|
|
|
open_tab :first_tab
|
|
|
|
open_tab :second_tab
|
|
|
|
first_tab.select do
|
|
|
|
write 'cd ~/projects'
|
|
|
|
write 'ls'
|
2008-06-06 21:59:27 +00:00
|
|
|
end
|
2008-08-12 22:08:02 +00:00
|
|
|
second_tab.write "echo 'hello there!'"
|
|
|
|
first_tab.select # brings first tab back to focus
|
2011-07-02 21:08:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Also, you get <tt>tab_color</tt> to change the color of the tab itself. Give it a hex value like <tt>F73</tt> or <tt>F7F3F1</tt>.
|
|
|
|
|