All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: Denton Liu <liu.denton@gmail.com>,
	Harrison McCullough <mccullough.harrison@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Error in bash completion
Date: Wed, 16 Jun 2021 14:19:30 -0500	[thread overview]
Message-ID: <60ca4ec28b0f9_56f520855@natae.notmuch> (raw)
In-Reply-To: <YMo3j6mqiKBTTEbS@generichostname>

Denton Liu wrote:
> 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

  parent reply	other threads:[~2021-06-16 19:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-16 15:44 Harrison McCullough
2021-06-16 17:40 ` Denton Liu
2021-06-16 18:05   ` Harrison McCullough
2021-06-16 19:19   ` Felipe Contreras [this message]
2021-06-17  2:06 ` Felipe Contreras
2021-06-17  2:15   ` Harrison McCullough

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=60ca4ec28b0f9_56f520855@natae.notmuch \
    --to=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=liu.denton@gmail.com \
    --cc=mccullough.harrison@gmail.com \
    --subject='Re: Error in bash completion' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.