summaryrefslogtreecommitdiff
path: root/internal/tmuxedit/pane.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-08 11:14:36 +0200
committerPaul Buetow <paul@buetow.org>2026-02-08 11:14:36 +0200
commit5e825543dc55a2c649e68dce6341844ad71fa217 (patch)
treef7aae1c1d130f08c383f95a23413bdde7843dc0f /internal/tmuxedit/pane.go
parent023ed82e612451caa38ec46106ed9d148ab9a595 (diff)
add hexai-tmux-edit: tmux popup editor for AI agent prompts
New tool that opens $EDITOR in a tmux popup for composing longer prompts when working with AI CLI agents (Claude Code, Cursor, Amp, Aider, etc.). Captures existing prompt text from the target pane, pre-fills the editor, and sends edited text back via tmux send-keys. Config-driven agent detection via regex patterns in [tmux_edit] config section. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/tmuxedit/pane.go')
-rw-r--r--internal/tmuxedit/pane.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/tmuxedit/pane.go b/internal/tmuxedit/pane.go
new file mode 100644
index 0000000..aae2d69
--- /dev/null
+++ b/internal/tmuxedit/pane.go
@@ -0,0 +1,42 @@
+package tmuxedit
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "strings"
+)
+
+// runCommand is the seam for exec.Command().Output(). Override in tests.
+var runCommand = func(name string, args ...string) ([]byte, error) {
+ return exec.Command(name, args...).Output()
+}
+
+// resolveTargetPane determines which tmux pane to target using a fallback
+// chain: explicit flag > HEXAI_TMUX_PANE env var > tmux query for active pane.
+// Returns the pane ID (e.g. "%5") or an error.
+func resolveTargetPane(flagPane string) (string, error) {
+ // 1. Explicit --pane flag
+ if p := strings.TrimSpace(flagPane); p != "" {
+ return p, nil
+ }
+ // 2. Environment variable
+ if p := strings.TrimSpace(os.Getenv("HEXAI_TMUX_PANE")); p != "" {
+ return p, nil
+ }
+ // 3. Query tmux for the active pane in the current window
+ return queryActivePane()
+}
+
+// queryActivePane asks tmux for the active pane ID using display-message.
+func queryActivePane() (string, error) {
+ out, err := runCommand("tmux", "display-message", "-p", "#{pane_id}")
+ if err != nil {
+ return "", fmt.Errorf("cannot determine tmux pane: %w", err)
+ }
+ pane := strings.TrimSpace(string(out))
+ if pane == "" {
+ return "", fmt.Errorf("tmux returned empty pane ID")
+ }
+ return pane, nil
+}