Active only inside LLeMbas TTY. llembas-tty.sh loads WezTerm's own integration (OSC 133, OSC 7) unless it is loaded already, and the autocomplete when LLEMBAS_TTY_AUTOCOMPLETE=1: ghost text after the cursor in zsh (asked beside the line editor, after a pause, stopped by a keystroke), a key in bash. Both ask lembas complete --shell and put only cleaned text on the line. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
44 lines
1.6 KiB
Bash
44 lines
1.6 KiB
Bash
# shellcheck shell=bash
|
|
# LLeMbas TTY: prompt autocomplete for bash, on demand.
|
|
#
|
|
# bash cannot draw a suggestion after the cursor, so this is a key: press it
|
|
# and the rest of the line is asked from LLeMbas and put on the line. Nothing
|
|
# runs: you still press Enter yourself.
|
|
#
|
|
# key: Ctrl+X Ctrl+A (set LLEMBAS_TTY_AUTOCOMPLETE_KEY to a readline key
|
|
# sequence before this file is sourced to change it)
|
|
#
|
|
# Active only inside LLeMbas TTY. Loaded by llembas-tty.sh when autocomplete is
|
|
# on, or source this file yourself. The line so far goes to
|
|
# `lembas complete --shell bash` on stdin; nothing is sent for an empty line,
|
|
# for a line that starts with a space, or when the cursor is not at the end.
|
|
|
|
if [ -z "${LLEMBAS_TTY-}" ] || [ -z "${BASH_VERSION-}" ]; then
|
|
return 0
|
|
fi
|
|
case "$-" in
|
|
*i*) ;;
|
|
*) return 0 ;;
|
|
esac
|
|
|
|
__llembas_complete_line() {
|
|
local line="$READLINE_LINE" rest cli="${LLEMBAS_TTY_CLI:-lembas}"
|
|
[ -n "$line" ] || return 0
|
|
case "$line" in
|
|
' '* | *$'\n'*) return 0 ;;
|
|
esac
|
|
[ "$READLINE_POINT" -eq "${#line}" ] || return 0
|
|
[ "${#line}" -le 2000 ] || return 0
|
|
command -v "$cli" >/dev/null 2>&1 || return 0
|
|
rest="$(printf '%s' "$line" | "$cli" complete --shell bash --cwd "$PWD" --timeout-ms 2500 2>/dev/null)" || return 0
|
|
# What comes back is a model's text: one line, no control characters, not endless.
|
|
rest="${rest%%$'\n'*}"
|
|
rest="${rest//[[:cntrl:]]/}"
|
|
rest="${rest:0:500}"
|
|
[ -n "$rest" ] || return 0
|
|
READLINE_LINE="$line$rest"
|
|
READLINE_POINT="${#READLINE_LINE}"
|
|
}
|
|
|
|
bind -x "\"${LLEMBAS_TTY_AUTOCOMPLETE_KEY:-\\C-x\\C-a}\": __llembas_complete_line"
|