Feature Request
Add a bash-widget command to generate readline integration for Bash users, similar to the existing zsh-widget.
Motivation
Currently only ZSH is supported. Bash remains widely used, especially on servers and in CI environments.
Proposed Implementation
Bash doesn't have ZSH's POSTDISPLAY variable. Instead, use readline's bind -x to hook keystrokes and manipulate READLINE_LINE/READLINE_POINT.
Suggested Widget Code
# aprender-shell Bash widget
# Add this to your ~/.bashrc
_aprender_suggest() {
local suggestion
suggestion=$(aprender-shell suggest "$READLINE_LINE" 2>/dev/null | head -1 | cut -f1)
if [[ -n "$suggestion" && "$suggestion" != "$READLINE_LINE" ]]; then
local completion="${suggestion#$READLINE_LINE}"
# Store for accept function
_APRENDER_SUGGESTION="$completion"
# Display ghost text (gray)
echo -ne "\001\e[90m\002${completion}\001\e[0m\002"
else
_APRENDER_SUGGESTION=""
fi
}
_aprender_accept() {
if [[ -n "$_APRENDER_SUGGESTION" ]]; then
READLINE_LINE="${READLINE_LINE}${_APRENDER_SUGGESTION}"
READLINE_POINT=${#READLINE_LINE}
_APRENDER_SUGGESTION=""
fi
}
# Bind to keystrokes
bind -x '"\C-i": _aprender_accept' # Tab to accept
Challenges
-
No true ghost-text: Bash readline doesn't support overlay text like ZSH's POSTDISPLAY. Options:
- Print suggestion after cursor, clear on next keystroke (janky)
- Use
ble.sh integration for richer readline features
- Implement as completion menu via
complete -F
-
Performance: bind -x runs on every keystroke - need fast suggestion latency
-
Escape code wrapping: Must use \001...\002 around ANSI codes in readline context
Alternatives Considered
- ble.sh integration: More powerful but adds dependency
- Completion function only:
complete -C "aprender-shell suggest" <cmd> - simpler but less seamless
CLI Addition
Commands:
...
bash-widget Generate Bash widget code
...
Feature Request
Add a
bash-widgetcommand to generate readline integration for Bash users, similar to the existingzsh-widget.Motivation
Currently only ZSH is supported. Bash remains widely used, especially on servers and in CI environments.
Proposed Implementation
Bash doesn't have ZSH's
POSTDISPLAYvariable. Instead, use readline'sbind -xto hook keystrokes and manipulateREADLINE_LINE/READLINE_POINT.Suggested Widget Code
Challenges
No true ghost-text: Bash readline doesn't support overlay text like ZSH's POSTDISPLAY. Options:
ble.shintegration for richer readline featurescomplete -FPerformance:
bind -xruns on every keystroke - need fast suggestion latencyEscape code wrapping: Must use
\001...\002around ANSI codes in readline contextAlternatives Considered
complete -C "aprender-shell suggest" <cmd>- simpler but less seamlessCLI Addition