iterm2_ruby 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +23 -0
- data/Gemfile +10 -0
- data/LICENSE +21 -0
- data/README.md +265 -0
- data/Rakefile +7 -0
- data/bin/iterm2ctl +620 -0
- data/docs/api.md +523 -0
- data/docs/architecture.md +91 -0
- data/docs/cli.md +257 -0
- data/iterm2_ruby.gemspec +29 -0
- data/lib/iterm2/client.rb +690 -0
- data/lib/iterm2/connection.rb +267 -0
- data/lib/iterm2/proto/api_pb.rb +233 -0
- data/lib/iterm2/session.rb +44 -0
- data/lib/iterm2/tab.rb +39 -0
- data/lib/iterm2/version.rb +5 -0
- data/lib/iterm2/window.rb +33 -0
- data/lib/iterm2.rb +106 -0
- data/llms.txt +114 -0
- data/proto/api.proto +1642 -0
- metadata +82 -0
data/docs/cli.md
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# CLI Reference
|
|
2
|
+
|
|
3
|
+
Complete reference for `iterm2ctl`, the command-line interface.
|
|
4
|
+
|
|
5
|
+
## Global Options
|
|
6
|
+
|
|
7
|
+
These flags work with most commands:
|
|
8
|
+
|
|
9
|
+
| Flag | Description |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `--session ID` | Target a specific session by ID |
|
|
12
|
+
| `--tab ID` | Target a specific tab by ID |
|
|
13
|
+
| `--window ID` | Target a specific window by ID |
|
|
14
|
+
| `--json` | Output as JSON (where supported) |
|
|
15
|
+
|
|
16
|
+
When no target is specified, most commands default to the first session.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Commands
|
|
21
|
+
|
|
22
|
+
### `list`
|
|
23
|
+
|
|
24
|
+
List all windows, tabs, and sessions.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
iterm2ctl list # table: window, tab, session, title
|
|
28
|
+
iterm2ctl list --with-cwd # add working directory column
|
|
29
|
+
iterm2ctl list --with-pid # add PID column
|
|
30
|
+
iterm2ctl list --with-cwd --with-pid # both
|
|
31
|
+
iterm2ctl list --json # JSON array output
|
|
32
|
+
iterm2ctl list --triage # compact: window/tab/session/cwd/job
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`--with-cwd`, `--with-pid`, and `--triage` all trigger enriched topology (one RPC per session -- slower with many sessions).
|
|
36
|
+
|
|
37
|
+
### `tabs`
|
|
38
|
+
|
|
39
|
+
List tabs grouped by window.
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
iterm2ctl tabs # window -> tab -> session count/title
|
|
43
|
+
iterm2ctl tabs --json # JSON output
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### `send`
|
|
47
|
+
|
|
48
|
+
Send text to a session as if typed. Auto-appends `\n` if not present.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
iterm2ctl send "echo hello" # sends to first session
|
|
52
|
+
iterm2ctl send "ls -la" --session E8F2... # sends to specific session
|
|
53
|
+
iterm2ctl send "make test" # newline auto-appended
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### `send-text`
|
|
57
|
+
|
|
58
|
+
Send text to a specific session by ID (positional, no `--session` flag).
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
iterm2ctl send-text E8F2... "echo hello"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### `read`
|
|
65
|
+
|
|
66
|
+
Read visible screen contents.
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
iterm2ctl read # visible screen, first session
|
|
70
|
+
iterm2ctl read --session E8F2... # specific session
|
|
71
|
+
iterm2ctl read --scrollback 200 # include 200 lines of scrollback
|
|
72
|
+
iterm2ctl read --json # JSON with lines array + cursor
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### `read-screen`
|
|
76
|
+
|
|
77
|
+
Read the screen for a specific session by ID (positional, no `--session` flag).
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
iterm2ctl read-screen E8F2... # visible screen
|
|
81
|
+
iterm2ctl read-screen E8F2... --scrollback 200 # include scrollback
|
|
82
|
+
iterm2ctl read-screen E8F2... --json # JSON output
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### `raise`
|
|
86
|
+
|
|
87
|
+
Raise (focus) a tab by title pattern or working directory.
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
iterm2ctl raise "my-project" # title pattern (case-insensitive regex)
|
|
91
|
+
iterm2ctl raise --cwd "/work/myproject" # match by working directory
|
|
92
|
+
iterm2ctl raise --session E8F2... # raise specific session by ID
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### `activate-session`
|
|
96
|
+
|
|
97
|
+
Activate (raise and focus) a session by ID directly (positional, no `--session` flag).
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
iterm2ctl activate-session E8F2...
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### `create`
|
|
104
|
+
|
|
105
|
+
Create a new tab or window.
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
iterm2ctl create tab # new tab in current window
|
|
109
|
+
iterm2ctl create window # new window
|
|
110
|
+
iterm2ctl create tab --window W123... # new tab in specific window
|
|
111
|
+
iterm2ctl create tab --profile "Custom" # new tab with profile
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### `split`
|
|
115
|
+
|
|
116
|
+
Split the current pane.
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
iterm2ctl split # vertical split, first session
|
|
120
|
+
iterm2ctl split --session E8F2... # split specific session
|
|
121
|
+
iterm2ctl split --horizontal # horizontal split
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### `close`
|
|
125
|
+
|
|
126
|
+
Close a session or tab.
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
iterm2ctl close # close first session
|
|
130
|
+
iterm2ctl close --session E8F2... # close specific session
|
|
131
|
+
iterm2ctl close --tab T456... # close entire tab
|
|
132
|
+
iterm2ctl close --force # skip confirmation
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### `move`
|
|
136
|
+
|
|
137
|
+
Move a tab to another window.
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
iterm2ctl move --tab T456... --to-window W789... # move tab to target window
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Appends the tab to the end of the target window's tab bar. Uses `reorder_tabs` under the hood.
|
|
144
|
+
|
|
145
|
+
### `var`
|
|
146
|
+
|
|
147
|
+
Get and set iTerm2 variables.
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
iterm2ctl var get path --session E8F2... # get a variable
|
|
151
|
+
iterm2ctl var set user.project myapp --session E8F2... # set a user variable
|
|
152
|
+
iterm2ctl var all --session E8F2... # dump all variables
|
|
153
|
+
iterm2ctl var all --json # JSON output
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Variable scope defaults to the first session. Use `--tab` or `--window` for other scopes.
|
|
157
|
+
|
|
158
|
+
**Note:** Only `user.*` variables can be set.
|
|
159
|
+
|
|
160
|
+
### `info`
|
|
161
|
+
|
|
162
|
+
Show session details (tty, pid, cwd, name, job).
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
iterm2ctl info # first session
|
|
166
|
+
iterm2ctl info --session E8F2... # specific session
|
|
167
|
+
iterm2ctl info --json # JSON output
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### `focus`
|
|
171
|
+
|
|
172
|
+
Show current focus state (active session, tab, window, app status).
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
iterm2ctl focus # table output
|
|
176
|
+
iterm2ctl focus --json # JSON output
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### `prompt`
|
|
180
|
+
|
|
181
|
+
Show shell prompt state (requires iTerm2 shell integration).
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
iterm2ctl prompt # first session
|
|
185
|
+
iterm2ctl prompt --session E8F2... # specific session
|
|
186
|
+
iterm2ctl prompt --json # JSON output
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
States: `editing` (at prompt), `running` (command executing), `at_prompt` (idle), `unavailable` (no shell integration).
|
|
190
|
+
|
|
191
|
+
### `watch`
|
|
192
|
+
|
|
193
|
+
Watch for real-time events. Outputs one JSON object per line.
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
iterm2ctl watch # all events (focus + sessions + layout)
|
|
197
|
+
iterm2ctl watch focus # focus changes only
|
|
198
|
+
iterm2ctl watch sessions # new session + terminated events
|
|
199
|
+
iterm2ctl watch prompt --session E8F2... # prompt state changes (requires session)
|
|
200
|
+
iterm2ctl watch screen --session E8F2... # screen updates (requires session)
|
|
201
|
+
iterm2ctl watch layout # layout changes
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Press `Ctrl+C` to stop watching.
|
|
205
|
+
|
|
206
|
+
### `profile`
|
|
207
|
+
|
|
208
|
+
Get profile properties for a session.
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
iterm2ctl profile --session E8F2... # all properties
|
|
212
|
+
iterm2ctl profile Name Guid --session E8F2... # specific keys
|
|
213
|
+
iterm2ctl profile --json # JSON output
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### `profiles`
|
|
217
|
+
|
|
218
|
+
List all iTerm2 profiles.
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
iterm2ctl profiles # name + GUID list
|
|
222
|
+
iterm2ctl profiles --properties Name,Guid # specific properties only
|
|
223
|
+
iterm2ctl profiles --json # JSON output
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### `inject`
|
|
227
|
+
|
|
228
|
+
Inject data into a session as if it came from the running process.
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
iterm2ctl inject "Hello from outside" --session E8F2...
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### `version`
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
iterm2ctl version # => iterm2ctl 0.2.0
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### `help`
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
iterm2ctl help # show usage summary
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Exit Codes
|
|
249
|
+
|
|
250
|
+
| Code | Meaning |
|
|
251
|
+
|---|---|
|
|
252
|
+
| 0 | Success |
|
|
253
|
+
| 1 | Usage error or unknown command |
|
|
254
|
+
| 2 | Connection error (iTerm2 not running or API disabled) |
|
|
255
|
+
| 3 | Authentication error (osascript failed) |
|
|
256
|
+
| 4 | Not found (no session matching pattern) |
|
|
257
|
+
| 5 | RPC error (iTerm2 returned an error) |
|
data/iterm2_ruby.gemspec
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/iterm2/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "iterm2_ruby"
|
|
7
|
+
spec.version = ITerm2::VERSION
|
|
8
|
+
spec.authors = ["Forrest Chang"]
|
|
9
|
+
spec.summary = "Ruby bindings for iTerm2's native WebSocket+Protobuf API"
|
|
10
|
+
spec.description = "Control iTerm2 via its native API: list sessions, send text, read screens, and raise tabs, all without osascript."
|
|
11
|
+
spec.homepage = "https://github.com/fkchang/iterm2_ruby"
|
|
12
|
+
spec.license = "MIT"
|
|
13
|
+
spec.required_ruby_version = ">= 3.1"
|
|
14
|
+
|
|
15
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
16
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
|
17
|
+
spec.metadata["bug_tracker_uri"] = "#{spec.homepage}/issues"
|
|
18
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
19
|
+
|
|
20
|
+
spec.files = Dir["lib/**/*.rb", "bin/*", "proto/*.proto", "README.md", "CHANGELOG.md", "LICENSE", "*.gemspec", "Gemfile", "Rakefile", "llms.txt", "docs/**/*.md"]
|
|
21
|
+
spec.bindir = "bin"
|
|
22
|
+
spec.executables = ["iterm2ctl"]
|
|
23
|
+
|
|
24
|
+
# Required for encoding/decoding iTerm2 API protobuf frames.
|
|
25
|
+
spec.add_dependency "google-protobuf", "~> 4.0"
|
|
26
|
+
|
|
27
|
+
# WebSocket framing is hand-rolled in lib/iterm2/connection.rb, so no websocket gem is required.
|
|
28
|
+
# base64/ostruct are stdlib in modern Ruby and intentionally not listed as gem dependencies.
|
|
29
|
+
end
|