From 8f09aa20601c6c8dfc8352fd2c037ca3ae8cbb1d Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Mon, 3 Aug 2026 10:09:32 +0200 Subject: [PATCH] scripts: enable readline in prompt REPL (read -e) Supports C-a, C-e, C-u, C-k, M-b, M-f, arrow keys, etc. Sent prompts and slash commands are added to readline history so up-arrow recalls previous inputs. --- data/scripts/o | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/data/scripts/o b/data/scripts/o index fc54d15..96756fe 100755 --- a/data/scripts/o +++ b/data/scripts/o @@ -171,16 +171,18 @@ cmd_prompt() { echo "Slash commands: /stop /compact /kill /clear /model /backend /cwd /help" echo "" - local buf="" + local buf="" line while true; do + local prompt_str if [[ -z "$buf" ]]; then - printf "\033[1m>\033[0m " + prompt_str=$'\033[1m>\033[0m ' else - printf " " + prompt_str=" " fi - if ! IFS= read -r line; then + if ! IFS= read -e -r -p "$prompt_str" line; then # EOF — send remaining buffer if any if [[ -n "$buf" ]]; then + history -s "$buf" printf '%s\n' "$buf" | ollie-9p write "$path/prompt" fi printf "\n" @@ -188,6 +190,7 @@ cmd_prompt() { fi # Slash commands (only when buffer is empty — first line) if [[ -z "$buf" && "$line" == /* ]]; then + history -s "$line" local cmd="${line#/}" case "$cmd" in stop) echo "stop" | ollie-9p write "$path/ctl"; echo "[stopped]" ;; @@ -212,6 +215,7 @@ cmd_prompt() { fi if [[ -z "$line" && -n "$buf" ]]; then # Blank line sends accumulated buffer + history -s "$buf" printf '%s\n' "$buf" | ollie-9p write "$path/prompt" buf="" elif [[ -z "$line" ]]; then