bash Cygwin git tab 完成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18722835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 06:31:27  来源:igfitidea点击:

Cygwin git tab completion

bashcygwinbash-completion

提问by JAyenGreen

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

我在 Windows 上安装了 Cygwin,默认包之一是 git tab 完成,但我没有 tab 完成。

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 .bashrcI uncommented the lines for completion and then relaunched the console. Still nothing.

我进行了一些搜索,发现一条说明默认情况下未启用它。我复制了skel .bashrc and .bash_profile to ~ and in .bashrc我取消注释行以完成,然后重新启动控制台。依然没有。

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.

然后我注意到 .bash_completion 文件不存在/etc,所以我在网上找到了一个副本并将其放在适当的位置,但我仍然没有在 git 中完成。

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

里面似乎也应该有一个/etc/bash_completion.d目录git/,但我也没有。

回答by sesm

Updated for 2016:Install package bash-completion.

2016 年更新:安装包bash-completion

回答by Johann

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

bash: have: command not found对于 bash_completion.d/ 中的几乎每个脚本,上面的答案都会打印出来。 链接帖子中的这个答案为我解决了这个问题

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.

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

脚本/程序 /etc/bash_completion 已经包含了 /etc/bash_completion.d 中的脚本,并且还定义了包含的脚本所需的一些功能。

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 .bakselectively from the commands you actually care about (thanks to Slow load time of bash in cygwin).

但是,请注意这会减慢 shell 的加载速度,尤其是在 Cygwin 中(对我来说减慢到大约 1 秒的加载速度)。为了缓解这种情况,您可以将 /etc/bash_completion.d/ 中的所有内容重命名为*.bak,然后有.bak选择地从您真正关心的命令中删除(感谢cygwin 中 bash 的缓慢加载时间)。

Update:The file /etc/bash_completionmagically 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.

更新:该文件/etc/bash_completion神奇地消失了(看起来是由于将 bash-completion 包升级到 2.1-1)。作为一个快速的解决方案,我刚刚在 /etc 中创建了一个指向/usr/share/bash-completion/bash_completion.

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

更新 2:重新阅读原始问题,没有/etc/bash_completion.d目录的问题可能与未在 Cygwin 中安装“bash-completion”包有关。

回答by Johann

In my .bashrc

在我的 .bashrc 中

 for file in /etc/bash_completion.d/* ; do
    source "$file"
 done

回答by Evmorov

To install "git-completion" package run from cmd.exe:

要安装从 cmd.exe 运行的“git-completion”包:

cyg-get git-completion

You don't need to modify your .bashrc after that.

之后你不需要修改你的 .bashrc 。

回答by vito

I stumbled on the same issue few days ago and installing bash-completionwas not enough.

几天前我偶然发现了同样的问题,安装bash-completion还不够。

The issue was solved in my case downloading https://github.com/git/git/blob/master/contrib/completion/git-completion.bashand copying it into /etc/bash_completion.d/

在我下载https://github.com/git/git/blob/master/contrib/completion/git-completion.bash并将其复制到/etc/bash_completion.d/

See also: https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks

另见:https: //git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks

回答by Alfredo Carrillo

I had to install the following Cygwin packages:

我必须安装以下 Cygwin 软件包:

  • bash-completion
  • bash-completion-devel
  • bash-completion
  • bash-completion-devel

回答by bblues

As of May 2016, I was able to get git & svn tab completion working by simply installing the bash-completion package using the Cygwin setup utility (v2.874) found here: https://www.cygwin.com/install.html. Make sure to select the 'Install from Internet' option. The bash-completion package is listed under the Shells category.

截至 2016 年 5 月,我只需使用此处找到的 Cygwin 安装实用程序 (v2.874) 安装 bash-completion 包,即可使 git & svn tab 完成工作:https://www.cygwin.com/install.html . 确保选择“从 Internet 安装”选项。bash-completion 软件包列在 Shells 类别下。