iterm_window 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/lib/iterm_window.rb +62 -78
- metadata +23 -32
data/README.rdoc
CHANGED
@@ -15,7 +15,7 @@ the tab name as an ItermWindow method.
|
|
15
15
|
== EXAMPLE - Open a new iTerm window, cd to a project and open it in TextMate
|
16
16
|
|
17
17
|
require 'rubygems'
|
18
|
-
require '
|
18
|
+
require 'iterm_window'
|
19
19
|
|
20
20
|
ItermWindow.open do
|
21
21
|
open_tab :my_tab do
|
@@ -66,4 +66,4 @@ the tab name as an ItermWindow method.
|
|
66
66
|
end
|
67
67
|
second_tab.write "echo 'hello there!'"
|
68
68
|
first_tab.select # brings first tab back to focus
|
69
|
-
end
|
69
|
+
end
|
data/lib/iterm_window.rb
CHANGED
@@ -1,38 +1,39 @@
|
|
1
1
|
# Developed March 17, 2008 by Chris Powers
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# The ItermWindow class models an iTerm terminal window and allows for full control via Ruby commands.
|
4
4
|
# Under the hood, this class is a wrapper of iTerm's Applescript scripting API. Methods are used to
|
5
5
|
# generate Applescript code which is run as an <tt>osascript</tt> command when the ItermWindow initialization
|
6
6
|
# block is closed.
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# ItermWindow::Tab models a tab (session) in an iTerm terminal window and allows for it to be controlled by Ruby.
|
9
9
|
# These tabs can be created with either the ItermWindow#open_bookmark method or the ItermWindow#open_tab
|
10
10
|
# method. Each tab is given a name (symbol) by which it can be accessed later as a method of ItermWindow.
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# EXAMPLE - Open a new iTerm window, cd to a project and open it in TextMate
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# ItermWindow.open do
|
15
15
|
# open_tab :my_tab do
|
16
16
|
# write "cd ~/projects/my_project/trunk"
|
17
17
|
# write "mate ./"
|
18
18
|
# end
|
19
19
|
# end
|
20
|
-
#
|
20
|
+
#
|
21
21
|
# EXAMPLE - Use the current iTerm window, cd to a project and open in TextMate, launch the server and the console and title them
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# ItermWindow.current do
|
24
24
|
# open_tab :project_dir do
|
25
25
|
# write "cd ~/projects/my_project/trunk"
|
26
26
|
# write "mate ./"
|
27
27
|
# set_title "MyProject Dir"
|
28
28
|
# end
|
29
|
-
#
|
30
|
-
#
|
29
|
+
#
|
30
|
+
# open_tab :server do
|
31
31
|
# write "cd ~/projects/my_project/trunk"
|
32
32
|
# write "script/server -p 3005"
|
33
33
|
# set_title "MyProject Server"
|
34
34
|
# end
|
35
|
-
#
|
35
|
+
#
|
36
|
+
# open_tab :console do
|
36
37
|
# write "cd ~/projects/my_project/trunk"
|
37
38
|
# write "script/console"
|
38
39
|
# set_title "MyProject Console"
|
@@ -40,18 +41,21 @@
|
|
40
41
|
# end
|
41
42
|
#
|
42
43
|
# EXAMPLE - Same thing, but use bookmarks that were made for the server and console. Also, switch focus back to project dir.
|
43
|
-
#
|
44
|
+
#
|
44
45
|
# ItermWindow.current do
|
45
46
|
# open_tab :project_dir do
|
46
47
|
# write "cd ~/projects/my_project/trunk"
|
47
48
|
# write "mate ./"
|
48
49
|
# end
|
50
|
+
#
|
49
51
|
# open_bookmark :server, 'MyProject Server'
|
50
52
|
# open_bookmark :console, 'MyProject Console'
|
53
|
+
#
|
51
54
|
# project_dir.select
|
52
|
-
#
|
55
|
+
# end
|
56
|
+
#
|
53
57
|
# EXAMPLE - Arbitrarily open two tabs, switch between them and run methods/blocks with Tab#select method and Tab#write directly
|
54
|
-
#
|
58
|
+
#
|
55
59
|
# ItermWindow.open do
|
56
60
|
# open_tab :first_tab
|
57
61
|
# open_tab :second_tab
|
@@ -66,51 +70,53 @@
|
|
66
70
|
|
67
71
|
# The ItermWindow class models an iTerm terminal window and allows for full control via Ruby commands.
|
68
72
|
class ItermWindow
|
69
|
-
|
70
|
-
# While you can directly use ItermWindow.new, using either ItermWindow.open or
|
73
|
+
|
74
|
+
# While you can directly use ItermWindow.new, using either ItermWindow.open or
|
71
75
|
# ItermWindow.current is the preferred method.
|
72
|
-
def initialize
|
76
|
+
def initialize
|
73
77
|
@buffer = []
|
74
78
|
@tabs = {}
|
75
|
-
run_commands window_type, &block
|
76
|
-
send_output
|
77
79
|
end
|
78
|
-
|
80
|
+
|
79
81
|
# Creates a new terminal window, runs the block on it
|
80
82
|
def self.open(&block)
|
81
|
-
new(:new, &block)
|
83
|
+
self.new.run(:new, &block)
|
82
84
|
end
|
83
|
-
|
85
|
+
|
84
86
|
# Selects the first terminal window, runs the block on it
|
85
87
|
def self.current(&block)
|
86
|
-
new(:current, &block)
|
88
|
+
self.new.run(:current, &block)
|
89
|
+
end
|
90
|
+
|
91
|
+
def run(window_type = :new, &block)
|
92
|
+
run_commands window_type, &block
|
93
|
+
send_output
|
87
94
|
end
|
88
|
-
|
95
|
+
|
89
96
|
# Creates a new tab from a bookmark, runs the block on it
|
90
97
|
def open_bookmark(name, bookmark, &block)
|
91
98
|
create_tab(name, bookmark, &block)
|
92
99
|
end
|
93
|
-
|
100
|
+
|
94
101
|
# Creates a new tab from 'Default Session', runs the block on it
|
95
102
|
def open_tab(name, &block)
|
96
103
|
create_tab(name, 'Default Session', &block)
|
97
104
|
end
|
98
|
-
|
105
|
+
|
99
106
|
# Outputs a single line of Applescript code
|
100
107
|
def output(command)
|
101
108
|
@buffer << command.gsub(/'/, '"')
|
102
109
|
end
|
103
|
-
|
104
|
-
|
110
|
+
|
111
|
+
|
105
112
|
private
|
106
|
-
|
113
|
+
|
107
114
|
# Outputs @buffer to the command line as an osascript function
|
108
115
|
def send_output
|
109
116
|
buffer_str = @buffer.map {|line| "-e '#{line}'"}.join(' ')
|
110
|
-
|
111
|
-
# puts buffer_str
|
117
|
+
shell_out "osascript #{buffer_str}"
|
112
118
|
end
|
113
|
-
|
119
|
+
|
114
120
|
# Initializes the terminal window
|
115
121
|
def run_commands(window_type, &block)
|
116
122
|
window_types = {:new => '(make new terminal)', :current => 'first terminal'}
|
@@ -123,25 +129,33 @@ class ItermWindow
|
|
123
129
|
output "end tell"
|
124
130
|
output "end tell"
|
125
131
|
end
|
126
|
-
|
127
|
-
# Creates a new Tab object, either default or from a bookmark
|
132
|
+
|
133
|
+
# Creates a new Tab object, either default or from a bookmark,
|
134
|
+
# and creates a convenience method for retrieval
|
128
135
|
def create_tab(name, bookmark=nil, &block)
|
129
136
|
@tabs[name] = Tab.new(self, name, bookmark, &block)
|
137
|
+
create_tab_convenience_method(name)
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
|
142
|
+
def create_tab_convenience_method(name)
|
143
|
+
(class << self; self; end).send(:define_method, name) do
|
144
|
+
@tabs[name]
|
145
|
+
end
|
130
146
|
end
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
@tabs[method_name] || super
|
147
|
+
|
148
|
+
def shell_out(str)
|
149
|
+
%x{str}
|
135
150
|
end
|
136
|
-
|
137
151
|
|
138
|
-
|
152
|
+
|
139
153
|
# The Tab class models a tab (session) in an iTerm terminal window and allows for it to be controlled by Ruby.
|
140
154
|
class Tab
|
141
|
-
|
155
|
+
|
142
156
|
attr_reader :name
|
143
157
|
attr_reader :bookmark
|
144
|
-
|
158
|
+
|
145
159
|
def initialize(window, name, bookmark = nil, &block)
|
146
160
|
@name = name
|
147
161
|
@bookmark = bookmark
|
@@ -152,7 +166,7 @@ class ItermWindow
|
|
152
166
|
output "set #{name}_tty to the tty of the last session"
|
153
167
|
execute_block &block if block_given?
|
154
168
|
end
|
155
|
-
|
169
|
+
|
156
170
|
# Brings a tab into focus, runs a block on it if passed
|
157
171
|
def select(&block)
|
158
172
|
if block_given?
|
@@ -161,7 +175,7 @@ class ItermWindow
|
|
161
175
|
output "select session id #{name}_tty"
|
162
176
|
end
|
163
177
|
end
|
164
|
-
|
178
|
+
|
165
179
|
# Writes a command into the terminal tab
|
166
180
|
def write(command)
|
167
181
|
if @currently_executing_block
|
@@ -170,7 +184,7 @@ class ItermWindow
|
|
170
184
|
execute_block { write command }
|
171
185
|
end
|
172
186
|
end
|
173
|
-
|
187
|
+
|
174
188
|
# Sets the title of the tab (ie the text on the iTerm tab itself)
|
175
189
|
def set_title(str)
|
176
190
|
if @currently_executing_block
|
@@ -179,37 +193,7 @@ class ItermWindow
|
|
179
193
|
execute_block { set_title = str }
|
180
194
|
end
|
181
195
|
end
|
182
|
-
|
183
|
-
# These style methods keep crashing iTerm for some reason...
|
184
|
-
|
185
|
-
# # Sets the tab's font color
|
186
|
-
# def set_font_color(str)
|
187
|
-
# if @currently_executing_block
|
188
|
-
# output "set foreground color to '#{str}'"
|
189
|
-
# else
|
190
|
-
# execute_block { set_font_color = str }
|
191
|
-
# end
|
192
|
-
# end
|
193
|
-
#
|
194
|
-
# # Sets the tab's background color
|
195
|
-
# def set_background_color(str)
|
196
|
-
# if @currently_executing_block
|
197
|
-
# output "set background color to '#{str}'"
|
198
|
-
# else
|
199
|
-
# execute_block { set_bg_color = str }
|
200
|
-
# end
|
201
|
-
# end
|
202
|
-
# alias_method :set_bg_color, :set_background_color
|
203
|
-
#
|
204
|
-
# # Sets the tab's transparency
|
205
|
-
# def set_transparency(float)
|
206
|
-
# if @currently_executing_block
|
207
|
-
# output "set transparency to '#{float}'"
|
208
|
-
# else
|
209
|
-
# execute_block { set_transparency = float }
|
210
|
-
# end
|
211
|
-
# end
|
212
|
-
|
196
|
+
|
213
197
|
# Runs a block on this tab with proper opening and closing statements
|
214
198
|
def execute_block(&block)
|
215
199
|
@currently_executing_block = true
|
@@ -218,14 +202,14 @@ class ItermWindow
|
|
218
202
|
output "end tell"
|
219
203
|
@currently_executing_block = false
|
220
204
|
end
|
221
|
-
|
205
|
+
|
222
206
|
private
|
223
|
-
|
207
|
+
|
224
208
|
def output(command)
|
225
209
|
@window.output command
|
226
210
|
end
|
227
211
|
|
228
|
-
|
212
|
+
|
229
213
|
end
|
230
|
-
|
214
|
+
|
231
215
|
end
|
metadata
CHANGED
@@ -1,57 +1,48 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: iterm_window
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.4
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
+
authors:
|
7
8
|
- Chris Powers
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
|
12
|
-
date: 2009-02-20 00:00:00 -06:00
|
13
|
-
default_executable:
|
12
|
+
date: 2009-02-20 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
|
-
|
16
14
|
description:
|
17
15
|
email: chrisjpowers@gmail.com
|
18
16
|
executables: []
|
19
|
-
|
20
17
|
extensions: []
|
21
|
-
|
22
18
|
extra_rdoc_files: []
|
23
|
-
|
24
|
-
files:
|
19
|
+
files:
|
25
20
|
- README.rdoc
|
26
21
|
- LICENSE
|
27
22
|
- lib/iterm_window.rb
|
28
|
-
has_rdoc: true
|
29
23
|
homepage: http://github.com/chrisjpowers/iterm_window
|
30
24
|
licenses: []
|
31
|
-
|
32
25
|
post_install_message:
|
33
26
|
rdoc_options: []
|
34
|
-
|
35
|
-
require_paths:
|
27
|
+
require_paths:
|
36
28
|
- lib
|
37
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
49
41
|
requirements: []
|
50
|
-
|
51
42
|
rubyforge_project:
|
52
|
-
rubygems_version: 1.
|
43
|
+
rubygems_version: 1.8.24
|
53
44
|
signing_key:
|
54
45
|
specification_version: 3
|
55
|
-
summary: The ItermWindow class models an iTerm terminal window and allows for full
|
46
|
+
summary: The ItermWindow class models an iTerm terminal window and allows for full
|
47
|
+
control via Ruby commands.
|
56
48
|
test_files: []
|
57
|
-
|