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

Re: Error in bash completion

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Jun 16, 2021, 19:19 UTC
Message-ID
<60ca4ec28b0f9_56f520855@natae.notmuch>
In-Reply-To
<YMo3j6mqiKBTTEbS@generichostname>
Denton Liu wrote:
Show 37 quoted lines
> Hi Harrison,
> 
> On Wed, Jun 16, 2021 at 09:44:38AM -0600, Harrison McCullough wrote:
> > What did you do before the bug happened? (Steps to reproduce your issue)
> > 
> > 1. Create a Bash function, e.g. `ga() { git add "${@:-.}"; }`
> > 2. Use the `__git_complete` function to add Bash tab completion for your custom
> >    Bash function, e.g. `__git_complete ga git_add`
> > 3. Attempt to tab complete a file path, e.g. `ga my-incomplete-file-path<TAB>`
> > 
> > 
> > What did you expect to happen? (Expected behavior)
> > 
> > Bash tab-completes the file path.
> > 
> > 
> > What happened instead? (Actual behavior)
> > 
> > Bash tab-completes the file path but also displays an error:
> > 
> > $ ga fi-bash: [: -lt: unary operator expected
> > le3.txt
> 
> This happened as a result of my changes at e94fb44042
> (git-completion.bash: pass $__git_subcommand_idx from __git_main(),
> 2021-03-24) and 87e629756f (git-completion.bash: rename to
> $__git_cmd_idx, 2021-04-22).
> 
> The tl;dr is that $__git_cmd_idx must be set to the index of the
> git command you're executing (e.g. for `git add`, the index of `add`).
> As a workaround for you, try setting __git_cmd_idx=0 where you define
> ga().
> 
> Now, a question to the wider list: does git-completion.bash have a
> public interface? I've been working off the assumption that any time a
> user uses the internals, it's at their own risk. Is this a valid
> assumption to make?

Traditionally that was a valid assumption, although in reality people have been using __git_complete for many years.

Since 5a067ba9d0 (completion: add proper public __git_complete, 2020-12-30) __git_complete became officially public, and the internal one is ___git_complete.

Perhaps we could set __git_cmd_idx in __git_complete, but we would also need to consider the zsh equivalent of __git_complete, which is compdef.

-- 
Felipe Contreras
Previous: Harrison McCulloughNext: Felipe Contreras
Message 4 of 6 in “Error in bash completion”
  1. Harrison McCulloughJun 16, 2021
  2. Denton LiuJun 16, 2021
  3. Harrison McCulloughJun 16, 2021
  4. Felipe ContrerasJun 16, 2021
  5. Felipe ContrerasJun 17, 2021
  6. Harrison McCulloughJun 17, 2021

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.