bash Mac OS 中的自动完成 git 不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4569463/
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
Autocomplete git in mac OS not working?
提问by Julio
I am using git in mac. I am trying to have the autocomplete feature. I followed these steps (http://www.codethatmatters.com/2010/01/git-autocomplete-in-mac-os-x/) but I get this error, any idea?
我在 mac 中使用 git。我正在尝试使用自动完成功能。我遵循了这些步骤 (http://www.codethatmatters.com/2010/01/git-autocomplete-in-mac-os-x/) 但我收到了这个错误,知道吗?
: command not found
-bash: /Users/me/git-completion.bash: line 80: syntax error near unex'ected token in
-bash: /Users/me/git-completion.bash: line 80:case "$COMP_WORDBREAK'" in
:未找到命令 -bash:/Users/me/git-completion.bash:第 80 行:在未预期的令牌in
-bash: /Users/me/git-completion.bash: line 80:案例“$COMP_WORDBREAK”附近的语法错误
回答by Julio
I had tried to use curl -O but the url was wrong and I ended up copying the text which caused the error.
我曾尝试使用 curl -O 但网址错误,我最终复制了导致错误的文本。
Using this command made it work perfectly:
使用此命令使其完美运行:
curl -O https://raw.github.com/git/git/master/contrib/completion/git-completion.bash
Thanks a lot everyone for your help!
非常感谢大家的帮助!
回答by Raymond
The git-completion.bash distributed is a Windows file with "\n\r" as a newline. You need to remove the '\r'.
分发的 git-completion.bash 是一个 Windows 文件,以“\n\r”作为换行符。您需要删除“\r”。
For vim users, just do ":set ff=unix".
对于 vim 用户,只需执行 ":set ff=unix"。
回答by jm666
From your error report:
从您的错误报告:
case "$COMP_WORDBREAK'" in
^ the problem is in unpaired apostrophe
回答by Karl Adler
save the file e.g. in gedit with Linux Line-Ending
使用 Linux Line-Ending 在 gedit 中保存文件
回答by nazar kuliyev
Was getting .git-completion.bash: bash: bad interpreter: No such file or directory in Mountain Lion.
正在获取 .git-completion.bash: bash: bad interpreter: 在 Mountain Lion 中没有这样的文件或目录。
Should be "source ~/.git-completion.bash" in ~/.bash_profile
应该是 ~/.bash_profile 中的“source ~/.git-completion.bash”
回答by Jo Liss
Since nobody's answering, quick sanity check: What does bash --versionsay? OS X tends to ship slightly outdated bashes, so if your system is old, it might be a compatibility thing. I'd expect that Bash 3.x works fine, but with 2.x I'm not so sure.
由于没有人回答,请快速检查一下:bash --version说什么?OS X 倾向于发布稍微过时的 bash,所以如果你的系统很旧,它可能是一个兼容性问题。我希望 Bash 3.x 可以正常工作,但对于 2.x,我不太确定。

