Class: ItermWindow

Inherits:
Object
  • Object
show all
Defined in:
lib/iterm_window.rb

Overview

The ItermWindow class models an iTerm terminal window and allows for full control via Ruby commands.

Defined Under Namespace

Classes: Tab

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeItermWindow

While you can directly use ItermWindow.new, using either ItermWindow.open or ItermWindow.current is the preferred method.



76
77
78
79
# File 'lib/iterm_window.rb', line 76

def initialize
  @buffer = []
  @tabs = {}
end

Class Method Details

.current(&block) ⇒ Object

Selects the first terminal window, runs the block on it



87
88
89
# File 'lib/iterm_window.rb', line 87

def self.current(&block)
  self.new.run(:current, &block)
end

.open(&block) ⇒ Object

Creates a new terminal window, runs the block on it



82
83
84
# File 'lib/iterm_window.rb', line 82

def self.open(&block)
  self.new.run(:new, &block)
end

Instance Method Details

#open_bookmark(name, bookmark, &block) ⇒ Object

Creates a new tab from a bookmark, runs the block on it



97
98
99
# File 'lib/iterm_window.rb', line 97

def open_bookmark(name, bookmark, &block)
  create_tab(name, bookmark, &block)
end

#open_tab(name, &block) ⇒ Object

Creates a new tab from ‘Default Session’, runs the block on it



102
103
104
# File 'lib/iterm_window.rb', line 102

def open_tab(name, &block)
  create_tab(name, 'Default Session', &block)
end

#output(command) ⇒ Object

Outputs a single line of Applescript code



107
108
109
# File 'lib/iterm_window.rb', line 107

def output(command)
  @buffer << command.gsub(/'/, '"')
end

#run(window_type = :new, &block) ⇒ Object



91
92
93
94
# File 'lib/iterm_window.rb', line 91

def run(window_type = :new, &block)
  run_commands window_type, &block
  send_output
end