From: Fabian Wermelinger <fabianw@mavt.ethz.ch>
To: <git@vger.kernel.org>
Cc: Fabian Wermelinger <fabianw@mavt.ethz.ch>
Subject: [PATCH] completion: bash: fix late declaration of __git_cmd_idx
Date: Fri, 18 Jun 2021 16:02:57 +0200 [thread overview]
Message-ID: <20210618140256.256481-1-fabianw@mavt.ethz.ch> (raw)
A recent update to contrib/completion/git-completion.bash causes bash to fail
auto complete custom commands that are wrapped with __git_func_wrap. Declaring
__git_cmd_idx=0 inside __git_func_wrap resolves the issue.
Signed-off-by: Fabian Wermelinger <fabianw@mavt.ethz.ch>
---
Fixes `bash: [: -lt: unary operator expected` error for tab completions
of wrapped `git` commands. For example, assume the convenience command
`gaa` defined in a shell script as
```bash
git aa "$@"
```
where `git aa` is an alias to `git add --all`. Then `gaa` is wrapped
for bash completion like
```bash
__git_complete gaa _git_add
```
For this example, the current bash completion fails at
`contrib/completion/git-completion.bash:1190` due to empty local
variable `c` as `__git_cmd_idx` is empty at the definition in
`contrib/completion/git-completion.bash:1179`. Defining
`__git_cmd_idx=0` earlier in `__git_func_wrap` attempts to solve this
problem.
contrib/completion/git-completion.bash | 1 +
1 file changed, 1 insertion(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b50c5d0ea3..ca5b456173 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3512,6 +3512,7 @@ fi
__git_func_wrap ()
{
local cur words cword prev
+ local __git_cmd_idx=0
_get_comp_words_by_ref -n =: cur words cword prev
$1
}
--
2.32.0
next reply other threads:[~2021-06-18 14:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-18 14:02 Fabian Wermelinger [this message]
2021-06-18 19:09 ` [PATCH] completion: bash: fix late declaration of __git_cmd_idx Felipe Contreras
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=20210618140256.256481-1-fabianw@mavt.ethz.ch \
--to=fabianw@mavt.ethz.ch \
--cc=git@vger.kernel.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).