From 251d2e6f5fc9b4b980059c2f502a9c6310e3a015 Mon Sep 17 00:00:00 2001 From: dkmar Date: Thu, 10 Apr 2025 04:33:02 -0700 Subject: [PATCH] feat(shell): bash support completion in the middle of a prompt --- television/utils/shell/completion.bash | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/television/utils/shell/completion.bash b/television/utils/shell/completion.bash index e352efe..f66ecee 100644 --- a/television/utils/shell/completion.bash +++ b/television/utils/shell/completion.bash @@ -1,14 +1,16 @@ function tv_smart_autocomplete() { - local current_prompt="${READLINE_LINE:0:$READLINE_POINT}" + local prompt_prefix="${READLINE_LINE:0:$READLINE_POINT}" + local prompt_suffix="${READLINE_LINE:$READLINE_POINT}" - local output=$(tv --autocomplete-prompt "$current_prompt") + local output=$(tv --autocomplete-prompt "$prompt_prefix" | tr '\n' ' ') if [[ -n $output ]]; then # add a space if the prompt does not end with one - [[ "${current_prompt}" != *" " ]] && current_prompt="${current_prompt} " + [[ "${prompt_prefix}" != *" " ]] && prompt_prefix="${prompt_prefix} " - READLINE_LINE=$current_prompt$output - READLINE_POINT=${#READLINE_LINE} + local lhs=$prompt_prefix$output + READLINE_LINE=$lhs$prompt_suffix + READLINE_POINT=${#lhs} fi }