editprompt 0.7.0 → 0.8.1

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.
Files changed (3) hide show
  1. package/README.md +15 -0
  2. package/dist/index.js +85 -23
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -176,10 +176,25 @@ While editprompt is running, you can send content to the target pane or clipboar
176
176
  ```bash
177
177
  # Run this command from within your editor session
178
178
  editprompt -- "your content here"
179
+ # Sends content to target pane and moves focus there
180
+
181
+ editprompt --auto-send -- "your content here"
182
+ # Sends content, automatically submits it (presses Enter), and returns focus to editor pane
183
+ # Perfect for iterating on prompts without leaving your editor
184
+
185
+ editprompt --auto-send --send-key "C-m" -- "your content here"
186
+ # Customize the key to send after content (tmux format example)
187
+ # WezTerm example: --send-key "\r" (default for WezTerm is \r, tmux default is Enter)
179
188
  ```
180
189
 
181
190
  This sends the content to the target pane (or clipboard) while keeping your editor open, so you can continue editing and send multiple times.
182
191
 
192
+ **Options:**
193
+ - `--auto-send`: Automatically sends the content and returns focus to your editor pane (requires multiplexer)
194
+ - `--send-key <key>`: Customize the key to send after content (requires `--auto-send`)
195
+ - tmux format: `Enter` (default), `C-a`, etc.
196
+ - WezTerm format: `\r` (default), `\x01`, etc.
197
+
183
198
  #### Neovim Integration Example
184
199
 
185
200
  You can set up a convenient keybinding to send your buffer content:
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { join } from "node:path";
9
9
  import clipboardy from "clipboardy";
10
10
 
11
11
  //#region package.json
12
- var version = "0.7.0";
12
+ var version = "0.8.1";
13
13
 
14
14
  //#endregion
15
15
  //#region src/modules/tmux.ts
@@ -81,6 +81,15 @@ async function appendToQuoteVariable(paneId, content) {
81
81
  async function clearQuoteVariable(targetPaneId) {
82
82
  await execAsync$2(`tmux set-option -pt '${targetPaneId}' @editprompt_quote ""`);
83
83
  }
84
+ async function sendKeyToTmuxPane(paneId, key) {
85
+ await new Promise((resolve) => setTimeout(resolve, 100));
86
+ await execAsync$2(`tmux send-keys -t '${paneId}' '${key}'`);
87
+ }
88
+ async function sendContentToTmuxPaneNoFocus(paneId, content) {
89
+ await execAsync$2(`tmux if-shell -t '${paneId}' '[ "#{pane_in_mode}" = "1" ]' "copy-mode -q -t '${paneId}'"`);
90
+ await execAsync$2(`tmux send-keys -t '${paneId}' -- '${content.replace(/'/g, "'\\''")}'`);
91
+ console.log(`Content sent to tmux pane: ${paneId}`);
92
+ }
84
93
 
85
94
  //#endregion
86
95
  //#region src/modules/wezterm.ts
@@ -190,6 +199,13 @@ async function clearQuoteText(paneId) {
190
199
  console.log(error);
191
200
  }
192
201
  }
202
+ async function sendKeyToWeztermPane(paneId, key) {
203
+ await execAsync$1(`wezterm cli send-text --no-paste --pane-id '${paneId}' $'${key}'`);
204
+ }
205
+ async function sendContentToWeztermPaneNoFocus(paneId, content) {
206
+ await execAsync$1(`wezterm cli send-text --no-paste --pane-id '${paneId}' -- '${content.replace(/'/g, "'\\''")}'`);
207
+ console.log(`Content sent to wezterm pane: ${paneId}`);
208
+ }
193
209
 
194
210
  //#endregion
195
211
  //#region src/utils/sendConfig.ts
@@ -363,6 +379,50 @@ async function sendContentToPane(content, mux, targetPaneId, alwaysCopy) {
363
379
  }
364
380
  }
365
381
 
382
+ //#endregion
383
+ //#region src/modes/sendOnly.ts
384
+ async function sendContentToPaneWithAutoSend(content, mux, targetPaneId, sendKey) {
385
+ if (mux === "wezterm") {
386
+ await sendContentToWeztermPaneNoFocus(targetPaneId, content);
387
+ await sendKeyToWeztermPane(targetPaneId, sendKey);
388
+ } else {
389
+ await sendContentToTmuxPaneNoFocus(targetPaneId, content);
390
+ await sendKeyToTmuxPane(targetPaneId, sendKey);
391
+ }
392
+ }
393
+ async function runSendOnlyMode(rawContent, autoSend, sendKey) {
394
+ const content = processContent(rawContent);
395
+ if (!content) {
396
+ console.log("No content to send. Exiting.");
397
+ return;
398
+ }
399
+ const config = readSendConfig();
400
+ if (!config.targetPane) {
401
+ console.error("Error: EDITPROMPT_TARGET_PANE environment variable is required in send-only mode");
402
+ process.exit(1);
403
+ }
404
+ if (autoSend) {
405
+ if (!config.mux) {
406
+ console.error("Error: --auto-send requires a multiplexer (tmux or wezterm)");
407
+ process.exit(1);
408
+ }
409
+ try {
410
+ const key = sendKey || (config.mux === "wezterm" ? "\\r" : "C-m");
411
+ await handleAutoSendDelivery(content, config.mux, config.targetPane, key);
412
+ } catch (error) {
413
+ console.error(`Error: ${error instanceof Error ? error.message : "Unknown error"}`);
414
+ process.exit(1);
415
+ }
416
+ return;
417
+ }
418
+ try {
419
+ await handleContentDelivery(content, config.mux, config.targetPane, config.alwaysCopy);
420
+ } catch (error) {
421
+ console.error(`Error: ${error instanceof Error ? error.message : "Unknown error"}`);
422
+ process.exit(1);
423
+ }
424
+ }
425
+
366
426
  //#endregion
367
427
  //#region src/modes/common.ts
368
428
  function outputContent(content) {
@@ -388,6 +448,17 @@ async function handleContentDelivery(content, mux, targetPane, alwaysCopy) {
388
448
  }
389
449
  outputContent(content);
390
450
  }
451
+ async function handleAutoSendDelivery(content, mux, targetPane, sendKey) {
452
+ if (!content || !targetPane) throw new Error("Content and target pane are required");
453
+ try {
454
+ await sendContentToPaneWithAutoSend(content, mux, targetPane, sendKey);
455
+ console.log("Content sent and submitted successfully!");
456
+ } catch (error) {
457
+ console.error(`Failed to send content: ${error instanceof Error ? error.message : "Unknown error"}`);
458
+ throw error;
459
+ }
460
+ outputContent(content);
461
+ }
391
462
 
392
463
  //#endregion
393
464
  //#region src/modes/openEditor.ts
@@ -607,27 +678,6 @@ async function runResumeMode(targetPane, mux) {
607
678
  process.exit(0);
608
679
  }
609
680
 
610
- //#endregion
611
- //#region src/modes/sendOnly.ts
612
- async function runSendOnlyMode(rawContent) {
613
- const content = processContent(rawContent);
614
- if (!content) {
615
- console.log("No content to send. Exiting.");
616
- return;
617
- }
618
- const config = readSendConfig();
619
- if (!config.targetPane) {
620
- console.error("Error: EDITPROMPT_TARGET_PANE environment variable is required in send-only mode");
621
- process.exit(1);
622
- }
623
- try {
624
- await handleContentDelivery(content, config.mux, config.targetPane, config.alwaysCopy);
625
- } catch (error) {
626
- console.error(`Error: ${error instanceof Error ? error.message : "Unknown error"}`);
627
- process.exit(1);
628
- }
629
- }
630
-
631
681
  //#endregion
632
682
  //#region src/utils/argumentParser.ts
633
683
  /**
@@ -690,10 +740,22 @@ await cli(process.argv.slice(2), {
690
740
  capture: {
691
741
  description: "Capture mode - copy pane variable to clipboard and clear",
692
742
  type: "boolean"
743
+ },
744
+ "auto-send": {
745
+ description: "Automatically send content and return focus to editor pane",
746
+ type: "boolean"
747
+ },
748
+ "send-key": {
749
+ description: "Key to send after content (default: Enter, requires --auto-send)",
750
+ type: "string"
693
751
  }
694
752
  },
695
753
  async run(ctx) {
696
754
  try {
755
+ if (ctx.values["send-key"] && !ctx.values["auto-send"]) {
756
+ console.error("Error: --send-key requires --auto-send option");
757
+ process.exit(1);
758
+ }
697
759
  if (ctx.values.resume) {
698
760
  if (!ctx.values["target-pane"]) {
699
761
  console.error("Error: --target-pane is required when using --resume");
@@ -733,7 +795,7 @@ await cli(process.argv.slice(2), {
733
795
  }
734
796
  const rawContent = extractRawContent(ctx.rest, ctx.positionals);
735
797
  if (rawContent !== void 0) {
736
- await runSendOnlyMode(rawContent);
798
+ await runSendOnlyMode(rawContent, ctx.values["auto-send"], ctx.values["send-key"]);
737
799
  return;
738
800
  }
739
801
  const muxValue = ctx.values.mux || "tmux";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "editprompt",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "author": "eetann",
5
5
  "description": "A CLI tool that lets you write prompts for CLI tools using your favorite text editor",
6
6
  "license": "MIT",