editprompt 1.7.0 → 2.0.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.
- package/README.md +132 -12
- package/dist/index.js +1154 -833
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -22,7 +22,8 @@ A CLI tool that lets you write prompts for CLI tools using your favorite text ed
|
|
|
22
22
|
## ✨ Features
|
|
23
23
|
|
|
24
24
|
- 🖊️ **Editor Integration**: Use your preferred text editor to write prompts
|
|
25
|
-
- 🖥️ **Multiplexer Support**: Send prompts directly to tmux, WezTerm, or
|
|
25
|
+
- 🖥️ **Multiplexer Support**: Send prompts directly to tmux, WezTerm, Herdr, niwaterm, or Rex sessions
|
|
26
|
+
- 🧩 **Custom Backends**: Add any other terminal with a CLI from your configuration file
|
|
26
27
|
- 🖥️ **Universal Terminal Support**: Works with any terminal via clipboard - no multiplexer required
|
|
27
28
|
- 📤 **Send Without Closing**: Iterate on prompts without closing your editor
|
|
28
29
|
- 📋 **Quote Buffering**: Collect text selections and send them as quoted replies
|
|
@@ -40,7 +41,7 @@ npx editprompt
|
|
|
40
41
|
|
|
41
42
|
### Neovim Plugin
|
|
42
43
|
|
|
43
|
-
For Neovim users, [editprompt.nvim](https://github.com/eetann/editprompt.nvim) provides easy integration.
|
|
44
|
+
For Neovim users, [editprompt.nvim](https://github.com/eetann/editprompt.nvim) provides easy integration.
|
|
44
45
|
|
|
45
46
|
## 🚀 Usage
|
|
46
47
|
|
|
@@ -187,6 +188,108 @@ Run the binding from a target pane. editprompt opens a regular bottom split for
|
|
|
187
188
|
|
|
188
189
|
Inside a Herdr pane, editprompt automatically selects the Herdr backend when `HERDR_SOCKET_PATH` and a pane ID are available. An explicit `--mux` option or `EDITPROMPT_MUX` value takes precedence, so the binding above keeps `--mux herdr` to make its intent clear.
|
|
189
190
|
|
|
191
|
+
### Rex Integration
|
|
192
|
+
|
|
193
|
+
[Rex](https://www.superlogical.com/rex/docs) is configured in Lua, and its configuration file can both run commands and build layouts, so the binding does the splitting and editprompt only opens the editor. Add this to `~/.config/rex/init.lua`:
|
|
194
|
+
|
|
195
|
+
```lua
|
|
196
|
+
-- Height of the editor pane, in rows. new_split takes a fraction, so it is
|
|
197
|
+
-- derived from the target pane's current height; a fixed fraction would make
|
|
198
|
+
-- the editor grow with the window. PANE_CHROME_ROWS is what a pane spends on
|
|
199
|
+
-- its header and border, which hold no text.
|
|
200
|
+
local EDITOR_ROWS = 12
|
|
201
|
+
local PANE_CHROME_ROWS = 3
|
|
202
|
+
|
|
203
|
+
local function editor_ratio(block_id)
|
|
204
|
+
local size = rex.block.call("com.superlogical.terminal", "size", { block_id = block_id })
|
|
205
|
+
local rows = size and size.rows
|
|
206
|
+
if not rows or rows <= 1 then
|
|
207
|
+
return 0.8
|
|
208
|
+
end
|
|
209
|
+
-- Never let the editor take more than half, for a pane too short to spare the
|
|
210
|
+
-- rows, and stay inside the fraction new_split accepts.
|
|
211
|
+
return math.max(0.5, math.min(0.9, 1 - (EDITOR_ROWS + PANE_CHROME_ROWS) / rows))
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
-- Start the editor in the directory the target pane last reported. A shell that
|
|
215
|
+
-- uses OSC 7, such as nushell, reports it as a file:// URL.
|
|
216
|
+
local function pane_cwd(block_id)
|
|
217
|
+
local result = rex.block.call("com.superlogical.terminal", "pwd", { block_id = block_id })
|
|
218
|
+
local pwd = result and result.pwd
|
|
219
|
+
if not pwd then
|
|
220
|
+
return nil
|
|
221
|
+
end
|
|
222
|
+
return (pwd:gsub("^file://[^/]*", ""))
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
rex.bind("alt+q", function(ctx)
|
|
226
|
+
-- Focus an editor pane that is already open, or, when pressed from the editor
|
|
227
|
+
-- pane, go back to the target pane.
|
|
228
|
+
local resumed, err = rex.exec({
|
|
229
|
+
"editprompt", "resume", "--mux", "rex", "--target-pane", ctx.block_id,
|
|
230
|
+
})
|
|
231
|
+
if not resumed then
|
|
232
|
+
-- The command never ran at all, which is not the same as having no editor
|
|
233
|
+
-- pane to go back to. Say so rather than opening a split that would fail
|
|
234
|
+
-- the same way.
|
|
235
|
+
rex.log("error", "editprompt could not be run: " .. tostring(err))
|
|
236
|
+
return true
|
|
237
|
+
end
|
|
238
|
+
if resumed.ok then
|
|
239
|
+
return true
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
rex.session.new_split{
|
|
243
|
+
anchor_id = ctx.block_id,
|
|
244
|
+
direction = "vertical",
|
|
245
|
+
side = "after",
|
|
246
|
+
ratio = editor_ratio(ctx.block_id),
|
|
247
|
+
focus = true,
|
|
248
|
+
layout = rex.layout.block{
|
|
249
|
+
flavor = "com.superlogical.terminal.shell",
|
|
250
|
+
options = {
|
|
251
|
+
command = {
|
|
252
|
+
"editprompt", "open", "--mux", "rex",
|
|
253
|
+
"--target-pane", ctx.block_id, "--editor", "nvim", "--always-copy",
|
|
254
|
+
},
|
|
255
|
+
cwd = pane_cwd(ctx.block_id),
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
}
|
|
259
|
+
return true
|
|
260
|
+
end)
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Reload it with `rex config reload`; Rex does not watch the file for changes. `rex config check` reports mistakes without applying them.
|
|
264
|
+
|
|
265
|
+
`ratio` is the share the `before` part keeps, which here is the target pane, so a larger value leaves the editor less room. `direction = "vertical"` stacks the panes and `side = "after"` puts the new one below. `EDITOR_ROWS` is the knob worth tuning: it keeps the editor the same height whatever the window's size, the way `--pane-rows` does for Herdr.
|
|
266
|
+
|
|
267
|
+
**Turn off the app's "Autobalance Splits" setting.** With it on, Rex equalises every pane as soon as a block is created, which discards the `ratio` the binding asked for and leaves the editor half the window. Setting the border afterwards with `session.resize_pane` does not help either: the equalisation lands after it. `focus` defaults to false, so the binding asks for it explicitly. The pane closes once the editor exits, which is Rex's default for a terminal started with a `command`; it stays open after a quick failure instead, so a startup error remains readable.
|
|
268
|
+
|
|
269
|
+
editprompt locates the `rex` CLI through `REX_BIN_DIR`, which Rex sets in every terminal it opens, and falls back to the PATH. That matters because the login shell can rebuild PATH and drop the directory Rex added. On NixOS and nix-darwin it does, and the fix Rex documents for that runs in interactive shells only, which a terminal started from `init.lua` is not.
|
|
270
|
+
|
|
271
|
+
`rex.exec` runs in the Rex server's environment rather than a shell's, so give `editprompt` an absolute path there if the server's PATH does not include it.
|
|
272
|
+
|
|
273
|
+
Name the editor with `--editor`. A terminal Rex starts gets the login shell's environment, not the interactive one, so `$EDITOR` is whatever that environment sets rather than what your prompt uses — on nix-darwin, for instance, it is `nano`.
|
|
274
|
+
|
|
275
|
+
Inside a Rex pane, editprompt automatically selects the Rex backend when `REX_BLOCK` is set. Running tmux inside a Rex pane sets both, and Rex wins, so pass `--mux tmux` or set `EDITPROMPT_MUX` for that case.
|
|
276
|
+
|
|
277
|
+
### Other Terminals (Custom Backends)
|
|
278
|
+
|
|
279
|
+
Any other terminal or multiplexer with a command-line interface can be added in `~/.config/editprompt/config.toml`, without waiting for editprompt to support it:
|
|
280
|
+
|
|
281
|
+
```toml
|
|
282
|
+
[backends.mytty]
|
|
283
|
+
detect = { env = "MYTTY_PANE_ID" }
|
|
284
|
+
currentPane = { env = "MYTTY_PANE_ID" }
|
|
285
|
+
paneExists = 'mytty pane exists "$EDITPROMPT_PANE"'
|
|
286
|
+
focus = 'mytty pane focus "$EDITPROMPT_PANE"'
|
|
287
|
+
sendText = 'mytty send-text --pane "$EDITPROMPT_PANE"'
|
|
288
|
+
sendKey = 'mytty send-key --pane "$EDITPROMPT_PANE" "$EDITPROMPT_KEY"'
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Then select it with `--mux mytty`, `EDITPROMPT_MUX=mytty`, or let `detect` pick it. See [docs/backends.md](docs/backends.md) for every option, including the commands that enable `editprompt toggle`.
|
|
292
|
+
|
|
190
293
|
### Editor Integration (Send Without Closing)
|
|
191
294
|
|
|
192
295
|
While editprompt is running, you can send content to the target pane or clipboard without closing the editor. This allows you to iterate quickly on your prompts.
|
|
@@ -205,7 +308,7 @@ editprompt input --auto-send -- "your content here"
|
|
|
205
308
|
editprompt input --auto-send --send-key "C-m" -- "your content here"
|
|
206
309
|
# Customize the key to send after content (tmux format example)
|
|
207
310
|
# WezTerm example: --send-key "\r"
|
|
208
|
-
# Herdr example: --send-key "enter"
|
|
311
|
+
# Herdr and Rex example: --send-key "enter"
|
|
209
312
|
```
|
|
210
313
|
|
|
211
314
|
This sends the content to the target pane (or clipboard) while keeping your editor open, so you can continue editing and send multiple times.
|
|
@@ -217,10 +320,11 @@ This sends the content to the target pane (or clipboard) while keeping your edit
|
|
|
217
320
|
- tmux format: `Enter` (default), `C-a`, etc.
|
|
218
321
|
- WezTerm format: `\r` (default), `\x01`, etc.
|
|
219
322
|
- Herdr format: `enter` (default), `ctrl+a`, etc.
|
|
323
|
+
- Rex format: `enter` (default), `ctrl+a`, etc.
|
|
220
324
|
|
|
221
325
|
#### Neovim Integration
|
|
222
326
|
|
|
223
|
-
For Neovim users, we recommend using [editprompt.nvim](https://github.com/eetann/editprompt.nvim) for easy setup.
|
|
327
|
+
For Neovim users, we recommend using [editprompt.nvim](https://github.com/eetann/editprompt.nvim) for easy setup.
|
|
224
328
|
|
|
225
329
|
### Key Sending (press)
|
|
226
330
|
|
|
@@ -236,7 +340,7 @@ editprompt press -- Up
|
|
|
236
340
|
editprompt press -- C-m # Enter
|
|
237
341
|
editprompt press -- C-c # Ctrl+C
|
|
238
342
|
|
|
239
|
-
# Herdr examples
|
|
343
|
+
# Herdr and Rex examples
|
|
240
344
|
editprompt press -- enter
|
|
241
345
|
editprompt press -- ctrl+c
|
|
242
346
|
|
|
@@ -252,12 +356,12 @@ editprompt press --delay 500 -- Tab
|
|
|
252
356
|
|
|
253
357
|
**Key notation** depends on your multiplexer:
|
|
254
358
|
|
|
255
|
-
| Key | tmux | WezTerm | Herdr |
|
|
256
|
-
| ------------- | ------------- | ------------------- | ------------- |
|
|
257
|
-
| Enter | `C-m` | `\r` | `enter` |
|
|
258
|
-
| Tab | `Tab` | `\t` | `tab` |
|
|
259
|
-
| Escape | `Escape` | `\x1b` | `esc` |
|
|
260
|
-
| Arrow Up/Down | `Up` / `Down` | `\x1b[A` / `\x1b[B` | `up` / `down` |
|
|
359
|
+
| Key | tmux | WezTerm | Herdr | Rex |
|
|
360
|
+
| ------------- | ------------- | ------------------- | ------------- | ------------- |
|
|
361
|
+
| Enter | `C-m` | `\r` | `enter` | `enter` |
|
|
362
|
+
| Tab | `Tab` | `\t` | `tab` | `tab` |
|
|
363
|
+
| Escape | `Escape` | `\x1b` | `esc` | `escape` |
|
|
364
|
+
| Arrow Up/Down | `Up` / `Down` | `\x1b[A` / `\x1b[B` | `up` / `down` | `up` / `down` |
|
|
261
365
|
|
|
262
366
|
### Quote Workflow Setup
|
|
263
367
|
|
|
@@ -327,6 +431,22 @@ editprompt collect --mux herdr --target-pane "$HERDR_PANE_ID" -- "selected text"
|
|
|
327
431
|
|
|
328
432
|
This can be called from a script or editor integration that has access to the selected text. Herdr quote buffers are stored in editprompt's configuration, associated with the target pane.
|
|
329
433
|
|
|
434
|
+
#### Collecting Quotes in Rex
|
|
435
|
+
|
|
436
|
+
Pass selected text as an argument together with the target block ID:
|
|
437
|
+
|
|
438
|
+
```bash
|
|
439
|
+
editprompt collect --mux rex --target-pane "$REX_BLOCK" -- "selected text"
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
From `init.lua`, call it with `rex.exec`, which takes an argv table so the text needs no quoting:
|
|
443
|
+
|
|
444
|
+
```lua
|
|
445
|
+
rex.exec({ "editprompt", "collect", "--mux", "rex", "--target-pane", ctx.block_id, "--", text })
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
As with Herdr, Rex quote buffers live in editprompt's configuration, associated with the target pane.
|
|
449
|
+
|
|
330
450
|
#### Capturing Collected Quotes
|
|
331
451
|
|
|
332
452
|
Run this command from within your editor pane to retrieve all collected quotes:
|
|
@@ -406,7 +526,7 @@ editprompt respects the following editor priority:
|
|
|
406
526
|
|
|
407
527
|
#### EDITPROMPT Environment Variable
|
|
408
528
|
|
|
409
|
-
editprompt automatically sets `EDITPROMPT=1` when launching your editor. This allows you to detect when your editor is launched by editprompt and enable specific configurations or plugins.
|
|
529
|
+
editprompt automatically sets `EDITPROMPT=1` when launching your editor. This allows you to detect when your editor is launched by editprompt and enable specific configurations or plugins.
|
|
410
530
|
|
|
411
531
|
#### Custom Environment Variables
|
|
412
532
|
|