editprompt 0.7.0 → 0.8.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.
Files changed (3) hide show
  1. package/README.md +15 -0
  2. package/dist/index.js +84 -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.0";
13
13
 
14
14
  //#endregion
15
15
  //#region src/modules/tmux.ts
@@ -81,6 +81,14 @@ 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 execAsync$2(`tmux send-keys -t '${paneId}' ${key}`);
86
+ }
87
+ async function sendContentToTmuxPaneNoFocus(paneId, content) {
88
+ await execAsync$2(`tmux if-shell -t '${paneId}' '[ "#{pane_in_mode}" = "1" ]' "copy-mode -q -t '${paneId}'"`);
89
+ await execAsync$2(`tmux send-keys -t '${paneId}' -- '${content.replace(/'/g, "'\\''")}'`);
90
+ console.log(`Content sent to tmux pane: ${paneId}`);
91
+ }
84
92
 
85
93
  //#endregion
86
94
  //#region src/modules/wezterm.ts
@@ -190,6 +198,13 @@ async function clearQuoteText(paneId) {
190
198
  console.log(error);
191
199
  }
192
200
  }
201
+ async function sendKeyToWeztermPane(paneId, key) {
202
+ await execAsync$1(`wezterm cli send-text --no-paste --pane-id '${paneId}' $'${key}'`);
203
+ }
204
+ async function sendContentToWeztermPaneNoFocus(paneId, content) {
205
+ await execAsync$1(`wezterm cli send-text --no-paste --pane-id '${paneId}' -- '${content.replace(/'/g, "'\\''")}'`);
206
+ console.log(`Content sent to wezterm pane: ${paneId}`);
207
+ }
193
208
 
194
209
  //#endregion
195
210
  //#region src/utils/sendConfig.ts
@@ -363,6 +378,50 @@ async function sendContentToPane(content, mux, targetPaneId, alwaysCopy) {
363
378
  }
364
379
  }
365
380
 
381
+ //#endregion
382
+ //#region src/modes/sendOnly.ts
383
+ async function sendContentToPaneWithAutoSend(content, mux, targetPaneId, sendKey) {
384
+ if (mux === "wezterm") {
385
+ await sendContentToWeztermPaneNoFocus(targetPaneId, content);
386
+ await sendKeyToWeztermPane(targetPaneId, sendKey);
387
+ } else {
388
+ await sendContentToTmuxPaneNoFocus(targetPaneId, content);
389
+ await sendKeyToTmuxPane(targetPaneId, sendKey);
390
+ }
391
+ }
392
+ async function runSendOnlyMode(rawContent, autoSend, sendKey) {
393
+ const content = processContent(rawContent);
394
+ if (!content) {
395
+ console.log("No content to send. Exiting.");
396
+ return;
397
+ }
398
+ const config = readSendConfig();
399
+ if (!config.targetPane) {
400
+ console.error("Error: EDITPROMPT_TARGET_PANE environment variable is required in send-only mode");
401
+ process.exit(1);
402
+ }
403
+ if (autoSend) {
404
+ if (!config.mux) {
405
+ console.error("Error: --auto-send requires a multiplexer (tmux or wezterm)");
406
+ process.exit(1);
407
+ }
408
+ try {
409
+ const key = sendKey || (config.mux === "wezterm" ? "\\r" : "Enter");
410
+ await handleAutoSendDelivery(content, config.mux, config.targetPane, key);
411
+ } catch (error) {
412
+ console.error(`Error: ${error instanceof Error ? error.message : "Unknown error"}`);
413
+ process.exit(1);
414
+ }
415
+ return;
416
+ }
417
+ try {
418
+ await handleContentDelivery(content, config.mux, config.targetPane, config.alwaysCopy);
419
+ } catch (error) {
420
+ console.error(`Error: ${error instanceof Error ? error.message : "Unknown error"}`);
421
+ process.exit(1);
422
+ }
423
+ }
424
+
366
425
  //#endregion
367
426
  //#region src/modes/common.ts
368
427
  function outputContent(content) {
@@ -388,6 +447,17 @@ async function handleContentDelivery(content, mux, targetPane, alwaysCopy) {
388
447
  }
389
448
  outputContent(content);
390
449
  }
450
+ async function handleAutoSendDelivery(content, mux, targetPane, sendKey) {
451
+ if (!content || !targetPane) throw new Error("Content and target pane are required");
452
+ try {
453
+ await sendContentToPaneWithAutoSend(content, mux, targetPane, sendKey);
454
+ console.log("Content sent and submitted successfully!");
455
+ } catch (error) {
456
+ console.error(`Failed to send content: ${error instanceof Error ? error.message : "Unknown error"}`);
457
+ throw error;
458
+ }
459
+ outputContent(content);
460
+ }
391
461
 
392
462
  //#endregion
393
463
  //#region src/modes/openEditor.ts
@@ -607,27 +677,6 @@ async function runResumeMode(targetPane, mux) {
607
677
  process.exit(0);
608
678
  }
609
679
 
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
680
  //#endregion
632
681
  //#region src/utils/argumentParser.ts
633
682
  /**
@@ -690,10 +739,22 @@ await cli(process.argv.slice(2), {
690
739
  capture: {
691
740
  description: "Capture mode - copy pane variable to clipboard and clear",
692
741
  type: "boolean"
742
+ },
743
+ "auto-send": {
744
+ description: "Automatically send content and return focus to editor pane",
745
+ type: "boolean"
746
+ },
747
+ "send-key": {
748
+ description: "Key to send after content (default: Enter, requires --auto-send)",
749
+ type: "string"
693
750
  }
694
751
  },
695
752
  async run(ctx) {
696
753
  try {
754
+ if (ctx.values["send-key"] && !ctx.values["auto-send"]) {
755
+ console.error("Error: --send-key requires --auto-send option");
756
+ process.exit(1);
757
+ }
697
758
  if (ctx.values.resume) {
698
759
  if (!ctx.values["target-pane"]) {
699
760
  console.error("Error: --target-pane is required when using --resume");
@@ -733,7 +794,7 @@ await cli(process.argv.slice(2), {
733
794
  }
734
795
  const rawContent = extractRawContent(ctx.rest, ctx.positionals);
735
796
  if (rawContent !== void 0) {
736
- await runSendOnlyMode(rawContent);
797
+ await runSendOnlyMode(rawContent, ctx.values["auto-send"], ctx.values["send-key"]);
737
798
  return;
738
799
  }
739
800
  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.0",
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",