From b20f95378febf0e61e4012f14d649e99401a66db Mon Sep 17 00:00:00 2001 From: Ramesh Padmanabhaiah <22363102+codeforester@users.noreply.github.com> Date: Sat, 19 Sep 2026 17:45:32 +0530 Subject: [PATCH 1/2] fix: preserve completion cursor boundaries --- lib/bash/cli/lib_cli.sh | 6 +++--- lib/bash/cli/tests/lib_cli.bats | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/bash/cli/lib_cli.sh b/lib/bash/cli/lib_cli.sh index 2a4ca66..1301cc2 100644 --- a/lib/bash/cli/lib_cli.sh +++ b/lib/bash/cli/lib_cli.sh @@ -1622,11 +1622,11 @@ base_cli_completion_script() { printf '%s\n' ' if [[ "$cursor" =~ ^[0-9]+$ ]]; then cursor=$((10#$cursor)); else cursor=0; fi' printf '%s\n' ' word_count="${#completion_words[@]}"' printf '%s\n' ' if ((cursor > 0)); then' - printf '%s\n' ' if ((cursor < word_count)); then' - printf '%s\n' ' cli_words=( "${completion_words[@]:1:cursor}" )' - printf '%s\n' ' else' + printf '%s\n' ' if ((cursor >= word_count)); then' printf '%s\n' ' cli_words=( "${completion_words[@]:1}" )' printf '%s\n' ' cli_words+=("")' + printf '%s\n' ' else' + printf '%s\n' ' cli_words=( "${completion_words[@]:1:cursor}" )' printf '%s\n' ' fi' printf '%s\n' ' fi' printf '%s\n' ' COMPREPLY=()' diff --git a/lib/bash/cli/tests/lib_cli.bats b/lib/bash/cli/tests/lib_cli.bats index 28669e4..d2557ed 100644 --- a/lib/bash/cli/tests/lib_cli.bats +++ b/lib/bash/cli/tests/lib_cli.bats @@ -760,10 +760,22 @@ EOF _cursor_complete [ "${COMPREPLY[*]}" = user ] + COMP_CWORD=99 + _cursor_complete + [ "${COMPREPLY[*]}" = user ] + COMP_WORDS=(cursor) COMP_CWORD=1 _cursor_complete [ "${COMPREPLY[*]}" = admin ] + + unset COMP_WORDS COMP_CWORD + set -u + _cursor_complete + status=$? + set +u + [ "$status" -eq 0 ] + [ "${COMPREPLY[*]}" = admin ] } @test "completion consumes option values and honors the double-dash boundary" { From e255cc4fc190f27236d8eb2d3f5faa6dd1ae368f Mon Sep 17 00:00:00 2001 From: Ramesh Padmanabhaiah <22363102+codeforester@users.noreply.github.com> Date: Wed, 30 Sep 2026 19:24:12 +0530 Subject: [PATCH 2/2] fix: preserve empty completion cursor word --- lib/bash/cli/lib_cli.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/bash/cli/lib_cli.sh b/lib/bash/cli/lib_cli.sh index 1301cc2..d55a6e1 100644 --- a/lib/bash/cli/lib_cli.sh +++ b/lib/bash/cli/lib_cli.sh @@ -1622,11 +1622,10 @@ base_cli_completion_script() { printf '%s\n' ' if [[ "$cursor" =~ ^[0-9]+$ ]]; then cursor=$((10#$cursor)); else cursor=0; fi' printf '%s\n' ' word_count="${#completion_words[@]}"' printf '%s\n' ' if ((cursor > 0)); then' + printf '%s\n' ' cli_words=( "${completion_words[@]:1:cursor}" )' printf '%s\n' ' if ((cursor >= word_count)); then' - printf '%s\n' ' cli_words=( "${completion_words[@]:1}" )' + printf '%s\n' ' # COMP_CWORD at or beyond the array end means the current word is empty.' printf '%s\n' ' cli_words+=("")' - printf '%s\n' ' else' - printf '%s\n' ' cli_words=( "${completion_words[@]:1:cursor}" )' printf '%s\n' ' fi' printf '%s\n' ' fi' printf '%s\n' ' COMPREPLY=()'