summaryrefslogtreecommitdiff
path: root/gemfeed
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-01 20:25:07 +0200
committerPaul Buetow <paul@buetow.org>2026-02-01 20:25:07 +0200
commit17de11dd16d86f3e383d7ee0149f458f47341e31 (patch)
treecc4810533c841bace3f2539b601485452d986e29 /gemfeed
parent4a3a5100a571ade1eeb2a91a405a0a2c3be6aaae (diff)
Update content for gemtext
Diffstat (limited to 'gemfeed')
-rw-r--r--gemfeed/2026-02-02-tmux-popup-editor-for-cursor-agent-prompts.gmi288
-rw-r--r--gemfeed/2026-02-02-tmux-popup-editor-for-cursor-agent-prompts.gmi.tpl277
-rw-r--r--gemfeed/atom.xml401
-rw-r--r--gemfeed/tmux-popup-editor-for-cursor-agent-prompts/demo1.pngbin0 -> 66443 bytes
-rw-r--r--gemfeed/tmux-popup-editor-for-cursor-agent-prompts/demo2.pngbin0 -> 79061 bytes
5 files changed, 874 insertions, 92 deletions
diff --git a/gemfeed/2026-02-02-tmux-popup-editor-for-cursor-agent-prompts.gmi b/gemfeed/2026-02-02-tmux-popup-editor-for-cursor-agent-prompts.gmi
new file mode 100644
index 00000000..235fb656
--- /dev/null
+++ b/gemfeed/2026-02-02-tmux-popup-editor-for-cursor-agent-prompts.gmi
@@ -0,0 +1,288 @@
+# A tmux popup editor for Cursor Agent prompts
+
+> Published at 2026-02-01T20:24:16+02:00
+
+...and any other TUI based application
+
+## Table of Contents
+
+* ⇢ A tmux popup editor for Cursor Agent prompts
+* ⇢ ⇢ Why I built this
+* ⇢ ⇢ What it is
+* ⇢ ⇢ How it works (overview)
+* ⇢ ⇢ Challenges and small discoveries
+* ⇢ ⇢ Test cases (for a future rewrite)
+* ⇢ ⇢ (Almost) works with any editor (or any TUI)
+
+## Why I built this
+
+I spend some time in Cursor Agent (the CLI version of the Cursor IDE, I don't like really the IDE), and I also jump between Claude Code CLI, Ampcode, Gemini CLI, OpenAI Codex CLI, OpenCode, and Aider just to see how things are evolving. But for the next month I'll be with Cursor Agent.
+
+Short prompts are fine in the inline input, but for longer prompts I want a real editor: spellcheck, search/replace, multiple cursors, and all the Helix muscle memory I already have.
+
+Cursor Agent has a Vim editing mode, but not Helix. And even in Vim mode I can't use my full editor setup. I want the real thing, not a partial emulation.
+
+=> https://helix-editor.com
+=> https://www.vim.org
+=> https://neovim.io
+
+So I built a tiny tmux popup editor. It opens `$EDITOR` (Helix for me), and when I close it, the buffer is sent back into the prompt. It sounds simple, but it feels surprisingly native.
+
+This is how it looks like:
+
+=> ./tmux-popup-editor-for-cursor-agent-prompts/demo1.png Popup editor in action
+
+## What it is
+
+The idea is straightforward:
+
+* A tmux key binding `prefix-e` opens a popup overlay near the bottom of the screen.
+* The popup starts `$EDITOR` on a temp file.
+* When I exit the editor, the script sends the contents back to the original pane with `tmux send-keys`.
+
+It also pre-fills the temp file with whatever is already typed after Cursor Agent's `→` prompt, so I can continue where I left off.
+
+## How it works (overview)
+
+This is the tmux binding I use (trimmed to the essentials):
+
+```
+bind-key e run-shell -b "tmux display-message -p '#{pane_id}'
+ > /tmp/tmux-edit-target-#{client_pid} \;
+ tmux popup -E -w 90% -h 35% -x 5% -y 65% -d '#{pane_current_path}'
+ \"~/scripts/tmux-edit-send /tmp/tmux-edit-target-#{client_pid}\""
+```
+
+And this is how it looks like after sending back the text to the Cursor Agent's input:
+
+=> ./tmux-popup-editor-for-cursor-agent-prompts/demo2.png Prefilled prompt text
+
+And here is the full script. It is a bit ugly since it's shell (written with Cursor Agent with GPT-5.2-Codex), and I might (let) rewrite it in Go and release it once I have time. But it works well enough for now.
+
+```bash
+#!/usr/bin/env bash
+set -u -o pipefail
+
+declare -i LOG_ENABLED=0
+
+log_file="${TMPDIR:-/tmp}/tmux-edit-send.log"
+
+log() {
+ if [ "$LOG_ENABLED" -eq 1 ]; then
+ printf '%s\n' "$*" >> "$log_file"
+ fi
+}
+
+# Read the target pane id from a temp file created by tmux binding.
+read_target_from_file() {
+ local file_path="$1"
+ if [ -n "$file_path" ] && [ -f "$file_path" ]; then
+ sed -n '1p' "$file_path" | tr -d '[:space:]'
+ fi
+}
+
+# Read the target pane id from tmux environment if present.
+read_target_from_env() {
+ local env_line
+ env_line="$(tmux show-environment -g TMUX_EDIT_TARGET 2>/dev/null || true)"
+ case "$env_line" in
+ TMUX_EDIT_TARGET=*) printf '%s' "${env_line#TMUX_EDIT_TARGET=}" ;;
+ esac
+}
+
+# Resolve the target pane id, falling back to the last pane.
+resolve_target_pane() {
+ local candidate="$1"
+ local current_pane last_pane
+
+ current_pane="$(tmux display-message -p "#{pane_id}" 2>/dev/null || true)"
+ log "current pane=${current_pane:-<empty>}"
+ if [ -n "$candidate" ] && [[ "$candidate" == *"#{"* ]]; then
+ log "format target detected, clearing"
+ candidate=""
+ fi
+ if [ -z "$candidate" ]; then
+ candidate="$(tmux display-message -p "#{last_pane}" 2>/dev/null || true)"
+ elif [ "$candidate" = "$current_pane" ]; then
+ last_pane="$(tmux display-message -p "#{last_pane}" 2>/dev/null || true)"
+ if [ -n "$last_pane" ]; then
+ candidate="$last_pane"
+ fi
+ fi
+ printf '%s' "$candidate"
+}
+
+# Capture the latest multi-line prompt content from the pane.
+capture_prompt_text() {
+ local target="$1"
+ tmux capture-pane -p -t "$target" -S -2000 2>/dev/null | awk '
+ function trim_box(line) {
+ sub(/^ *│ ?/, "", line)
+ sub(/ *│ *$/, "", line)
+ sub(/[[:space:]]+$/, "", line)
+ return line
+ }
+ /^ *│ *→/ && index($0,"INSERT")==0 && index($0,"Add a follow-up")==0 {
+ if (text != "") last = text
+ text = ""
+ capture = 1
+ line = $0
+ sub(/^.*→ ?/, "", line)
+ line = trim_box(line)
+ if (line != "") text = line
+ next
+ }
+ capture {
+ if ($0 ~ /^ *└/) {
+ capture = 0
+ if (text != "") last = text
+ next
+ }
+ if ($0 ~ /^ *│/ && index($0,"INSERT")==0 && index($0,"Add a follow-up")==0) {
+ line = trim_box($0)
+ if (line != "") {
+ if (text != "") text = text " " line
+ else text = line
+ }
+ }
+ }
+ END {
+ if (text != "") last = text
+ if (last != "") print last
+ }
+ '
+}
+
+# Write captured prompt text into the temp file if available.
+prefill_tmpfile() {
+ local tmpfile="$1"
+ local prompt_text="$2"
+ if [ -n "$prompt_text" ]; then
+ printf '%s\n' "$prompt_text" > "$tmpfile"
+ fi
+}
+
+# Ensure the target pane exists before sending keys.
+validate_target_pane() {
+ local target="$1"
+ local pane target_found
+ if [ -z "$target" ]; then
+ log "error: no target pane determined"
+ echo "Could not determine target pane." >&2
+ return 1
+ fi
+ target_found=0
+ for pane in $(tmux list-panes -a -F "#{pane_id}" 2>/dev/null || true); do
+ if [ "$pane" = "$target" ]; then
+ target_found=1
+ break
+ fi
+ done
+ if [ "$target_found" -ne 1 ]; then
+ log "error: target pane not found: $target"
+ echo "Target pane not found: $target" >&2
+ return 1
+ fi
+}
+
+# Send temp file contents to the target pane line by line.
+send_content() {
+ local target="$1"
+ local tmpfile="$2"
+ local prompt_text="$3"
+ local first_line=1
+ local line
+ while IFS= read -r line || [ -n "$line" ]; do
+ if [ "$first_line" -eq 1 ] && [ -n "$prompt_text" ]; then
+ if [[ "$line" == "$prompt_text"* ]]; then
+ line="${line#"$prompt_text"}"
+ fi
+ fi
+ first_line=0
+ tmux send-keys -t "$target" -l "$line"
+ tmux send-keys -t "$target" Enter
+ done < "$tmpfile"
+ log "sent content to $target"
+}
+
+# Main entry point.
+main() {
+ local target_file="${1:-}"
+ local target
+ local editor="${EDITOR:-vi}"
+ local tmpfile
+ local prompt_text
+
+ target="$(read_target_from_file "$target_file" || true)"
+ if [ -n "$target" ]; then
+ log "file target=${target:-<empty>}"
+ rm -f "$target_file"
+ fi
+ if [ -z "$target" ]; then
+ target="${TMUX_EDIT_TARGET:-}"
+ fi
+ log "env target=${target:-<empty>}"
+ if [ -z "$target" ]; then
+ target="$(read_target_from_env || true)"
+ fi
+ log "tmux env target=${target:-<empty>}"
+ target="$(resolve_target_pane "$target")"
+ log "fallback target=${target:-<empty>}"
+
+ tmpfile="$(mktemp "./.tmux-edit-send.XXXXXX.md")"
+ trap 'rm -f "$tmpfile"' EXIT
+
+ prompt_text="$(capture_prompt_text "$target")"
+ prefill_tmpfile "$tmpfile" "$prompt_text"
+
+ "$editor" "$tmpfile"
+ log "editor exited with status $?"
+
+ if [ ! -s "$tmpfile" ]; then
+ log "empty file, nothing sent"
+ exit 0
+ fi
+
+ validate_target_pane "$target"
+ send_content "$target" "$tmpfile" "$prompt_text"
+}
+
+main "$@"
+```
+
+## Challenges and small discoveries
+
+The problems were mostly small but annoying:
+
+* Getting the right target pane was the first hurdle. I ended up storing the pane id in a file because of tmux format expansion quirks.
+* The Cursor UI draws a nice box around the prompt, so the prompt line contains a `│` and other markers. I had to filter those out and strip the box-drawing characters.
+* When I prefilled text and then sent it back, I sometimes duplicated the prompt. Stripping the prefilled prompt text from the first line fixed that.
+
+## Test cases (for a future rewrite)
+
+These are the cases I test whenever I touch the script:
+
+* Single-line prompt: capture everything after `→` and prefill the editor.
+* Multi-line boxed prompt: capture the wrapped lines inside the `│ ... │` box and join them with spaces (no newline in the editor).
+* Ignore UI noise: do not capture lines containing `INSERT` or `Add a follow-up`.
+* Preserve appended text: if I add ` juju` to an existing line, the space before `juju` must survive.
+* No duplicate send: if the prefilled text is still at the start of the first line, it must be stripped once before sending back.
+
+## (Almost) works with any editor (or any TUI)
+
+Although I use Helix, this is just `$EDITOR`. If you prefer Vim, Neovim, or something more exotic, it should work. The same mechanism can be used to feed text into any TUI that reads from a terminal pane, not just Cursor Agent.
+
+One caveat: different agents draw different prompt UIs, so the capture logic depends on the prompt shape. A future version of this script should be more modular in that respect; for now this is just a PoC tailored to Cursor Agent.
+
+If I get a chance, I'll clean it up and rewrite it in Go (and release it properly). For now, I am happy with this little hack. It already feels like a native editing workflow for Cursor Agent prompts.
+
+E-Mail your comments to `paul@nospam.buetow.org` :-)
+
+Other related posts are:
+
+=> ./2026-02-02-tmux-popup-editor-for-cursor-agent-prompts.gmi 2026-02-02 A tmux popup editor for Cursor Agent prompts (You are currently reading this)
+=> ./2025-08-05-local-coding-llm-with-ollama.gmi 2025-08-05 Local LLM for Coding with Ollama on macOS
+=> ./2025-05-02-terminal-multiplexing-with-tmux-fish-edition.gmi 2025-05-02 Terminal multiplexing with `tmux` - Fish edition
+=> ./2024-06-23-terminal-multiplexing-with-tmux.gmi 2024-06-23 Terminal multiplexing with `tmux` - Z-Shell edition
+
+=> ../ Back to the main site
diff --git a/gemfeed/2026-02-02-tmux-popup-editor-for-cursor-agent-prompts.gmi.tpl b/gemfeed/2026-02-02-tmux-popup-editor-for-cursor-agent-prompts.gmi.tpl
new file mode 100644
index 00000000..696328d0
--- /dev/null
+++ b/gemfeed/2026-02-02-tmux-popup-editor-for-cursor-agent-prompts.gmi.tpl
@@ -0,0 +1,277 @@
+# A tmux popup editor for Cursor Agent prompts
+
+> Published at 2026-02-01T20:24:16+02:00
+
+...and any other TUI based application
+
+<< template::inline::toc
+
+## Why I built this
+
+I spend some time in Cursor Agent (the CLI version of the Cursor IDE, I don't like really the IDE), and I also jump between Claude Code CLI, Ampcode, Gemini CLI, OpenAI Codex CLI, OpenCode, and Aider just to see how things are evolving. But for the next month I'll be with Cursor Agent.
+
+Short prompts are fine in the inline input, but for longer prompts I want a real editor: spellcheck, search/replace, multiple cursors, and all the Helix muscle memory I already have.
+
+Cursor Agent has a Vim editing mode, but not Helix. And even in Vim mode I can't use my full editor setup. I want the real thing, not a partial emulation.
+
+=> https://helix-editor.com
+=> https://www.vim.org
+=> https://neovim.io
+
+So I built a tiny tmux popup editor. It opens `$EDITOR` (Helix for me), and when I close it, the buffer is sent back into the prompt. It sounds simple, but it feels surprisingly native.
+
+This is how it looks like:
+
+=> ./tmux-popup-editor-for-cursor-agent-prompts/demo1.png Popup editor in action
+
+## What it is
+
+The idea is straightforward:
+
+* A tmux key binding `prefix-e` opens a popup overlay near the bottom of the screen.
+* The popup starts `$EDITOR` on a temp file.
+* When I exit the editor, the script sends the contents back to the original pane with `tmux send-keys`.
+
+It also pre-fills the temp file with whatever is already typed after Cursor Agent's `→` prompt, so I can continue where I left off.
+
+## How it works (overview)
+
+This is the tmux binding I use (trimmed to the essentials):
+
+```
+bind-key e run-shell -b "tmux display-message -p '#{pane_id}'
+ > /tmp/tmux-edit-target-#{client_pid} \;
+ tmux popup -E -w 90% -h 35% -x 5% -y 65% -d '#{pane_current_path}'
+ \"~/scripts/tmux-edit-send /tmp/tmux-edit-target-#{client_pid}\""
+```
+
+And this is how it looks like after sending back the text to the Cursor Agent's input:
+
+=> ./tmux-popup-editor-for-cursor-agent-prompts/demo2.png Prefilled prompt text
+
+And here is the full script. It is a bit ugly since it's shell (written with Cursor Agent with GPT-5.2-Codex), and I might (let) rewrite it in Go and release it once I have time. But it works well enough for now.
+
+```bash
+#!/usr/bin/env bash
+set -u -o pipefail
+
+declare -i LOG_ENABLED=0
+
+log_file="${TMPDIR:-/tmp}/tmux-edit-send.log"
+
+log() {
+ if [ "$LOG_ENABLED" -eq 1 ]; then
+ printf '%s\n' "$*" >> "$log_file"
+ fi
+}
+
+# Read the target pane id from a temp file created by tmux binding.
+read_target_from_file() {
+ local file_path="$1"
+ if [ -n "$file_path" ] && [ -f "$file_path" ]; then
+ sed -n '1p' "$file_path" | tr -d '[:space:]'
+ fi
+}
+
+# Read the target pane id from tmux environment if present.
+read_target_from_env() {
+ local env_line
+ env_line="$(tmux show-environment -g TMUX_EDIT_TARGET 2>/dev/null || true)"
+ case "$env_line" in
+ TMUX_EDIT_TARGET=*) printf '%s' "${env_line#TMUX_EDIT_TARGET=}" ;;
+ esac
+}
+
+# Resolve the target pane id, falling back to the last pane.
+resolve_target_pane() {
+ local candidate="$1"
+ local current_pane last_pane
+
+ current_pane="$(tmux display-message -p "#{pane_id}" 2>/dev/null || true)"
+ log "current pane=${current_pane:-<empty>}"
+ if [ -n "$candidate" ] && [[ "$candidate" == *"#{"* ]]; then
+ log "format target detected, clearing"
+ candidate=""
+ fi
+ if [ -z "$candidate" ]; then
+ candidate="$(tmux display-message -p "#{last_pane}" 2>/dev/null || true)"
+ elif [ "$candidate" = "$current_pane" ]; then
+ last_pane="$(tmux display-message -p "#{last_pane}" 2>/dev/null || true)"
+ if [ -n "$last_pane" ]; then
+ candidate="$last_pane"
+ fi
+ fi
+ printf '%s' "$candidate"
+}
+
+# Capture the latest multi-line prompt content from the pane.
+capture_prompt_text() {
+ local target="$1"
+ tmux capture-pane -p -t "$target" -S -2000 2>/dev/null | awk '
+ function trim_box(line) {
+ sub(/^ *│ ?/, "", line)
+ sub(/ *│ *$/, "", line)
+ sub(/[[:space:]]+$/, "", line)
+ return line
+ }
+ /^ *│ *→/ && index($0,"INSERT")==0 && index($0,"Add a follow-up")==0 {
+ if (text != "") last = text
+ text = ""
+ capture = 1
+ line = $0
+ sub(/^.*→ ?/, "", line)
+ line = trim_box(line)
+ if (line != "") text = line
+ next
+ }
+ capture {
+ if ($0 ~ /^ *└/) {
+ capture = 0
+ if (text != "") last = text
+ next
+ }
+ if ($0 ~ /^ *│/ && index($0,"INSERT")==0 && index($0,"Add a follow-up")==0) {
+ line = trim_box($0)
+ if (line != "") {
+ if (text != "") text = text " " line
+ else text = line
+ }
+ }
+ }
+ END {
+ if (text != "") last = text
+ if (last != "") print last
+ }
+ '
+}
+
+# Write captured prompt text into the temp file if available.
+prefill_tmpfile() {
+ local tmpfile="$1"
+ local prompt_text="$2"
+ if [ -n "$prompt_text" ]; then
+ printf '%s\n' "$prompt_text" > "$tmpfile"
+ fi
+}
+
+# Ensure the target pane exists before sending keys.
+validate_target_pane() {
+ local target="$1"
+ local pane target_found
+ if [ -z "$target" ]; then
+ log "error: no target pane determined"
+ echo "Could not determine target pane." >&2
+ return 1
+ fi
+ target_found=0
+ for pane in $(tmux list-panes -a -F "#{pane_id}" 2>/dev/null || true); do
+ if [ "$pane" = "$target" ]; then
+ target_found=1
+ break
+ fi
+ done
+ if [ "$target_found" -ne 1 ]; then
+ log "error: target pane not found: $target"
+ echo "Target pane not found: $target" >&2
+ return 1
+ fi
+}
+
+# Send temp file contents to the target pane line by line.
+send_content() {
+ local target="$1"
+ local tmpfile="$2"
+ local prompt_text="$3"
+ local first_line=1
+ local line
+ while IFS= read -r line || [ -n "$line" ]; do
+ if [ "$first_line" -eq 1 ] && [ -n "$prompt_text" ]; then
+ if [[ "$line" == "$prompt_text"* ]]; then
+ line="${line#"$prompt_text"}"
+ fi
+ fi
+ first_line=0
+ tmux send-keys -t "$target" -l "$line"
+ tmux send-keys -t "$target" Enter
+ done < "$tmpfile"
+ log "sent content to $target"
+}
+
+# Main entry point.
+main() {
+ local target_file="${1:-}"
+ local target
+ local editor="${EDITOR:-vi}"
+ local tmpfile
+ local prompt_text
+
+ target="$(read_target_from_file "$target_file" || true)"
+ if [ -n "$target" ]; then
+ log "file target=${target:-<empty>}"
+ rm -f "$target_file"
+ fi
+ if [ -z "$target" ]; then
+ target="${TMUX_EDIT_TARGET:-}"
+ fi
+ log "env target=${target:-<empty>}"
+ if [ -z "$target" ]; then
+ target="$(read_target_from_env || true)"
+ fi
+ log "tmux env target=${target:-<empty>}"
+ target="$(resolve_target_pane "$target")"
+ log "fallback target=${target:-<empty>}"
+
+ tmpfile="$(mktemp "./.tmux-edit-send.XXXXXX.md")"
+ trap 'rm -f "$tmpfile"' EXIT
+
+ prompt_text="$(capture_prompt_text "$target")"
+ prefill_tmpfile "$tmpfile" "$prompt_text"
+
+ "$editor" "$tmpfile"
+ log "editor exited with status $?"
+
+ if [ ! -s "$tmpfile" ]; then
+ log "empty file, nothing sent"
+ exit 0
+ fi
+
+ validate_target_pane "$target"
+ send_content "$target" "$tmpfile" "$prompt_text"
+}
+
+main "$@"
+```
+
+## Challenges and small discoveries
+
+The problems were mostly small but annoying:
+
+* Getting the right target pane was the first hurdle. I ended up storing the pane id in a file because of tmux format expansion quirks.
+* The Cursor UI draws a nice box around the prompt, so the prompt line contains a `│` and other markers. I had to filter those out and strip the box-drawing characters.
+* When I prefilled text and then sent it back, I sometimes duplicated the prompt. Stripping the prefilled prompt text from the first line fixed that.
+
+## Test cases (for a future rewrite)
+
+These are the cases I test whenever I touch the script:
+
+* Single-line prompt: capture everything after `→` and prefill the editor.
+* Multi-line boxed prompt: capture the wrapped lines inside the `│ ... │` box and join them with spaces (no newline in the editor).
+* Ignore UI noise: do not capture lines containing `INSERT` or `Add a follow-up`.
+* Preserve appended text: if I add ` juju` to an existing line, the space before `juju` must survive.
+* No duplicate send: if the prefilled text is still at the start of the first line, it must be stripped once before sending back.
+
+## (Almost) works with any editor (or any TUI)
+
+Although I use Helix, this is just `$EDITOR`. If you prefer Vim, Neovim, or something more exotic, it should work. The same mechanism can be used to feed text into any TUI that reads from a terminal pane, not just Cursor Agent.
+
+One caveat: different agents draw different prompt UIs, so the capture logic depends on the prompt shape. A future version of this script should be more modular in that respect; for now this is just a PoC tailored to Cursor Agent.
+
+If I get a chance, I'll clean it up and rewrite it in Go (and release it properly). For now, I am happy with this little hack. It already feels like a native editing workflow for Cursor Agent prompts.
+
+E-Mail your comments to `paul@nospam.buetow.org` :-)
+
+Other related posts are:
+
+<< template::inline::rindex LLM ollama tmux
+
+=> ../ Back to the main site
diff --git a/gemfeed/atom.xml b/gemfeed/atom.xml
index 003a76b3..c9a51a98 100644
--- a/gemfeed/atom.xml
+++ b/gemfeed/atom.xml
@@ -1,12 +1,320 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
- <updated>2026-01-31T19:49:46+02:00</updated>
+ <updated>2026-02-01T20:24:16+02:00</updated>
<title>foo.zone feed</title>
<subtitle>To be in the .zone!</subtitle>
<link href="gemini://foo.zone/gemfeed/atom.xml" rel="self" />
<link href="gemini://foo.zone/" />
<id>gemini://foo.zone/</id>
<entry>
+ <title>A tmux popup editor for Cursor Agent prompts</title>
+ <link href="gemini://foo.zone/gemfeed/2026-02-02-tmux-popup-editor-for-cursor-agent-prompts.gmi" />
+ <id>gemini://foo.zone/gemfeed/2026-02-02-tmux-popup-editor-for-cursor-agent-prompts.gmi</id>
+ <updated>2026-02-01T20:24:16+02:00</updated>
+ <author>
+ <name>Paul Buetow aka snonux</name>
+ <email>paul@dev.buetow.org</email>
+ </author>
+ <summary>I spend some time in Cursor Agent (the CLI version of the Cursor IDE, I don't like really the IDE), and I also jump between Claude Code CLI, Ampcode, Gemini CLI, OpenAI Codex CLI, OpenCode, and Aider just to see how things are evolving. But for the next month I'll be with Cursor Agent.</summary>
+ <content type="xhtml">
+ <div xmlns="http://www.w3.org/1999/xhtml">
+ <h1 style='display: inline' id='a-tmux-popup-editor-for-cursor-agent-prompts'>A tmux popup editor for Cursor Agent prompts</h1><br />
+<br />
+<span>...and any other TUI based application</span><br />
+<br />
+<h2 style='display: inline' id='table-of-contents'>Table of Contents</h2><br />
+<br />
+<ul>
+<li><a href='#a-tmux-popup-editor-for-cursor-agent-prompts'>A tmux popup editor for Cursor Agent prompts</a></li>
+<li>⇢ <a href='#why-i-built-this'>Why I built this</a></li>
+<li>⇢ <a href='#what-it-is'>What it is</a></li>
+<li>⇢ <a href='#how-it-works-overview'>How it works (overview)</a></li>
+<li>⇢ <a href='#challenges-and-small-discoveries'>Challenges and small discoveries</a></li>
+<li>⇢ <a href='#test-cases-for-a-future-rewrite'>Test cases (for a future rewrite)</a></li>
+<li>⇢ <a href='#almost-works-with-any-editor-or-any-tui'>(Almost) works with any editor (or any TUI)</a></li>
+</ul><br />
+<h2 style='display: inline' id='why-i-built-this'>Why I built this</h2><br />
+<br />
+<span>I spend some time in Cursor Agent (the CLI version of the Cursor IDE, I don&#39;t like really the IDE), and I also jump between Claude Code CLI, Ampcode, Gemini CLI, OpenAI Codex CLI, OpenCode, and Aider just to see how things are evolving. But for the next month I&#39;ll be with Cursor Agent.</span><br />
+<br />
+<span>Short prompts are fine in the inline input, but for longer prompts I want a real editor: spellcheck, search/replace, multiple cursors, and all the Helix muscle memory I already have.</span><br />
+<br />
+<span>Cursor Agent has a Vim editing mode, but not Helix. And even in Vim mode I can&#39;t use my full editor setup. I want the real thing, not a partial emulation.</span><br />
+<br />
+<a class='textlink' href='https://helix-editor.com'>https://helix-editor.com</a><br />
+<a class='textlink' href='https://www.vim.org'>https://www.vim.org</a><br />
+<a class='textlink' href='https://neovim.io'>https://neovim.io</a><br />
+<br />
+<span>So I built a tiny tmux popup editor. It opens <span class='inlinecode'>$EDITOR</span> (Helix for me), and when I close it, the buffer is sent back into the prompt. It sounds simple, but it feels surprisingly native.</span><br />
+<br />
+<span>This is how it looks like:</span><br />
+<br />
+<a href='./tmux-popup-editor-for-cursor-agent-prompts/demo1.png'><img alt='Popup editor in action' title='Popup editor in action' src='./tmux-popup-editor-for-cursor-agent-prompts/demo1.png' /></a><br />
+<br />
+<h2 style='display: inline' id='what-it-is'>What it is</h2><br />
+<br />
+<span>The idea is straightforward:</span><br />
+<br />
+<ul>
+<li>A tmux key binding <span class='inlinecode'>prefix-e</span> opens a popup overlay near the bottom of the screen.</li>
+<li>The popup starts <span class='inlinecode'>$EDITOR</span> on a temp file.</li>
+<li>When I exit the editor, the script sends the contents back to the original pane with <span class='inlinecode'>tmux send-keys</span>.</li>
+</ul><br />
+<span>It also pre-fills the temp file with whatever is already typed after Cursor Agent&#39;s <span class='inlinecode'>→</span> prompt, so I can continue where I left off.</span><br />
+<br />
+<h2 style='display: inline' id='how-it-works-overview'>How it works (overview)</h2><br />
+<br />
+<span>This is the tmux binding I use (trimmed to the essentials):</span><br />
+<br />
+<pre>
+bind-key e run-shell -b "tmux display-message -p &#39;#{pane_id}&#39;
+ &gt; /tmp/tmux-edit-target-#{client_pid} \;
+ tmux popup -E -w 90% -h 35% -x 5% -y 65% -d &#39;#{pane_current_path}&#39;
+ \"~/scripts/tmux-edit-send /tmp/tmux-edit-target-#{client_pid}\""
+</pre>
+<br />
+<span>And this is how it looks like after sending back the text to the Cursor Agent&#39;s input:</span><br />
+<br />
+<a href='./tmux-popup-editor-for-cursor-agent-prompts/demo2.png'><img alt='Prefilled prompt text' title='Prefilled prompt text' src='./tmux-popup-editor-for-cursor-agent-prompts/demo2.png' /></a><br />
+<br />
+<span>And here is the full script. It is a bit ugly since it&#39;s shell (written with Cursor Agent with GPT-5.2-Codex), and I might (let) rewrite it in Go and release it once I have time. But it works well enough for now.</span><br />
+<br />
+<!-- Generator: GNU source-highlight 3.1.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><i><font color="silver">#!/usr/bin/env bash</font></i>
+<b><u><font color="#000000">set</font></u></b> -u -o pipefail
+
+<b><u><font color="#000000">declare</font></u></b> -i LOG_ENABLED=<font color="#000000">0</font>
+
+log_file=<font color="#808080">"${TMPDIR:-/tmp}/tmux-edit-send.log"</font>
+
+log() {
+ <b><u><font color="#000000">if</font></u></b> [ <font color="#808080">"$LOG_ENABLED"</font> -eq <font color="#000000">1</font> ]; <b><u><font color="#000000">then</font></u></b>
+ <b><u><font color="#000000">printf</font></u></b> <font color="#808080">'%s</font>\n<font color="#808080">'</font> <font color="#808080">"$*"</font> &gt;&gt; <font color="#808080">"$log_file"</font>
+ <b><u><font color="#000000">fi</font></u></b>
+}
+
+<i><font color="silver"># Read the target pane id from a temp file created by tmux binding.</font></i>
+read_target_from_file() {
+ <b><u><font color="#000000">local</font></u></b> file_path=<font color="#808080">"$1"</font>
+ <b><u><font color="#000000">if</font></u></b> [ -n <font color="#808080">"$file_path"</font> ] &amp;&amp; [ -f <font color="#808080">"$file_path"</font> ]; <b><u><font color="#000000">then</font></u></b>
+ sed -n <font color="#808080">'1p'</font> <font color="#808080">"$file_path"</font> | tr -d <font color="#808080">'[:space:]'</font>
+ <b><u><font color="#000000">fi</font></u></b>
+}
+
+<i><font color="silver"># Read the target pane id from tmux environment if present.</font></i>
+read_target_from_env() {
+ <b><u><font color="#000000">local</font></u></b> env_line
+ env_line=<font color="#808080">"$(tmux show-environment -g TMUX_EDIT_TARGET 2&gt;/dev/null || true)"</font>
+ <b><u><font color="#000000">case</font></u></b> <font color="#808080">"$env_line"</font> <b><u><font color="#000000">in</font></u></b>
+ TMUX_EDIT_TARGET=*) <b><u><font color="#000000">printf</font></u></b> <font color="#808080">'%s'</font> <font color="#808080">"${env_line#TMUX_EDIT_TARGET=}"</font> ;;
+ <b><u><font color="#000000">esac</font></u></b>
+}
+
+<i><font color="silver"># Resolve the target pane id, falling back to the last pane.</font></i>
+resolve_target_pane() {
+ <b><u><font color="#000000">local</font></u></b> candidate=<font color="#808080">"$1"</font>
+ <b><u><font color="#000000">local</font></u></b> current_pane last_pane
+
+ current_pane=<font color="#808080">"$(tmux display-message -p "</font><i><font color="silver">#{pane_id}" 2&gt;/dev/null || true)"</font></i>
+ log <font color="#808080">"current pane=${current_pane:-&lt;empty&gt;}"</font>
+ <b><u><font color="#000000">if</font></u></b> [ -n <font color="#808080">"$candidate"</font> ] &amp;&amp; [[ <font color="#808080">"$candidate"</font> == *<font color="#808080">"#{"</font>* ]]; <b><u><font color="#000000">then</font></u></b>
+ log <font color="#808080">"format target detected, clearing"</font>
+ candidate=<font color="#808080">""</font>
+ <b><u><font color="#000000">fi</font></u></b>
+ <b><u><font color="#000000">if</font></u></b> [ -z <font color="#808080">"$candidate"</font> ]; <b><u><font color="#000000">then</font></u></b>
+ candidate=<font color="#808080">"$(tmux display-message -p "</font><i><font color="silver">#{last_pane}" 2&gt;/dev/null || true)"</font></i>
+ <b><u><font color="#000000">elif</font></u></b> [ <font color="#808080">"$candidate"</font> = <font color="#808080">"$current_pane"</font> ]; <b><u><font color="#000000">then</font></u></b>
+ last_pane=<font color="#808080">"$(tmux display-message -p "</font><i><font color="silver">#{last_pane}" 2&gt;/dev/null || true)"</font></i>
+ <b><u><font color="#000000">if</font></u></b> [ -n <font color="#808080">"$last_pane"</font> ]; <b><u><font color="#000000">then</font></u></b>
+ candidate=<font color="#808080">"$last_pane"</font>
+ <b><u><font color="#000000">fi</font></u></b>
+ <b><u><font color="#000000">fi</font></u></b>
+ <b><u><font color="#000000">printf</font></u></b> <font color="#808080">'%s'</font> <font color="#808080">"$candidate"</font>
+}
+
+<i><font color="silver"># Capture the latest multi-line prompt content from the pane.</font></i>
+capture_prompt_text() {
+ <b><u><font color="#000000">local</font></u></b> target=<font color="#808080">"$1"</font>
+ tmux capture-pane -p -t <font color="#808080">"$target"</font> -S -<font color="#000000">2000</font> <font color="#000000">2</font>&gt;/dev/null | awk <font color="#808080">'</font>
+<font color="#808080"> function trim_box(line) {</font>
+<font color="#808080"> sub(/^ *│ ?/, "", line)</font>
+<font color="#808080"> sub(/ *│ *$/, "", line)</font>
+<font color="#808080"> sub(/[[:space:]]+$/, "", line)</font>
+<font color="#808080"> return line</font>
+<font color="#808080"> }</font>
+<font color="#808080"> /^ *│ *→/ &amp;&amp; index($0,"INSERT")==0 &amp;&amp; index($0,"Add a follow-up")==0 {</font>
+<font color="#808080"> if (text != "") last = text</font>
+<font color="#808080"> text = ""</font>
+<font color="#808080"> capture = 1</font>
+<font color="#808080"> line = $0</font>
+<font color="#808080"> sub(/^.*→ ?/, "", line)</font>
+<font color="#808080"> line = trim_box(line)</font>
+<font color="#808080"> if (line != "") text = line</font>
+<font color="#808080"> next</font>
+<font color="#808080"> }</font>
+<font color="#808080"> capture {</font>
+<font color="#808080"> if ($0 ~ /^ *└/) {</font>
+<font color="#808080"> capture = 0</font>
+<font color="#808080"> if (text != "") last = text</font>
+<font color="#808080"> next</font>
+<font color="#808080"> }</font>
+<font color="#808080"> if ($0 ~ /^ *│/ &amp;&amp; index($0,"INSERT")==0 &amp;&amp; index($0,"Add a follow-up")==0) {</font>
+<font color="#808080"> line = trim_box($0)</font>
+<font color="#808080"> if (line != "") {</font>
+<font color="#808080"> if (text != "") text = text " " line</font>
+<font color="#808080"> else text = line</font>
+<font color="#808080"> }</font>
+<font color="#808080"> }</font>
+<font color="#808080"> }</font>
+<font color="#808080"> END {</font>
+<font color="#808080"> if (text != "") last = text</font>
+<font color="#808080"> if (last != "") print last</font>
+<font color="#808080"> }</font>
+<font color="#808080"> '</font>
+}
+
+<i><font color="silver"># Write captured prompt text into the temp file if available.</font></i>
+prefill_tmpfile() {
+ <b><u><font color="#000000">local</font></u></b> tmpfile=<font color="#808080">"$1"</font>
+ <b><u><font color="#000000">local</font></u></b> prompt_text=<font color="#808080">"$2"</font>
+ <b><u><font color="#000000">if</font></u></b> [ -n <font color="#808080">"$prompt_text"</font> ]; <b><u><font color="#000000">then</font></u></b>
+ <b><u><font color="#000000">printf</font></u></b> <font color="#808080">'%s</font>\n<font color="#808080">'</font> <font color="#808080">"$prompt_text"</font> &gt; <font color="#808080">"$tmpfile"</font>
+ <b><u><font color="#000000">fi</font></u></b>
+}
+
+<i><font color="silver"># Ensure the target pane exists before sending keys.</font></i>
+validate_target_pane() {
+ <b><u><font color="#000000">local</font></u></b> target=<font color="#808080">"$1"</font>
+ <b><u><font color="#000000">local</font></u></b> pane target_found
+ <b><u><font color="#000000">if</font></u></b> [ -z <font color="#808080">"$target"</font> ]; <b><u><font color="#000000">then</font></u></b>
+ log <font color="#808080">"error: no target pane determined"</font>
+ echo <font color="#808080">"Could not determine target pane."</font> &gt;&amp;<font color="#000000">2</font>
+ <b><u><font color="#000000">return</font></u></b> <font color="#000000">1</font>
+ <b><u><font color="#000000">fi</font></u></b>
+ target_found=<font color="#000000">0</font>
+ <b><u><font color="#000000">for</font></u></b> pane <b><u><font color="#000000">in</font></u></b> $(tmux list-panes -a -F <font color="#808080">"#{pane_id}"</font> <font color="#000000">2</font>&gt;/dev/null || <b><u><font color="#000000">true</font></u></b>); <b><u><font color="#000000">do</font></u></b>
+ <b><u><font color="#000000">if</font></u></b> [ <font color="#808080">"$pane"</font> = <font color="#808080">"$target"</font> ]; <b><u><font color="#000000">then</font></u></b>
+ target_found=<font color="#000000">1</font>
+ <b><u><font color="#000000">break</font></u></b>
+ <b><u><font color="#000000">fi</font></u></b>
+ <b><u><font color="#000000">done</font></u></b>
+ <b><u><font color="#000000">if</font></u></b> [ <font color="#808080">"$target_found"</font> -ne <font color="#000000">1</font> ]; <b><u><font color="#000000">then</font></u></b>
+ log <font color="#808080">