From a74deceb982970ae38b6b9052ed65b0deb14c00c Mon Sep 17 00:00:00 2001 From: Alex Pasmantier <47638216+alexpasmantier@users.noreply.github.com> Date: Tue, 31 Dec 2024 18:21:07 +0100 Subject: [PATCH] fix(shell): add space if needed when using smart autocomplete (#200) --- crates/television-utils/shell/completion.bash | 3 +++ crates/television-utils/shell/completion.fish | 2 ++ crates/television-utils/shell/completion.zsh | 2 ++ 3 files changed, 7 insertions(+) diff --git a/crates/television-utils/shell/completion.bash b/crates/television-utils/shell/completion.bash index ef0281f..e570403 100644 --- a/crates/television-utils/shell/completion.bash +++ b/crates/television-utils/shell/completion.bash @@ -4,6 +4,9 @@ function tv_smart_autocomplete() { local output=$(tv --autocomplete-prompt "$current_prompt") if [[ -n $output ]]; then + # add a space if the prompt does not end with one + [[ "${current_prompt}" != *" " ]] && current_prompt="${current_prompt} " + READLINE_LINE=$current_prompt$output READLINE_POINT=${#READLINE_LINE} fi diff --git a/crates/television-utils/shell/completion.fish b/crates/television-utils/shell/completion.fish index 222c727..6e84ebe 100644 --- a/crates/television-utils/shell/completion.fish +++ b/crates/television-utils/shell/completion.fish @@ -4,6 +4,8 @@ function tv_smart_autocomplete set -l output (tv --autocomplete-prompt "$current_prompt") if test -n "$output" + # add a space if the prompt does not end with one + string match -q "* " -- "$current_prompt" || set current_prompt "$current_prompt " commandline -r "$current_prompt$output" end end diff --git a/crates/television-utils/shell/completion.zsh b/crates/television-utils/shell/completion.zsh index 3aff40b..2624e44 100644 --- a/crates/television-utils/shell/completion.zsh +++ b/crates/television-utils/shell/completion.zsh @@ -13,6 +13,8 @@ _tv_smart_autocomplete() { if [[ -n $output ]]; then zle reset-prompt RBUFFER="" + # add a space if the prompt does not end with one + [[ "${current_prompt}" != *" " ]] && current_prompt="${current_prompt} " LBUFFER=$current_prompt$output # uncomment this to automatically accept the line