Class: ItermWindow
- Inherits:
-
Object
- Object
- ItermWindow
- 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
-
.current(&block) ⇒ Object
Selects the first terminal window, runs the block on it.
-
.open(&block) ⇒ Object
Creates a new terminal window, runs the block on it.
Instance Method Summary collapse
-
#initialize(window_type = :new, &block) ⇒ ItermWindow
constructor
While you can directly use ItermWindow.new, using either ItermWindow.open or ItermWindow.current is the preferred method.
-
#open_bookmark(name, bookmark, &block) ⇒ Object
Creates a new tab from a bookmark, runs the block on it.
-
#open_tab(name, &block) ⇒ Object
Creates a new tab from ‘Default Session’, runs the block on it.
-
#output(command) ⇒ Object
Outputs a single line of Applescript code.
Constructor Details
#initialize(window_type = :new, &block) ⇒ ItermWindow
While you can directly use ItermWindow.new, using either ItermWindow.open or ItermWindow.current is the preferred method.
72 73 74 75 76 77 |
# File 'lib/iterm_window.rb', line 72 def initialize(window_type = :new, &block) @buffer = [] @tabs = {} run_commands window_type, &block send_output end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object (private)
Access the tabs by their names
133 134 135 |
# File 'lib/iterm_window.rb', line 133 def method_missing(method_name, *args, &block) @tabs[method_name] || super end |
Class Method Details
.current(&block) ⇒ Object
Selects the first terminal window, runs the block on it
85 86 87 |
# File 'lib/iterm_window.rb', line 85 def self.current(&block) new(:current, &block) end |
.open(&block) ⇒ Object
Creates a new terminal window, runs the block on it
80 81 82 |
# File 'lib/iterm_window.rb', line 80 def self.open(&block) new(:new, &block) end |
Instance Method Details
#open_bookmark(name, bookmark, &block) ⇒ Object
Creates a new tab from a bookmark, runs the block on it
90 91 92 |
# File 'lib/iterm_window.rb', line 90 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
95 96 97 |
# File 'lib/iterm_window.rb', line 95 def open_tab(name, &block) create_tab(name, 'Default Session', &block) end |
#output(command) ⇒ Object
Outputs a single line of Applescript code
100 101 102 |
# File 'lib/iterm_window.rb', line 100 def output(command) @buffer << command.gsub(/'/, '"') end |