40 lines
839 B
Bash
Executable File
40 lines
839 B
Bash
Executable File
#!/bin/bash
|
|
# Fix - Ask ollie to fix the selected code
|
|
#
|
|
# Usage: Select code, then middle-click Fix in the tag
|
|
|
|
set -euo pipefail
|
|
|
|
if [[ -z "${winid:-}" ]]; then
|
|
echo "Fix must be run from within acme" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Get the window name (filename) from the tag
|
|
filename=$(9p read acme/$winid/tag | awk '{print $1}')
|
|
|
|
# Read the current selection
|
|
echo 'addr=dot' | 9p write acme/$winid/ctl
|
|
selection=$(9p read acme/$winid/xdata 2>/dev/null || true)
|
|
|
|
if [[ -z "$selection" ]]; then
|
|
echo "No selection. Select some code first." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Build location string
|
|
location=""
|
|
if [[ -n "$filename" && "$filename" != *"+Errors" && "$filename" != "+*" ]]; then
|
|
location=" in \`$filename\`"
|
|
fi
|
|
|
|
# Build the prompt
|
|
prompt="Fix this code${location}:
|
|
|
|
\`\`\`
|
|
$selection
|
|
\`\`\`"
|
|
|
|
# Send to ollie
|
|
echo "$prompt" | o generate
|