bash-completion icon indicating copy to clipboard operation
bash-completion copied to clipboard

COMP_POINT: substring expression < 0 when completing A= ./do

Open kpyrkosz opened this issue 8 months ago • 1 comments

Describe the bug

COMP_POINT: substring expression < 0 when hitting a tab.

To reproduce

  • Type A= ./do
  • Move the cursor one character back, to point between d and o
  • Hit TAB
  • COMP_POINT: substring expression < 0 error pops up

Expected behavior

Not an error

Versions (please complete the following information)

Tested on Debian Stable (2.11-6) and Sid (2.16.0-7).

  • [ ] Operating system name/distribution and version: Debian Stable

  • [ ] bash version 5.2.15(1)-release

  • [ ] bash-completion version 2.11

  • [ ] Operating system name/distribution and version: Debian Sid

  • [ ] bash version 5.2.37(1)-release

  • [ ] bash-completion version 2.16.0

Debug trace

$ A= ./d+ local words
+ unset -v words
+ local offset i
+ offset=1
+ (( i = 1 ))
+ (( i <= COMP_CWORD ))
+ _comp_command_offset 1
+ local REPLY
+ _comp__find_original_word 1
+ REPLY=1
+ [[ -v cword ]]
+ return 0
+ local word_offset=1
+ local COMP_LINE=./do COMP_POINT=3 COMP_CWORD=0
+ comp_words=('./do')
+ local -a comp_words
+ COMP_WORDS=('./do')
+ local -a COMP_WORDS
+ local i tail
+ (( i = 0 ))
+ (( i < word_offset ))
+ tail=
+ (( COMP_POINT -= 4 - 0 ))
+ COMP_LINE=
+ (( i++ ))
+ (( i < word_offset ))
+ COMP_WORDS=("${COMP_WORDS[@]:word_offset}")
+ (( COMP_CWORD -= word_offset ))
+ COMPREPLY=()
+ local cur
+ _comp_get_words cur
+ local exclude= flag i OPTIND=1
+ words=()
+ local cur cword words
+ upargs=()
+ upvars=()
+ local upargs upvars vcur= vcword= vprev= vwords=
+ getopts c:i:n:p:w: flag cur
+ [[ 1 -ge 1 ]]
+ case ${!OPTIND} in
+ vcur=cur
+ (( OPTIND += 1 ))
+ [[ 1 -ge 2 ]]
+ _comp__get_cword_at_cursor '' words cword cur
+ words=()
+ local cword words
+ _comp__reassemble_words '' words cword
+ local exclude= i j line ref
+ [[ -n '' ]]
+ printf -v cword %s -1
+ [[ -n '' ]]
bash: COMP_POINT: substring expression < 0

kpyrkosz avatar May 19 '25 19:05 kpyrkosz

I confirmed the problem. This happens with Bash 4.3..5.3-rc1. This doesn't happen with Bash 4.2. The completion function for do seems to be called for the command line A= ./d[TAB]o.

$ bash-5.2 --norc
$ complete -F _test aa; _test() { declare -p "${!COMP_@}"; }
$ complete -p
complete -F _test aa
$ A= a[TAB]a
declare -- COMP_CWORD="0"
declare -- COMP_KEY="9"
declare -- COMP_LINE="aa"
declare -- COMP_POINT="1"
declare -- COMP_TYPE="9"
declare -- COMP_WORDBREAKS=$' \t\n"\'@><=;|&(:'
declare -a COMP_WORDS=([0]="aa")

This is not supposed to happen because the completion setting for do should be used for the arguments of do (but not the command name itself). I think this is a bug of Bash.

akinomyoga avatar May 19 '25 21:05 akinomyoga