libtmux-workspace 0.1.1 → 0.1.3
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 +4 -4
- data/CHANGELOG.md +62 -0
- data/README.md +123 -79
- data/lib/libtmux/workspace/apply.rb +19 -6
- data/lib/libtmux/workspace/cli.rb +76 -16
- data/lib/libtmux/workspace/normalizer.rb +21 -7
- data/lib/libtmux/workspace/version.rb +1 -1
- metadata +22 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3625d967b7c3ec20bf317e01a55fac932785afb2beb696cd89df6f3e3dc82f01
|
|
4
|
+
data.tar.gz: 4221145fededd61e039bca57d4b09a15055c4f10acdf41ae265aa5da9b9ff345
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad04686adb1594089b5dfd11abae5c3f97be897e6767a43bb85e3a8ed214752eb9a6a57d66ef7206a5263ff590f38b1a5d568f488fa8aca71e0e1bf835bf24e8
|
|
7
|
+
data.tar.gz: 7c5c575a4d5f54c660a1b8dde99cb44215e87be16e99b94b87c13ec5db456f26b3441d02450cb39a2662748842a11aba7548633171bc1c5d493a4c3abc4686df
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Notable changes to `libtmux-workspace`.
|
|
4
|
+
|
|
5
|
+
Releases are numbered `0.1.N`, and each release increments `N`. The API is not
|
|
6
|
+
settled: pin an exact version to avoid a break.
|
|
7
|
+
|
|
8
|
+
The gems are released together at one version, so every release has a section
|
|
9
|
+
here. Changes that span gems, such as documentation, CI and release tooling, are
|
|
10
|
+
in the [main changelog](../../CHANGELOG.md).
|
|
11
|
+
|
|
12
|
+
## 0.1.4 (unreleased)
|
|
13
|
+
|
|
14
|
+
## 0.1.3 (2026-12-05)
|
|
15
|
+
|
|
16
|
+
- Workspace load errors identify the pane and failed directory check without
|
|
17
|
+
disclosing the resolved path. (#177)
|
|
18
|
+
- Workspace directories inherit from the containing session and window. A
|
|
19
|
+
leading tilde expands from the HOME supplied for the workspace. (#179)
|
|
20
|
+
- **Behavior change:** a pane written as `pane` or `blank`, or with a
|
|
21
|
+
`shell_command` that is only `pane` or `blank`, is now a pane with nothing to
|
|
22
|
+
run, as in tmuxp's blank-pane example. It was a pane that typed the word
|
|
23
|
+
`pane` or `blank` into its shell.
|
|
24
|
+
|
|
25
|
+
## 0.1.2 (2026-11-04)
|
|
26
|
+
|
|
27
|
+
No entries for `libtmux-workspace`.
|
|
28
|
+
|
|
29
|
+
## 0.1.1 (2026-10-31)
|
|
30
|
+
|
|
31
|
+
- **Behavior change:** `libtmux-workspace load` and `plan --live` no longer
|
|
32
|
+
need `--socket`. Without it they use the same choice as `Server.new`, so a
|
|
33
|
+
command that failed with status 2 for a missing socket now acts on the
|
|
34
|
+
server tmux would pick. (#71)
|
|
35
|
+
|
|
36
|
+
## 0.1.0 (2026-10-25)
|
|
37
|
+
|
|
38
|
+
No entries for `libtmux-workspace`.
|
|
39
|
+
|
|
40
|
+
## 0.1.0.alpha.3 (2026-10-24)
|
|
41
|
+
|
|
42
|
+
No entries for `libtmux-workspace`.
|
|
43
|
+
|
|
44
|
+
## 0.1.0.alpha.2 (2026-10-18)
|
|
45
|
+
|
|
46
|
+
No entries for `libtmux-workspace`.
|
|
47
|
+
|
|
48
|
+
## 0.1.0.alpha.1 (2026-09-20)
|
|
49
|
+
|
|
50
|
+
### libtmux-workspace
|
|
51
|
+
|
|
52
|
+
- Load YAML or JSON with `LibTmux::Workspace.load` or `.parse`, inspect a
|
|
53
|
+
creation plan, then apply it explicitly. Supports the documented subset of
|
|
54
|
+
tmuxp-style configuration. [Workspace example](../../examples/workspace_apply.rb).
|
|
55
|
+
- Validate, plan and load from the `libtmux-workspace` CLI; optionally attach
|
|
56
|
+
or switch an explicit client after creation. `--version` reports the
|
|
57
|
+
installed gem version without reading a configuration or contacting tmux.
|
|
58
|
+
[CLI guide](../../gems/libtmux-workspace/README.md#script-it).
|
|
59
|
+
- Inspect partial application through `ApplyError#result`. Optional
|
|
60
|
+
compensation removes only a positively identified new session after
|
|
61
|
+
checking that its windows and panes belong to the apply operation.
|
|
62
|
+
[Failure results](../../gems/libtmux-workspace/README.md#recover-from-a-failed-apply).
|
data/README.md
CHANGED
|
@@ -20,8 +20,10 @@
|
|
|
20
20
|
[Guides](https://libtmux.org/en/ruby/latest/workspace/guides/) ·
|
|
21
21
|
[RubyGems](https://rubygems.org/gems/libtmux-workspace)
|
|
22
22
|
|
|
23
|
-
[](https://github.com/libtmux/libtmux-ruby/actions/workflows/compatibility.yml)
|
|
24
24
|
[](https://rubygems.org/gems/libtmux-workspace)
|
|
25
|
+
[](https://libtmux.org/en/ruby/latest/workspace/)
|
|
26
|
+
[](https://github.com/libtmux/libtmux-ruby/blob/master/LICENSE)
|
|
25
27
|
|
|
26
28
|
</div>
|
|
27
29
|
|
|
@@ -30,15 +32,13 @@ Built on [libtmux](https://github.com/libtmux/libtmux-ruby/tree/master/gems/libt
|
|
|
30
32
|
|
|
31
33
|
Check a workspace file, see the ordered steps a load would run, and create the
|
|
32
34
|
session on a running tmux server, from the `libtmux-workspace` command or from
|
|
33
|
-
Ruby.
|
|
34
|
-
|
|
35
|
-
Validation and offline planning need no running daemon, and imports start no
|
|
36
|
-
tmux process.
|
|
35
|
+
Ruby. Importing the Ruby library starts no tmux process.
|
|
37
36
|
|
|
38
37
|
**Contents** — [Quick start](#quick-start) ·
|
|
39
38
|
[Write the file](#write-the-file) ·
|
|
40
39
|
[Create the session](#create-the-session) ·
|
|
41
40
|
[Failed apply](#recover-from-a-failed-apply) ·
|
|
41
|
+
[Rejoin](#attach-to-an-existing-session) ·
|
|
42
42
|
[Attach or switch](#attach-or-switch-to-the-new-session) ·
|
|
43
43
|
[Scripts](#script-it) · [Leaves out](#what-it-leaves-out) ·
|
|
44
44
|
[Support](#support-and-status) · [Documentation](#documentation)
|
|
@@ -52,8 +52,7 @@ newer, and tmux 3.3a or newer to load a plan:
|
|
|
52
52
|
$ gem install libtmux-workspace
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
Save this
|
|
56
|
-
directories resolve against the configuration file's directory.
|
|
55
|
+
Save this workspace configuration as `workspace.yaml`.
|
|
57
56
|
|
|
58
57
|
<!-- example: workspace/config -->
|
|
59
58
|
```yaml
|
|
@@ -70,7 +69,7 @@ windows:
|
|
|
70
69
|
```
|
|
71
70
|
<!-- /example -->
|
|
72
71
|
|
|
73
|
-
Check the file
|
|
72
|
+
Check the file:
|
|
74
73
|
|
|
75
74
|
```console
|
|
76
75
|
$ libtmux-workspace validate workspace.yaml
|
|
@@ -80,8 +79,7 @@ $ libtmux-workspace validate workspace.yaml
|
|
|
80
79
|
Workspace configuration is valid.
|
|
81
80
|
```
|
|
82
81
|
|
|
83
|
-
Print the ordered operations a load would run
|
|
84
|
-
not contact tmux either:
|
|
82
|
+
Print the ordered operations a load would run:
|
|
85
83
|
|
|
86
84
|
```console
|
|
87
85
|
$ libtmux-workspace plan workspace.yaml
|
|
@@ -102,6 +100,21 @@ offline_create: 11 ordered steps
|
|
|
102
100
|
11. unset_session_option session (configuration)
|
|
103
101
|
```
|
|
104
102
|
|
|
103
|
+
| Command | What it checks |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| [`validate`][cli-validate] | Reads and normalizes the configuration, including path syntax. Needs no tmux server. |
|
|
106
|
+
| [`plan`][cli-plan] | Builds the ordered creation steps from the configuration. Needs no tmux server. |
|
|
107
|
+
| [`plan --live`][cli-plan] | Builds the steps against a snapshot of a running server and checks for a session name conflict. |
|
|
108
|
+
| [`load`][cli-load] | Checks the server and requires each planned pane directory to exist and be searchable before creating the session. |
|
|
109
|
+
|
|
110
|
+
At the workspace root, `start_directory: src` resolves next to the file. If
|
|
111
|
+
`src` is missing, validation and both plans can succeed. Load exits with
|
|
112
|
+
status 1 before creating the session.
|
|
113
|
+
|
|
114
|
+
Load errors omit filesystem paths. Use [`plan --json`](#script-it) to inspect
|
|
115
|
+
the normalized pane directories in `steps[].arguments.cwd`. Create the missing
|
|
116
|
+
directory or correct `start_directory`, then retry the load.
|
|
117
|
+
|
|
105
118
|
## Write the file
|
|
106
119
|
|
|
107
120
|
### [`Workspace.load`][workspace-load]: the declared subset
|
|
@@ -116,6 +129,9 @@ directory instead. Both return an immutable workspace:
|
|
|
116
129
|
- Pane: a command string, or a mapping with `focus`, `split` and `size`.
|
|
117
130
|
- Root, windows and panes accept `start_directory`, `environment`,
|
|
118
131
|
`shell_command` and `shell_command_before`.
|
|
132
|
+
- A relative `start_directory` starts from its parent's directory. At the
|
|
133
|
+
root it starts from the file or parse base directory. For `~` or `~/path`,
|
|
134
|
+
pass an absolute `HOME` in `environment:` or supply `--env HOME=PATH`.
|
|
119
135
|
- Layouts are `even-horizontal`, `even-vertical`, `main-horizontal`,
|
|
120
136
|
`main-vertical` and `tiled`.
|
|
121
137
|
- At most one window and one pane per window declare focus.
|
|
@@ -134,26 +150,31 @@ directory instead. Both return an immutable workspace:
|
|
|
134
150
|
The full field, option and limit lists are in
|
|
135
151
|
[Workspace parsing][behavior-workspace-parsing].
|
|
136
152
|
|
|
153
|
+
For a blank pane in a tmuxp migration, specify the session and window names
|
|
154
|
+
and set `panes: [{}]` in the window. The [tmuxp syntax record][tmuxp-syntax]
|
|
155
|
+
covers configuration shorthands and command compatibility.
|
|
156
|
+
|
|
157
|
+
The [`load` command][cli-load] takes one file.
|
|
158
|
+
|
|
137
159
|
## Create the session
|
|
138
160
|
|
|
139
161
|
### [`libtmux-workspace load`][cli-load]: build it on a running server
|
|
140
162
|
|
|
141
|
-
`
|
|
142
|
-
|
|
163
|
+
Set `TMUX_SOCKET` to the socket of a running tmux server that has no `work`
|
|
164
|
+
session. Run [a live plan][cli-plan] to check that server for a name conflict:
|
|
143
165
|
|
|
144
166
|
```console
|
|
145
|
-
$
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
$ tmux -S "$WORKSPACE_TMP/tmux.sock" -f /dev/null new-session -d -s keepalive
|
|
167
|
+
$ libtmux-workspace plan \
|
|
168
|
+
--live \
|
|
169
|
+
--socket "$TMUX_SOCKET" \
|
|
170
|
+
workspace.yaml
|
|
150
171
|
```
|
|
151
172
|
|
|
152
|
-
|
|
173
|
+
The plan begins with `captured_create`. Now create the detached session:
|
|
153
174
|
|
|
154
175
|
```console
|
|
155
176
|
$ libtmux-workspace load \
|
|
156
|
-
--socket "$
|
|
177
|
+
--socket "$TMUX_SOCKET" \
|
|
157
178
|
workspace.yaml
|
|
158
179
|
```
|
|
159
180
|
|
|
@@ -161,50 +182,57 @@ $ libtmux-workspace load \
|
|
|
161
182
|
Workspace created; 11 steps completed. Shell commands were dispatched.
|
|
162
183
|
```
|
|
163
184
|
|
|
164
|
-
The new `work` session holds the `editor` window:
|
|
165
|
-
|
|
166
|
-
```console
|
|
167
|
-
$ tmux -S "$WORKSPACE_TMP/tmux.sock" list-windows -t work
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
Stop only the private server and remove its directory:
|
|
171
|
-
|
|
172
|
-
```console
|
|
173
|
-
$ tmux -S "$WORKSPACE_TMP/tmux.sock" kill-server
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
```console
|
|
177
|
-
$ rm -rf "$WORKSPACE_TMP"
|
|
178
|
-
```
|
|
179
|
-
|
|
180
185
|
Loading the same file again fails with status 1: a plan creates a new session
|
|
181
|
-
and never reconciles an existing one.
|
|
186
|
+
and never reconciles an existing one. To try the same without a server of your
|
|
187
|
+
own, run the Ruby program below, which starts and stops its own.
|
|
182
188
|
|
|
183
189
|
### [`Plan#apply`][workspace-plan-apply]: the same from Ruby
|
|
184
190
|
|
|
185
191
|
[`Workspace.load`][workspace-load] reads the file,
|
|
186
192
|
[`workspace.plan`][workspace-plan-method] plans it against a snapshot, and
|
|
187
193
|
`apply` creates the session. Calling `apply` authorizes the configuration's
|
|
188
|
-
shell commands
|
|
194
|
+
shell commands.
|
|
195
|
+
|
|
196
|
+
[The example file](../../examples/api/workspace_apply.rb) writes the same
|
|
197
|
+
document to a temporary `workspace.yaml` before loading it, so it runs saved on
|
|
198
|
+
its own:
|
|
189
199
|
|
|
190
200
|
<!-- example: api_workspace_apply/main -->
|
|
191
201
|
```ruby
|
|
192
202
|
require "libtmux"
|
|
193
203
|
require "libtmux/workspace"
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
204
|
+
require "tmpdir"
|
|
205
|
+
|
|
206
|
+
document = <<~'YAML'
|
|
207
|
+
session_name: work
|
|
208
|
+
environment:
|
|
209
|
+
PROJECT_MODE: development
|
|
210
|
+
windows:
|
|
211
|
+
- window_name: editor
|
|
212
|
+
window_index: 1
|
|
213
|
+
layout: tiled
|
|
214
|
+
panes:
|
|
215
|
+
- shell_command: printf 'editor ready\n'
|
|
216
|
+
- {}
|
|
217
|
+
YAML
|
|
218
|
+
|
|
219
|
+
Dir.mktmpdir("workspace-") do |directory|
|
|
220
|
+
path = File.join(directory, "workspace.yaml")
|
|
221
|
+
File.write(path, document)
|
|
222
|
+
LibTmux::Server.start do |server|
|
|
223
|
+
workspace = LibTmux::Workspace.load(path)
|
|
224
|
+
plan = workspace.plan(snapshot: server.snapshot)
|
|
225
|
+
puts "planned steps: #{plan.steps.length}"
|
|
226
|
+
result = plan.apply(server: server)
|
|
227
|
+
puts "applied: #{result.success?}"
|
|
228
|
+
sessions = server.list_sessions.map { |session| session.snapshot.name }
|
|
229
|
+
puts "sessions: #{sessions.join(', ')}"
|
|
230
|
+
end
|
|
202
231
|
end
|
|
203
232
|
```
|
|
204
233
|
<!-- /example -->
|
|
205
234
|
|
|
206
|
-
The program runs
|
|
207
|
-
prints:
|
|
235
|
+
The program runs on a private server and prints:
|
|
208
236
|
|
|
209
237
|
```text
|
|
210
238
|
planned steps: 11
|
|
@@ -241,10 +269,10 @@ require "libtmux/workspace"
|
|
|
241
269
|
|
|
242
270
|
LibTmux::Server.start do |server|
|
|
243
271
|
server.new_session(name: "borrowed", command: ["/bin/cat"])
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
272
|
+
document = {session_name: "crowded",
|
|
273
|
+
windows: [{window_name: "small", panes: Array.new(40) { {} }}]}
|
|
274
|
+
crowded = LibTmux::Workspace.parse(JSON.generate(document),
|
|
275
|
+
format: :json, base_directory: __dir__)
|
|
248
276
|
begin
|
|
249
277
|
crowded.plan.apply(server: server, compensate: true)
|
|
250
278
|
rescue LibTmux::Workspace::ApplyError => error
|
|
@@ -252,7 +280,8 @@ LibTmux::Server.start do |server|
|
|
|
252
280
|
puts "created a session: #{error.result.created_refs.key?('session')}"
|
|
253
281
|
puts "compensation: #{error.result.compensation}"
|
|
254
282
|
end
|
|
255
|
-
|
|
283
|
+
sessions = server.list_sessions.map { |session| session.snapshot.name }
|
|
284
|
+
puts "sessions: #{sessions.join(', ')}"
|
|
256
285
|
end
|
|
257
286
|
```
|
|
258
287
|
<!-- /example -->
|
|
@@ -269,22 +298,37 @@ sessions: borrowed
|
|
|
269
298
|
|
|
270
299
|
- Compensation removes the new session only after a tmux guard shows that
|
|
271
300
|
every window and pane in it has a positively identified created reference.
|
|
272
|
-
|
|
301
|
+
An unknown initial entity, or a borrowed entity moved into the session,
|
|
273
302
|
makes it refuse.
|
|
274
303
|
- Compensation cannot undo what shell commands did. Without it, the partial
|
|
275
304
|
state stays for you to inspect.
|
|
276
305
|
- Diagnostics omit command payloads and paths. Names are never used to guess
|
|
277
306
|
ownership.
|
|
278
307
|
|
|
308
|
+
If apply fails at `check_directories`, check the indicated pane's
|
|
309
|
+
`start_directory` and any inherited setting. The error's `path` field gives
|
|
310
|
+
the pane's zero-based position in both Ruby and JSON output.
|
|
311
|
+
|
|
279
312
|
The command takes `--compensate`. The contracts are in
|
|
280
313
|
[Workspace results][behavior-workspace-results].
|
|
281
314
|
|
|
315
|
+
## Attach to an existing session
|
|
316
|
+
|
|
317
|
+
Run [`libtmux-workspace attach`][workspace-cli] from an interactive terminal with
|
|
318
|
+
`TERM` set. Use `--socket "$TMUX_SOCKET" '$1'`, substituting the session ID
|
|
319
|
+
from the load result. Keep the quotes to preserve the dollar sign.
|
|
320
|
+
|
|
321
|
+
If `load --attach` returns 3 with `result.success: true` and
|
|
322
|
+
`error.phase: "terminal"`, use `result.created_refs.session.id` with the
|
|
323
|
+
same socket to join the session already created.
|
|
324
|
+
|
|
282
325
|
## Attach or switch to the new session
|
|
283
326
|
|
|
284
327
|
### [`load --switch`][cli-load]: move a client to the session
|
|
285
328
|
|
|
286
|
-
- `load --attach`
|
|
287
|
-
|
|
329
|
+
- `load --attach` runs a terminal client after creation and waits for you to
|
|
330
|
+
detach. It requires `TERM` and the same terminal on stdin and stdout, with
|
|
331
|
+
at least one stream open for reading and writing.
|
|
288
332
|
- `load --switch CLIENT` switches a current tmux client to the created session
|
|
289
333
|
after apply, keeping the session's environment.
|
|
290
334
|
- `CLIENT` is a client name, a full TTY path or a TTY path without `/dev/`.
|
|
@@ -317,13 +361,13 @@ $ libtmux-workspace plan \
|
|
|
317
361
|
workspace.yaml
|
|
318
362
|
```
|
|
319
363
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
`
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
364
|
+
Without `--socket`, load and live planning use the socket in
|
|
365
|
+
`LIBTMUX_SOCKET_PATH`, else the name in `LIBTMUX_SOCKET`, else the server
|
|
366
|
+
`TMUX` names when run inside tmux, else tmux's default socket.
|
|
367
|
+
|
|
368
|
+
When both variables are set, the path wins. An empty variable counts as unset,
|
|
369
|
+
and `--socket` ignores both. This example loads into the server
|
|
370
|
+
`TMUX_SOCKET` names:
|
|
327
371
|
|
|
328
372
|
```console
|
|
329
373
|
$ libtmux-workspace load \
|
|
@@ -337,15 +381,15 @@ $ libtmux-workspace load \
|
|
|
337
381
|
|
|
338
382
|
| Option | Effect |
|
|
339
383
|
| --- | --- |
|
|
340
|
-
| `--json` | Write one structured result or error object to stdout |
|
|
341
|
-
| `--socket PATH` | Select the existing server's socket for `load
|
|
384
|
+
| `--json` | Write one structured result or error object to stdout for `validate`, `plan` or `load` |
|
|
385
|
+
| `--socket PATH` | Select the existing server's socket for `load`, `plan --live` or `attach`; required for `attach`, otherwise defaults to the socket variables, then `TMUX`, then tmux's default socket |
|
|
342
386
|
| `--live` | Capture a snapshot before planning |
|
|
343
|
-
| `--timeout SECONDS` | Bound each apply, live capture or
|
|
387
|
+
| `--timeout SECONDS` | Bound each apply, live capture, switch or attach session lookup; the default is 5 |
|
|
344
388
|
| `--compensate` | Run guarded cleanup after an apply failure |
|
|
345
389
|
| `--attach` | Attach this CLI's terminal after a successful `load` |
|
|
346
390
|
| `--switch CLIENT` | Switch an explicit current client to the new session after `load` |
|
|
347
391
|
| `--expand-environment` | Expand `${NAME}` in directories and environment values; requires `--env` |
|
|
348
|
-
| `--env NAME=VALUE` | Supply a value for
|
|
392
|
+
| `--env NAME=VALUE` | Supply a value for substitution or an absolute `HOME` for `~` in `start_directory` |
|
|
349
393
|
|
|
350
394
|
| Exit status | Meaning |
|
|
351
395
|
| --- | --- |
|
|
@@ -377,22 +421,20 @@ values by design.
|
|
|
377
421
|
|
|
378
422
|
## Support and status
|
|
379
423
|
|
|
380
|
-
Releases are numbered `0.1.N`, and
|
|
381
|
-
|
|
382
|
-
changelog
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
424
|
+
- **Unstable API.** Releases are numbered `0.1.N`, and any release may change
|
|
425
|
+
or remove exported identifiers. Pin an exact version. See the
|
|
426
|
+
[changelog](CHANGELOG.md), and the [main
|
|
427
|
+
changelog](https://github.com/libtmux/libtmux-ruby/blob/master/CHANGELOG.md)
|
|
428
|
+
for changes that span gems.
|
|
429
|
+
- **Ruby 3.3 or newer** and **tmux 3.3a or newer** to load or apply a plan. The
|
|
430
|
+
gem needs `libtmux` at the same version as itself.
|
|
387
431
|
- **Older daemons.** `load` creates nothing and prints the refusal with the
|
|
388
432
|
floor and the remedy. With `--json`, the refusal is in `error.message` and
|
|
389
433
|
`error.kind` is `tmux_unsupported`.
|
|
390
|
-
- **Linux, including WSL, and macOS.**
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
release runs all of them. macOS is supported on a best-effort basis, and CI
|
|
395
|
-
coverage for it is highly limited.
|
|
434
|
+
- **Linux, including WSL, and macOS.** CI runs on Linux; macOS is best effort.
|
|
435
|
+
The library and the command share the core
|
|
436
|
+
[compatibility workflow][compat]; see the
|
|
437
|
+
[CI matrix](../../.github/CONTRIBUTING.md#running-ci-against-any-tmux).
|
|
396
438
|
- **History limit.** On tmux 3.3a to 3.6 the reused initial pane keeps the
|
|
397
439
|
global `history-limit`. Set the server's global value before you apply to
|
|
398
440
|
get one history size.
|
|
@@ -411,8 +453,10 @@ changelog marks each break. Pin an exact version to avoid one.
|
|
|
411
453
|
[behavior-client-switching]: ../../docs/reference/behavior.md#client-switching
|
|
412
454
|
[behavior-workspace-apply]: ../../docs/reference/behavior.md#workspace-apply
|
|
413
455
|
[behavior-workspace-parsing]: ../../docs/reference/behavior.md#workspace-parsing
|
|
456
|
+
[tmuxp-syntax]: ../../test/fixtures/tmuxp/syntax-support.json
|
|
414
457
|
[behavior-workspace-plans]: ../../docs/reference/behavior.md#workspace-plans
|
|
415
458
|
[behavior-workspace-results]: ../../docs/reference/behavior.md#workspace-results
|
|
459
|
+
[workspace-cli]: ../../docs/reference/behavior.md#workspace-cli
|
|
416
460
|
[cli-load]: https://libtmux.org/en/ruby/latest/workspace/cli/load/
|
|
417
461
|
[cli-plan]: https://libtmux.org/en/ruby/latest/workspace/cli/plan/
|
|
418
462
|
[cli-validate]: https://libtmux.org/en/ruby/latest/workspace/cli/validate/
|
|
@@ -45,8 +45,13 @@ module LibTmux
|
|
|
45
45
|
def initialize(result, failure)
|
|
46
46
|
@result, @failure_class = result, failure.class.name.freeze
|
|
47
47
|
delivery = result.uncertain? ? :possibly_sent : (result.effects.empty? ? :not_sent : :observed)
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
if result.failed_action == :check_directories && failure.is_a?(ConfigError)
|
|
49
|
+
message, path, expected = failure.message, failure.path, failure.expected
|
|
50
|
+
else
|
|
51
|
+
message = "workspace apply failed during #{result.failed_action} (#{failure_class})"
|
|
52
|
+
end
|
|
53
|
+
super(message, path: path, expected: expected, phase: :apply,
|
|
54
|
+
delivery: delivery, cleanup_errors: result.cleanup_errors)
|
|
50
55
|
end
|
|
51
56
|
end
|
|
52
57
|
|
|
@@ -106,10 +111,18 @@ module LibTmux
|
|
|
106
111
|
if snapshot.sessions.where(name: @plan.preconditions.fetch("session_name_absent")).exists?
|
|
107
112
|
raise ConflictError.new("workspace creation requires an absent session name", phase: :apply)
|
|
108
113
|
end
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
action(:check_directories, mutation: false) { check_directories }
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def check_directories
|
|
118
|
+
steps = @plan.steps.select { |step| step.arguments.key?("cwd") }
|
|
119
|
+
steps.uniq { |step| step.arguments.fetch("cwd") }.each do |step|
|
|
120
|
+
directory = step.arguments.fetch("cwd")
|
|
121
|
+
next if File.directory?(directory) && File.executable?(directory)
|
|
122
|
+
|
|
123
|
+
_, window, pane = step.produces.last.split(":")
|
|
124
|
+
raise ConfigError.new("workspace start_directory is unavailable",
|
|
125
|
+
path: "$.windows[#{window}].panes[#{pane}]", expected: "existing accessible directory")
|
|
113
126
|
end
|
|
114
127
|
end
|
|
115
128
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "libtmux/workspace"
|
|
4
4
|
require "optparse"
|
|
5
|
+
require "fcntl"
|
|
5
6
|
|
|
6
7
|
module LibTmux
|
|
7
8
|
class Workspace
|
|
@@ -22,7 +23,7 @@ module LibTmux
|
|
|
22
23
|
return version if @arguments == ["--version"]
|
|
23
24
|
|
|
24
25
|
command = @arguments.shift
|
|
25
|
-
raise ArgumentError unless %w[validate plan load].include?(command)
|
|
26
|
+
raise ArgumentError unless %w[validate plan load attach].include?(command)
|
|
26
27
|
|
|
27
28
|
@arguments.take_while { |argument| argument != "--" }.each_with_index do |argument, index|
|
|
28
29
|
next unless argument == "--switch"
|
|
@@ -33,7 +34,10 @@ module LibTmux
|
|
|
33
34
|
return help if @options[:help]
|
|
34
35
|
return version if @options[:version]
|
|
35
36
|
|
|
37
|
+
return attach_existing if command == "attach"
|
|
38
|
+
|
|
36
39
|
validate_arguments(command)
|
|
40
|
+
term = attachment_term if @options[:attach]
|
|
37
41
|
file = configuration_file
|
|
38
42
|
workspace = Workspace.load(file, expand_environment: @options.fetch(:expand_environment), environment: @options.fetch(:environment))
|
|
39
43
|
case command
|
|
@@ -55,10 +59,11 @@ module LibTmux
|
|
|
55
59
|
timeout: @options.fetch(:timeout))
|
|
56
60
|
end
|
|
57
61
|
if @options[:attach]
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
terminal = attachment_terminal
|
|
63
|
+
raise TransportError.new("interactive terminal required", phase: :terminal) unless terminal
|
|
64
|
+
|
|
65
|
+
result = server.attach(session: @result.created_refs.fetch("session"), terminal: terminal, term: term)
|
|
66
|
+
raise TransportError.new("attached terminal client failed", phase: :terminal) unless result.success?
|
|
62
67
|
end
|
|
63
68
|
end
|
|
64
69
|
emit(@result.to_h, "Workspace created; #{@result.completed_steps.length} steps completed. Shell commands were dispatched.")
|
|
@@ -83,18 +88,20 @@ module LibTmux
|
|
|
83
88
|
|
|
84
89
|
def parser
|
|
85
90
|
@parser ||= OptionParser.new do |options|
|
|
86
|
-
options.banner = "Usage: libtmux-workspace validate|plan|load [options] [FILE]"
|
|
91
|
+
options.banner = "Usage: libtmux-workspace validate|plan|load [options] [FILE]\n" \
|
|
92
|
+
" libtmux-workspace attach --socket PATH [--timeout SECONDS] SESSION_ID"
|
|
87
93
|
options.on("--json", "Write structured JSON to stdout") { @json = true }
|
|
88
|
-
options.on("--socket PATH", "
|
|
89
|
-
"
|
|
94
|
+
options.on("--socket PATH", "Existing tmux server socket for load, plan --live or attach",
|
|
95
|
+
"Required for attach. Otherwise defaults to LIBTMUX_SOCKET_PATH,",
|
|
96
|
+
"then LIBTMUX_SOCKET, then the",
|
|
90
97
|
"server TMUX names, then tmux's default socket") { |value| @options[:socket] = value }
|
|
91
98
|
options.on("--live", "Acquire a snapshot before planning") { @options[:live] = true }
|
|
92
|
-
options.on("--timeout SECONDS", Float, "Per-operation apply/capture/switch deadline (default: 5)") { |value| @options[:timeout] = value }
|
|
99
|
+
options.on("--timeout SECONDS", Float, "Per-operation apply/capture/switch/session lookup deadline (default: 5)") { |value| @options[:timeout] = value }
|
|
93
100
|
options.on("--compensate", "Attempt guarded cleanup of positively created resources on failure") { @options[:compensate] = true }
|
|
94
|
-
options.on("--attach", "Attach
|
|
101
|
+
options.on("--attach", "Attach after load using the terminal on stdin and stdout") { @options[:attach] = true }
|
|
95
102
|
options.on("--switch CLIENT", "Switch the explicit current client after successful load") { |value| @options[:switch] = value }
|
|
96
103
|
options.on("--expand-environment", "Expand ${NAME} in paths/environment using explicit --env values") { @options[:expand_environment] = true }
|
|
97
|
-
options.on("--env NAME=VALUE", "
|
|
104
|
+
options.on("--env NAME=VALUE", "Supply a substitution value or HOME for ~ in start_directory") do |value|
|
|
98
105
|
name, contents = value.split("=", 2)
|
|
99
106
|
raise ArgumentError unless contents && /\A[A-Za-z_][A-Za-z0-9_]*\z/.match?(name)
|
|
100
107
|
raise ArgumentError if @options.fetch(:environment).key?(name)
|
|
@@ -126,13 +133,61 @@ module LibTmux
|
|
|
126
133
|
end
|
|
127
134
|
raise ArgumentError if command != "load" && (@options[:attach] || @options[:switch] || @options[:compensate])
|
|
128
135
|
raise ArgumentError if @options[:live] && command != "plan"
|
|
129
|
-
live = command
|
|
136
|
+
live = %w[load attach].include?(command) || @options[:live]
|
|
130
137
|
raise ArgumentError if @options.key?(:socket) && @options[:socket].empty?
|
|
131
138
|
raise ArgumentError if !live && @options[:socket]
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def attach_existing
|
|
142
|
+
if @json || @options.values_at(:live, :attach, :switch, :compensate, :expand_environment).any? ||
|
|
143
|
+
!@options.fetch(:environment).empty?
|
|
144
|
+
@argument_message = "Attach accepts --socket and --timeout; use --help for usage."
|
|
145
|
+
raise ArgumentError
|
|
146
|
+
end
|
|
147
|
+
id = @arguments.first
|
|
148
|
+
unless @arguments.length == 1 && /\A\$(?:0|[1-9][0-9]*)\z/.match?(id)
|
|
149
|
+
@argument_message = "Provide one numeric session ID, for example '$1'."
|
|
150
|
+
raise ArgumentError
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
unless @options[:socket] && !@options[:socket].empty?
|
|
154
|
+
@argument_message = "Provide --socket PATH for the server that owns the session ID."
|
|
155
|
+
raise ArgumentError
|
|
135
156
|
end
|
|
157
|
+
validate_arguments("attach")
|
|
158
|
+
terminal = attachment_terminal
|
|
159
|
+
return attachment_error("Attach requires an interactive terminal on stdin and stdout.") unless terminal
|
|
160
|
+
term = attachment_term
|
|
161
|
+
|
|
162
|
+
with_server do |server|
|
|
163
|
+
session = server.list_sessions(timeout: @options.fetch(:timeout)).find { |candidate| candidate.id == id }
|
|
164
|
+
return attachment_error("The session ID was not found on the selected tmux server.") unless session
|
|
165
|
+
|
|
166
|
+
result = server.attach(session: session.ref, terminal: terminal, term: term)
|
|
167
|
+
return attachment_error("The tmux terminal client failed to attach.") unless result.success?
|
|
168
|
+
end
|
|
169
|
+
0
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def attachment_term
|
|
173
|
+
term = @environment["TERM"]
|
|
174
|
+
return term if LibTmux::Server.valid_terminal_type?(term)
|
|
175
|
+
|
|
176
|
+
@argument_message = "Set TERM to the terminal type before attaching."
|
|
177
|
+
raise ArgumentError
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def attachment_terminal
|
|
181
|
+
input = $stdin
|
|
182
|
+
return unless input.tty? && @out.is_a?(IO) && @out.tty? && input.stat.rdev == @out.stat.rdev
|
|
183
|
+
|
|
184
|
+
# tmux needs the actual terminal device on both streams.
|
|
185
|
+
[input, @out].find { |stream| (stream.fcntl(Fcntl::F_GETFL) & Fcntl::O_ACCMODE) == Fcntl::O_RDWR }
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def attachment_error(message)
|
|
189
|
+
@err.puts(message)
|
|
190
|
+
1
|
|
136
191
|
end
|
|
137
192
|
|
|
138
193
|
def configuration_file
|
|
@@ -199,7 +254,12 @@ module LibTmux
|
|
|
199
254
|
value.fetch("error")["delivery"] = error.delivery.to_s
|
|
200
255
|
value.fetch("error")["phase"] = error.phase&.to_s
|
|
201
256
|
end
|
|
202
|
-
|
|
257
|
+
if error.is_a?(Workspace::ApplyError)
|
|
258
|
+
details = value.fetch("error")
|
|
259
|
+
details["failure_class"] = error.failure_class
|
|
260
|
+
details["path"] = error.path if error.path
|
|
261
|
+
details["expected"] = error.expected if error.expected
|
|
262
|
+
end
|
|
203
263
|
value["result"] = @result.to_h if @result
|
|
204
264
|
if @json
|
|
205
265
|
@out.puts(JSON.generate(value))
|
|
@@ -19,7 +19,8 @@ module LibTmux
|
|
|
19
19
|
"main-pane-width" => :index, "main-pane-height" => :index,
|
|
20
20
|
"window-status-format" => :text, "window-status-current-format" => :text,
|
|
21
21
|
"pane-border-status" => %w[off top bottom]}.freeze
|
|
22
|
-
|
|
22
|
+
BLANK_PANE = %w[blank pane].freeze
|
|
23
|
+
private_constant :COMMON, :ROOT, :WINDOW, :PANE, :LAYOUTS, :SESSION_OPTIONS, :WINDOW_OPTIONS, :BLANK_PANE
|
|
23
24
|
|
|
24
25
|
def initialize(base, expand, environment, limits)
|
|
25
26
|
@limits, @expand, @expanded_bytes = limits, expand, 0
|
|
@@ -130,11 +131,9 @@ module LibTmux
|
|
|
130
131
|
end
|
|
131
132
|
|
|
132
133
|
def common(input, parent, path)
|
|
133
|
-
directory =
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
File.expand_path(value.start_with?(File::SEPARATOR) ? value : File.join(@base, value))
|
|
137
|
-
else parent.fetch("start_directory")
|
|
134
|
+
directory = parent.fetch("start_directory")
|
|
135
|
+
if input.key?("start_directory")
|
|
136
|
+
directory = start_directory(input["start_directory"], directory, "#{path}.start_directory")
|
|
138
137
|
end
|
|
139
138
|
inherited_environment = parent.fetch("environment").merge(environment_map(input.fetch("environment", {}), "#{path}.environment"))
|
|
140
139
|
before = parent.fetch("shell_command_before") + commands(input.fetch("shell_command_before", []), "#{path}.shell_command_before")
|
|
@@ -145,6 +144,19 @@ module LibTmux
|
|
|
145
144
|
result
|
|
146
145
|
end
|
|
147
146
|
|
|
147
|
+
def start_directory(input, parent, path)
|
|
148
|
+
value = expand(text(input, path, empty: false), path)
|
|
149
|
+
if value.start_with?("~")
|
|
150
|
+
fail_at(path, "~ or ~/path for home expansion") unless value == "~" || value.start_with?("~/")
|
|
151
|
+
|
|
152
|
+
home = @environment["HOME"]
|
|
153
|
+
fail_at(path, "absolute HOME in the supplied environment") unless home&.start_with?("/")
|
|
154
|
+
|
|
155
|
+
value = File.join(home, value.delete_prefix("~"))
|
|
156
|
+
end
|
|
157
|
+
File.absolute_path(value, parent)
|
|
158
|
+
end
|
|
159
|
+
|
|
148
160
|
def object(value, allowed, path)
|
|
149
161
|
fail_at(path, "configuration object") unless value.is_a?(Hash)
|
|
150
162
|
unknown = value.keys - allowed
|
|
@@ -226,7 +238,9 @@ module LibTmux
|
|
|
226
238
|
value = [value] if value.is_a?(String)
|
|
227
239
|
fail_at(path, "shell command string or ordered string array") unless value.is_a?(Array)
|
|
228
240
|
fail_at(path, "bounded command array") if value.length > @limits.fetch(:max_nodes)
|
|
229
|
-
value.map { |command| text(command, path) }
|
|
241
|
+
commands = value.map { |command| text(command, path) }
|
|
242
|
+
# tmuxp reads a lone "pane" or "blank" as a pane with nothing to run.
|
|
243
|
+
(commands.one? && BLANK_PANE.include?(commands.first)) ? [] : commands
|
|
230
244
|
end
|
|
231
245
|
|
|
232
246
|
def boolean(value, path)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: libtmux-workspace
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- libtmux contributors
|
|
@@ -15,42 +15,54 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - '='
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.1.
|
|
18
|
+
version: 0.1.3
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - '='
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.1.
|
|
25
|
+
version: 0.1.3
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: json
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
|
-
- - "
|
|
30
|
+
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
32
|
version: 3.0.2
|
|
33
|
+
- - "<"
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '4'
|
|
33
36
|
type: :runtime
|
|
34
37
|
prerelease: false
|
|
35
38
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
39
|
requirements:
|
|
37
|
-
- - "
|
|
40
|
+
- - ">="
|
|
38
41
|
- !ruby/object:Gem::Version
|
|
39
42
|
version: 3.0.2
|
|
43
|
+
- - "<"
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '4'
|
|
40
46
|
- !ruby/object:Gem::Dependency
|
|
41
47
|
name: psych
|
|
42
48
|
requirement: !ruby/object:Gem::Requirement
|
|
43
49
|
requirements:
|
|
44
|
-
- - "
|
|
50
|
+
- - ">="
|
|
45
51
|
- !ruby/object:Gem::Version
|
|
46
52
|
version: 5.5.0
|
|
53
|
+
- - "<"
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '6'
|
|
47
56
|
type: :runtime
|
|
48
57
|
prerelease: false
|
|
49
58
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
59
|
requirements:
|
|
51
|
-
- - "
|
|
60
|
+
- - ">="
|
|
52
61
|
- !ruby/object:Gem::Version
|
|
53
62
|
version: 5.5.0
|
|
63
|
+
- - "<"
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: '6'
|
|
54
66
|
description: Validate YAML or JSON workspace configurations, inspect creation plans
|
|
55
67
|
and apply them to tmux.
|
|
56
68
|
executables:
|
|
@@ -58,6 +70,7 @@ executables:
|
|
|
58
70
|
extensions: []
|
|
59
71
|
extra_rdoc_files: []
|
|
60
72
|
files:
|
|
73
|
+
- CHANGELOG.md
|
|
61
74
|
- LICENSE
|
|
62
75
|
- README.md
|
|
63
76
|
- assets/logo.png
|
|
@@ -76,7 +89,8 @@ licenses:
|
|
|
76
89
|
- MIT
|
|
77
90
|
metadata:
|
|
78
91
|
source_code_uri: https://github.com/libtmux/libtmux-ruby
|
|
79
|
-
|
|
92
|
+
changelog_uri: https://github.com/libtmux/libtmux-ruby/blob/master/gems/libtmux-workspace/CHANGELOG.md
|
|
93
|
+
documentation_uri: https://libtmux.org/en/ruby/v0.1.3/workspace/
|
|
80
94
|
rdoc_options: []
|
|
81
95
|
require_paths:
|
|
82
96
|
- lib
|