Git Autocompletion:意外令牌“换行”附近的语法错误

时间:2015-02-26 18:01:09

标签: git bash git-bash

我已经看过关于这个问题的不同问题,似乎没有一个与我的相同:Mac 10.10.2上的新git安装

我已使用以下内容安装自动完成功能:

curl -OL https://github.com/git/git/blob/master/contrib/completion/git-completion.bash

我还尝试了以上内容:-O

我在已下载的文件中添加了.

mv ~/git-completion.bash ~/.git-completion.bash

然后我编辑我的bash_profile并插入该行以在终端加载时获得自动加载:

if [ -f ~/.git-completion.bash ]; then
  source ~/.git-completion.bash
fi

重新启动终端:

Users/user/.git-completion.bash: line 4: syntax error near unexpected token `newline'

下载的文件或我的操作系统是否存在问题?

6 个答案:

答案 0 :(得分:5)

/\b(india)\b/i

这不是真正的'.bash'文件。 (看起来像网站html文件)

如果你想git-completion.bash文件,

连接网站“https://github.com/git/git

点击“下载ZIP”按钮

感谢。

答案 1 :(得分:1)

我找到了解决方案。我和你的错误完全相同。

  1. 从中下载文件 https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash并另存为.bash文件
  2. 打开终端
  3. 删除用户文件夹中的任何先前git-completion.bash文件
  4. 将下载的文件复制到用户文件夹
  5. 在终端中键入以下内容,确保您位于用户目录中 mv ~/git-completion.bash ~/.git-completion.bash
  6. 输入终端  nano .bash_profile
  7. ctr + x for mac user
  8. 输入以下代码

    `if [ -f ~/.git-completion.bash ]; then
        source ~/.git-completion.bash
     fi`
    
  9. 按ctr + x退出.bash_profile,选择' Y'
  10. 关闭终端并重新打开。
  11. 要检查自动完成功能,请键入git h并按Tab键以自动完成帮助。

答案 2 :(得分:0)

问题是由下载文件中的换行符引起的。因此,您可以按一下github页面上的“原始”按钮,然后复制脚本的原始内容。然后,使用文本编辑器将git-completion.bash的内容替换为原始内容,保存并可以使用。

答案 3 :(得分:0)

您使用了错误的URL:

curl -o ~/.git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash

答案 4 :(得分:0)

=>Mac 用户

=> 安装自制软件

=> 安装 Git 和 bash-completion: brew install git && brew install bash-completion (注意:如果此安装失败并出现 404 错误,并且您已经安装了 git,只需删除此 brew install 的 git 部分)

=> 将 bash-completion 添加到您的 ~/.bash_profile:

if [ -f brew --prefix/etc/bash_completion.d/git-completion.bash ];然后 . brew --prefix/etc/bash_completion.d/git-completion.bash 菲

答案 5 :(得分:-1)

我收到了类似的错误:git-completion.bash: line 155: syntax error near unexpected token。该文件看起来很好,所以我做了brew install bash并且错误消失了。当前的一个是4.3.39,前一个是:

$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14)

希望它能帮助那些用Google搜索错误信息的人。