Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cygwin git tab completion

I installed Cygwin on windows and one of the default packages is git tab completion, but I don't have tab completion.

I did some searching and found a note saying it isn't enabled by default. I copied the skel .bashrc and .bash_profile to ~ and in .bashrc I uncommented the lines for completion and then relaunched the console. Still nothing.

I then noticed that the file .bash_completion was not present in /etc, so I found a copy of that online and put it in place, but I still have no completion in git.

It seems there should also be a /etc/bash_completion.d directory with git/ in it, but I don't have that either.

like image 523
JAyenGreen Avatar asked Sep 10 '13 15:09

JAyenGreen


People also ask

What is bash completion?

What is Bash completion? Bash completion is a functionality through which Bash helps users type their commands more quickly and easily. It does this by presenting possible options when users press the Tab key while typing a command.

What is git-completion zsh?

fpath : The git-completion. zsh is a function file, not designed to be sourced like the bash script. This command appends the ~/. zsh directory onto the shell's function lookup list.


2 Answers

The answer above prints out bash: have: command not found for nearly every script in bash_completion.d/. This answer from the linked post solves it for me:

if [ -f /etc/bash_completion ]; then . /etc/bash_completion fi

The script/program /etc/bash_completion already includes the scripts in /etc/bash_completion.d and also defines some functions needed by the included scripts.

However, beware that this will slow down the loading of your shell, especially in Cygwin (slowed to about 1 second load for me). To mitigate this, you can rename everything in /etc/bash_completion.d/ to *.bak, and then remove the .bak selectively from the commands you actually care about (thanks to Slow load time of bash in cygwin).

Update: The file /etc/bash_completion magically disappeared (looks like it was due to upgrading the bash-completion package to 2.1-1). As a quick solution, I just created a symlink in /etc to /usr/share/bash-completion/bash_completion.

Update 2: Re-reading the original question, the issue with not having an /etc/bash_completion.d directory might be related to not installing the "bash-completion" package in Cygwin.

like image 38
Johann Avatar answered Sep 21 '22 12:09

Johann


Updated for 2016: Install package bash-completion.

like image 54
sesm Avatar answered Sep 20 '22 12:09

sesm