3

After setting up bash completion support for git (version 2.14.5 on Slackware Linux 14.2) using the file contrib/completion/git-completion.bash from the git master repository as described and already did for other commands, I expected to get git commands as completion words on ususal TAB-completion hits like for git [TAB][TAB]. For instance:

$ git c[TAB][TAB]
checkout commit clone ...

Instead of getting any git commands like checkout, commit, or else, only filenames are suggested or completed. Whereas, when requesting completion with dashes like git --b[TAB][TAB], then git options, like --bare are suggested or completed well.

I know, there are a lot of similar questions out there, but despite searching the answers, I could not find a proper solution to solve this issue.

  • The git-completion.bash file is sourced correctly; after sourcing with . git-completion.bash its functions are available in the executing bash environment, as declare -f shows.
  • The progcomp shell option is on.
  • The git completion function is registered as the output of complete -p git shows:
    $ complete -p git
    complete -o bashdefault -o default -o nospace -F __git_wrap__git_main git
    
  • After inspecting the sourced git-completion.bash file, I can say, the completion function __git_wrap__git_main is called on git [TAB] hits, but the COMPREPLY variable is not filled with completion words when requesting completion without double-dashes --*

Has anybody an idea why only git options are completed while git commands are not?

Nero
  • 33
  • 4

1 Answers1

0

Since Git 2.14, there have been many improvement to completion (Git 2.18 notably), I would first check if the same issue persists with Git 2.26 (possibly using slpkg)

The contrib/completion/git-completion.bash has a rich and recent history.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Basically I am not a friend of reinstalling parts of a working environment. So changing the entire git suite to get in return a simple bash completion working seems quite expensive especially when considering the fact, that the running environment - which heavily uses a lot of the existing git features - is working well. – Nero Mar 27 '20 at 06:43
  • The completion script is a bash script that makes use of the *Bash Completion Facility*. I thought that it could not be a big deal for a completion script to supply *static* completion words; just the **most basic** git commands which `git help` shows. *Far failed. A good example how easy it s to fall into error.* **However, I followed your advice, and compiled git based on its current sources what lead to correct completion functionality.** Although it is not clear why the completion script was not working with version 2.14, there is left to say: Thank you. – Nero Mar 27 '20 at 06:55
  • @Nero You are welcome. That seems indeed a bit extreme as a solution, but I cannot rule out interaction between the up-to-date completion script and an up-to-date Git, which would make said script work correctly (when used with the latest Git release) – VonC Mar 27 '20 at 07:11