summaryrefslogtreecommitdiff
path: root/frontends/scripts
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-01 19:44:03 +0200
committerPaul Buetow <paul@buetow.org>2026-02-01 19:44:03 +0200
commit687132aea4c9ea486fc958f042294fb914d3c1c5 (patch)
treebcbca20a3a4762d909b868c7867fccb701e423ef /frontends/scripts
parentaad3c58b14aa90ef88ee12741760517862d7ec29 (diff)
Capture multiline prompt input in popup editor.
Parse boxed prompt lines and join wrapped text for prefill.
Diffstat (limited to 'frontends/scripts')
-rw-r--r--frontends/scripts/tmux-edit-send37
1 files changed, 36 insertions, 1 deletions
diff --git a/frontends/scripts/tmux-edit-send b/frontends/scripts/tmux-edit-send
index 9e70544..af2ffa3 100644
--- a/frontends/scripts/tmux-edit-send
+++ b/frontends/scripts/tmux-edit-send
@@ -51,7 +51,42 @@ cleanup() {
trap cleanup EXIT
prompt_text="$(tmux capture-pane -p -t "$target" -S -2000 2>/dev/null | \
- awk '/^ *│ *→/ && index($0,"INSERT")==0 && index($0,"Add a follow-up")==0 {line=$0} END { if (line!="") { sub(/^.*→ ?/, "", line); sub(/[[:space:]│]+$/, "", line); print line } }')"
+ 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
+ }
+ ')"
if [ -n "$prompt_text" ]; then
printf '%s\n' "$prompt_text" > "$tmpfile"
fi