【问题标题】:Enable bash tab completion for Mercurial (hg)为 Mercurial (hg) 启用 bash 选项卡补全
【发布时间】:2011-12-14 11:01:26
【问题描述】:

我在 ubuntu 上安装了 Mercurial (1.4.3-1),默认情况下它不会在 bash 中完成制表符。启用此功能的最简单方法是什么?

【问题讨论】:

  • 您真的应该考虑使用更新的 Mercurial 版本。有可用于 Ubuntu 的 PPA 存储库,您可以启用它们以无缝方式获得 Mercurial 的正常自动更新行为,不会让您落后当前一年多:launchpad.net/~mercurial-ppa/+archive/releases

标签: bash ubuntu mercurial tab-completion


【解决方案1】:

在您的 Linux 中安装 bash-completion 软件包(取决于您使用的 Linux 发行版)。

然后转到/etc/bash_completion.d/ 并创建一个名为hg 的文件 并将此脚本的内容(如下)放入创建的hg 文件中。

http://fts.ifac.cnr.it/cgi-bin/dwww/usr/share/doc/bash/completion-contrib/hg

【讨论】:

  • 不幸的是,上面的链接似乎不再起作用 - 导致 403。
【解决方案2】:

系统范围

适用于所有用户。

$ sudo curl https://www.mercurial-scm.org/repo/hg/raw-file/tip/contrib/bash_completion -o /etc/bash_completion.d/mercurial
$ source /etc/bash_completion.d/mercurial

【讨论】:

    【解决方案3】:
    curl https://www.mercurial-scm.org/repo/hg/raw-file/tip/contrib/bash_completion -o ~/.hg-completion.bash && source ~/.hg-completion.bash
    

    这里似乎维护了善变的自动完成脚本:

    https://www.mercurial-scm.org/repo/hg/file/tip/contrib/bash_completion

    source 这个脚本在你的.bashrc 或等效项中

    【讨论】:

      【解决方案4】:

      bash_completion 脚本位置已更改,因此您需要这样做

      curl https://www.mercurial-scm.org/repo/hg/raw-file/tip/contrib/bash_completion -o ~/.hg-completion.bash && source ~/.hg-completion.bash
      

      而不是

      curl http://www.selenic.com/hg/raw-file/tip/contrib/bash_completion -o ~/.hg-completion.bash && source ~/.hg-completion.bash
      

      【讨论】:

      • 这个答案是跨平台的,不需要 Ubuntu。我在 OS X 上使用它。它应该可以在您拥有 bashcurl(和 hg ;-) 的任何地方使用。
      • 在 OSX 上为我工作。谢谢!
      • 您应该更新它以包括在您的.bashrc 中添加source ~/.hg-completion.bash,这样您就不必在每个新shell 中运行它。
      【解决方案5】:

      由于它既没有标记也没有命名为“ubuntu”,并且因为使用 Fedora 进行谷歌搜索也会导致此处出现问题,所以我将通过在 ~/.bashrc 中引用 /etc/bash_completion.d/mercurial.sh 而不是 /etc/bash_completion 来添加 Martin 的答案的变体:

      # Use bash-completion, if available if [ -f /etc/bash_completion.d/mercurial.sh ]; then . /etc/bash_completion.d/mercurial.sh fi

      不确定操作系统是否需要进行这种区分,但这对我在 Fedora 11 到 20 上有效。

      更正: Fedora 11 和 Fedora 20。(12-19 未测试。)

      【讨论】:

        【解决方案6】:

        你需要

        • 为 Mercurial 安装最新的软件包,请参阅 Mercurial PPA。这将为您提供一个带有 Mercurial 完成代码的 /etc/bash_completion.d/mercurial 文件。您可以直接获取此文件以启用对 Mercurial 的补全支持。

        您还可以为所有程序启用完成支持:

        • 安装bash-completion 包:aptitude install bash-completion

        • 在您的~/.bashrc 文件中输入/etc/bash_completion

          # Use bash-completion, if available
          if [ -f /etc/bash_completion ]; then
            . /etc/bash_completion
          fi
          

          这将启用所有命令的完成,包括 Mercurial。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-04-09
          • 2023-04-10
          • 1970-01-01
          • 2010-09-17
          • 2015-06-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多