Score:0

Git autocompletions raises the error "bash: [: -lt: unary operator expected"

in flag

In a Ubuntu 21.10 (new computer with setup) with git version 2.32.0 and bash version 5.1.8(1)-release (x86_64-pc-linux-gnu)

I can't use alias for git checkout because it generates the error bash: [: -lt: unary operator expected.

So, in my .bashrc i have

alias gitc="git checkout"
. /usr/share/bash-completion/bash_completion

and then

source /usr/share/bash-completion/completions/git
__git_complete gitc _git_checkout

And when I try to change to "develop" branch typing "gitc deve" + tab => I get the mentioned error

All the posts I found regarding this error are very old, actually the file /usr/share/bash-completion/completions/git I can see the comment:

# Compatible with bash 3.2.57.

Does anybody have solved this issue?

Thanks

------ Edited at CPH`s request:

I had to change the funtion in line 3512, from

__git_func_wrap ()
{
    local cur words cword prev
    ...

to

__git_func_wrap ()
{
    local cur words cword prev __git_cmd_idx=1
    ...
CPH avatar
in flag
CPH
Can you share the contents of /usr/share/bash-completion/bash_completion?
in flag
Sure,... well what I've done is exactly what the associated question says, anyway I edit my question
CPH avatar
in flag
CPH
Ahh, glad you found your answer!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.