简体   繁体   中英

Enable bash tab completion for Mercurial (hg)

I've installed Mercurial (1.4.3-1) on ubuntu and it doesn't do tab completion in bash by default. What is the simplest way to enable this feature?

You need to

  • Install an up-to-date package for Mercurial, see the Mercurial PPA . This will give you a /etc/bash_completion.d/mercurial file with the completion code for Mercurial. You can source this file directly to enable completion support for Mercurial.

You can also enable completion support for all programs:

  • Install the bash-completion package: aptitude install bash-completion .

  • Source /etc/bash_completion in your ~/.bashrc file:

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

    This will enable completion for all commands, including Mercurial.

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

The mercurial autocomplete script appears to be maintained here:

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

source this script in your .bashrc or equivalent

The bash_completion script location has changed so you need to do

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

instead of

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

System wide

for all users.

$ 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

Since it's neither tagged nor titled "ubuntu", and because googling with fedora also leads here, I'll add a variation on Martin's answer that works by referencing /etc/bash_completion.d/mercurial.sh instead of /etc/bash_completion in your ~/.bashrc :

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

Not sure if the OS makes this distinction necessary, but this works for me on Fedora 11 through 20.

Correction: Fedora 11 and Fedora 20. (Not tested 12-19.)

Install bash-completion package in your Linux (depends on Linux Distribution you are using).

Then go to /etc/bash_completion.d/ and create a file called hg and put the content of this script (below) into created hg file.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM