feat: AI command edit via clipboard + xdotool fallback
gates / consistency-and-conventions (push) Successful in 2m14s
gates / consistency-and-conventions (push) Successful in 2m14s
- _inject_command tries: xclip/wl-copy (clipboard) -> xdotool (typing) -> tmux -> history - Clipboard is primary: user pastes with Ctrl+Shift+V - preinstall.sh: add xdotool and xclip to PACKAGES
This commit is contained in:
@@ -633,7 +633,7 @@ Use conventional prefixes: `feat:`, `fix:`, `docs:`, `refactor:`, `chore:`
|
|||||||
| `bin/pos-system-health` | 209 | Host health dashboard (disk, RAM, services, backup age, fail2ban, docker); exit 1 if any FAIL |
|
| `bin/pos-system-health` | 209 | Host health dashboard (disk, RAM, services, backup age, fail2ban, docker); exit 1 if any FAIL |
|
||||||
| `bin/pos-system-schedule` | 151 | Scheduled jobs: run a command on a timer; notify on threshold/change/error/always or silently |
|
| `bin/pos-system-schedule` | 151 | Scheduled jobs: run a command on a timer; notify on threshold/change/error/always or silently |
|
||||||
| `bin/pos-system-uninstall` | 415 | Remove pos toolkit binaries, services, shell integration, config, and data |
|
| `bin/pos-system-uninstall` | 415 | Remove pos toolkit binaries, services, shell integration, config, and data |
|
||||||
| `bin/pos-ai` | 702 | AI assistant: ask, chat, sessions, capture, models, providers |
|
| `bin/pos-ai` | 716 | AI assistant: ask, chat, sessions, capture, models, providers |
|
||||||
| `bin/pos-config` | 80 | Interactive editor for the tools' runtime config (reads # POS_CONFIG: registry) |
|
| `bin/pos-config` | 80 | Interactive editor for the tools' runtime config (reads # POS_CONFIG: registry) |
|
||||||
| `bin/pos-tree` | 112 | Show the pos CLI command tree: categories, commands, and subcommands |
|
| `bin/pos-tree` | 112 | Show the pos CLI command tree: categories, commands, and subcommands |
|
||||||
| `completions/pos.bash` | 306 | Dynamic bash completion |
|
| `completions/pos.bash` | 306 | Dynamic bash completion |
|
||||||
|
|||||||
+29
-15
@@ -396,23 +396,37 @@ _prompt_run_command() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# Simulate keyboard input to paste command onto the active terminal line.
|
# Inject command for editing: clipboard copy → xdotool typing → tmux → history.
|
||||||
# Tries: xdotool (X11/Wayland) → tmux send-keys → history fallback.
|
# User pastes with Ctrl+Shift+V (X11) or Ctrl+V (Wayland/SSH).
|
||||||
_inject_command() {
|
_inject_command() {
|
||||||
local cmd="$1"
|
local cmd="$1" injected=""
|
||||||
if command -v xdotool >/dev/null 2>&1 && [ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ]; then
|
# 1. Clipboard (most universal — works over SSH via OSC52 in modern terminals)
|
||||||
# xdotool: simulate typing into the focused terminal
|
if command -v xclip >/dev/null 2>&1 && [ -n "${DISPLAY:-}" ]; then
|
||||||
printf '%s\n' "Typing command — edit if needed, press Enter to run." >&2
|
printf '%s' "$cmd" | xclip -selection clipboard && injected="clipboard"
|
||||||
printf '%s' "$cmd" | xdotool type --clearmodifiers --file -
|
elif command -v wl-copy >/dev/null 2>&1 && [ -n "${WAYLAND_DISPLAY:-}" ]; then
|
||||||
elif [ -n "${TMUX:-}" ]; then
|
printf '%s' "$cmd" | wl-copy && injected="clipboard"
|
||||||
# tmux: send keys directly into the pane
|
elif command -v xsel >/dev/null 2>&1 && [ -n "${DISPLAY:-}" ]; then
|
||||||
printf '%s\n' "Typing command — edit if needed, press Enter to run." >&2
|
printf '%s' "$cmd" | xsel --clipboard --input && injected="clipboard"
|
||||||
tmux send-keys "$cmd"
|
|
||||||
else
|
|
||||||
# Fallback: add to history, user presses ↑ to recall
|
|
||||||
history -s "$cmd" 2>/dev/null || true
|
|
||||||
printf '%s\n' "Command added to history — press ↑ to recall, edit, and run." >&2
|
|
||||||
fi
|
fi
|
||||||
|
if [ -n "$injected" ]; then
|
||||||
|
printf '%s\n' "Command copied to clipboard — paste with Ctrl+Shift+V, edit, Enter to run." >&2
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
# 2. xdotool: simulate typing into focused terminal
|
||||||
|
if command -v xdotool >/dev/null 2>&1 && [ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ]; then
|
||||||
|
printf '%s\n' "Typing command — edit if needed, Enter to run." >&2
|
||||||
|
printf '%s' "$cmd" | xdotool type --clearmodifiers --file -
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
# 3. tmux: send keys directly into the pane
|
||||||
|
if [ -n "${TMUX:-}" ]; then
|
||||||
|
printf '%s\n' "Typing command — edit if needed, Enter to run." >&2
|
||||||
|
tmux send-keys "$cmd"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
# 4. Fallback: add to history, user presses ↑ to recall
|
||||||
|
history -s "$cmd" 2>/dev/null || true
|
||||||
|
printf '%s\n' "Command added to history — press ↑ to recall, edit, and run." >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
# ── Machine context appended to the built-in default prompt ─────
|
# ── Machine context appended to the built-in default prompt ─────
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ PACKAGES=(
|
|||||||
python3 python3-pip rclone
|
python3 python3-pip rclone
|
||||||
ffmpeg
|
ffmpeg
|
||||||
libqrencode4 libgtk-3-0 adb
|
libqrencode4 libgtk-3-0 adb
|
||||||
|
xdotool xclip
|
||||||
)
|
)
|
||||||
|
|
||||||
spawn "apt update" sudo apt update
|
spawn "apt update" sudo apt update
|
||||||
|
|||||||
Reference in New Issue
Block a user