From 5e825543dc55a2c649e68dce6341844ad71fa217 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 8 Feb 2026 11:14:36 +0200 Subject: 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 --- internal/tmuxedit/pane.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 internal/tmuxedit/pane.go (limited to 'internal/tmuxedit/pane.go') 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 +} -- cgit v1.2.3