fix(shell): unite completion naming conventions

This commit is contained in:
dkmar 2025-04-10 05:28:19 -07:00
parent 000d18b32e
commit 7e85dd64dc
3 changed files with 11 additions and 6 deletions

View File

@ -1,15 +1,17 @@
function tv_smart_autocomplete() {
local prompt_prefix="${READLINE_LINE:0:$READLINE_POINT}"
local prompt_suffix="${READLINE_LINE:$READLINE_POINT}"
# prefix (lhs of cursor)
local current_prompt="${READLINE_LINE:0:$READLINE_POINT}"
local output=$(tv --autocomplete-prompt "$prompt_prefix" | tr '\n' ' ')
local output=$(tv --autocomplete-prompt "$current_prompt" | tr '\n' ' ')
if [[ -n $output ]]; then
# suffix (rhs of cursor)
local rhs="${READLINE_LINE:$READLINE_POINT}"
# add a space if the prompt does not end with one
[[ "${prompt_prefix}" != *" " ]] && prompt_prefix="${prompt_prefix} "
[[ "${current_prompt}" != *" " ]] && current_prompt="${current_prompt} "
local lhs=$prompt_prefix$output
READLINE_LINE=$lhs$prompt_suffix
local lhs=$current_prompt$output
READLINE_LINE=$lhs$rhs
READLINE_POINT=${#lhs}
fi
}

View File

@ -1,4 +1,5 @@
function tv_smart_autocomplete
# prefix (lhs of cursor)
set -l current_prompt (commandline -cp)
set -l output (tv --autocomplete-prompt "$current_prompt")

View File

@ -2,6 +2,7 @@ _tv_smart_autocomplete() {
emulate -L zsh
zle -I
# prefix (lhs of cursor)
local current_prompt
current_prompt=$LBUFFER
@ -9,6 +10,7 @@ _tv_smart_autocomplete() {
output=$(tv --autocomplete-prompt "$current_prompt" $* | tr '\n' ' ')
if [[ -n $output ]]; then
# suffix (rhs of cursor)
local rhs=$RBUFFER
# add a space if the prompt does not end with one
[[ "${current_prompt}" != *" " ]] && current_prompt="${current_prompt} "