diff --git a/television/utils/shell/completion.bash b/television/utils/shell/completion.bash index f66ecee..8a2bae7 100644 --- a/television/utils/shell/completion.bash +++ b/television/utils/shell/completion.bash @@ -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 } diff --git a/television/utils/shell/completion.fish b/television/utils/shell/completion.fish index b7994cc..97fd9a2 100644 --- a/television/utils/shell/completion.fish +++ b/television/utils/shell/completion.fish @@ -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") diff --git a/television/utils/shell/completion.zsh b/television/utils/shell/completion.zsh index 56a50c6..ad6c7ae 100644 --- a/television/utils/shell/completion.zsh +++ b/television/utils/shell/completion.zsh @@ -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} "