git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [BUG] Autocompletion fails with "bash: words: bad array subscript"

From
Jeff King <peff@peff.net>
Date
May 10, 2011, 20:31 UTC
Message-ID
<20110510203101.GG14456@sigill.intra.peff.net>
In-Reply-To
<BANLkTi=nOUEp_J+2dkZZp=HvER-eAdG9eg@mail.gmail.com>
On Tue, May 10, 2011 at 10:13:11PM +0200, Sverre Rabbelier wrote:
Show 10 quoted lines
> This happens if I try use ctrl-shift-r (reverse-i-search) for the
> string `git commit -am "S`, resulting in the following:
> 
> (reverse-i-search)`git commit -am "S': git commit -am "Set new Melange
> version number to 2-0-20110501 in app.yaml.template."
> 
> If I then hit tab, I get:
> 
> $ bash: words: bad array subscriptversion number to 2-0-20110501 in
> app.yaml.template."
I can reproduce it here pretty easily.
Show 10 quoted lines
> Hitting tab again gives:
> 
> bash: words: bad array subscript
> 
> Display all 3032 possibilities? (y or n)
> 
> I have no clue how to debug this, other than that it doesn't happen if
> I don't source ~/code/git/contrib/completion/git-completion.bash.
> 
> Anyone have any idea's?

You can try "set -x" which will show you what was executing. Of course that will spew pages of output. So you'll want to use something like "script", or if you're man enough, "exec 2>stderr" and then do the whole thing blind. ;)

It looks like we set $cword too low at some point, as the problematic code seems to be:

  + upargs+=(-v $vprev "${words[cword - 1]}")
  bash: words: bad array subscript
but I haven't figured out yet where that happens.
-Peff
Previous: Sverre RabbelierNext: Jeff King
Message 2 of 12 in “[BUG] Autocompletion fails with "bash: words: bad array subscript"”
  1. Sverre RabbelierMay 10, 2011
  2. Jeff KingMay 10, 2011
  3. Jeff KingMay 10, 2011
  4. Sverre RabbelierMay 10, 2011
  5. Jeff KingMay 10, 2011
  6. Sverre RabbelierMay 10, 2011
  7. Jeff KingMay 10, 2011
  8. SZEDER GáborMay 10, 2011
  9. Jonathan NiederMay 10, 2011
  10. SZEDER GáborMay 11, 2011
  11. completion: fix array indexing error after reverse history searchSZEDER Gábor, May 10, 2011
  12. Sverre RabbelierMay 10, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.