9

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?

AWrightIV
  • 553
  • 7
  • 15
Vincent Scheib
  • 17,142
  • 9
  • 61
  • 77
  • 2
    You should really consider using a newer Mercurial release. There are PPA repositories available for Ubuntu that you can enable to get your normal auto-update behavior of Mercurial in a seamless fashion that won't have you more than a year behind current: https://launchpad.net/~mercurial-ppa/+archive/releases – Ry4an Brase Oct 25 '11 at 02:54

6 Answers6

12

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.

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
5
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

Andrei
  • 10,918
  • 12
  • 76
  • 110
samstav
  • 1,945
  • 1
  • 20
  • 20
2

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
Serge Stroobandt
  • 28,495
  • 9
  • 107
  • 102
1

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
Ludovic Kuty
  • 4,868
  • 3
  • 28
  • 42
user1603602
  • 984
  • 1
  • 7
  • 11
  • This answer is cross-platform and doesn't need Ubuntu. I used it on OS X. It should work everywhere you have `bash`, `curl` (and `hg` ;-). – Ludovic Kuty Jan 16 '17 at 16:49
  • Worked for me on OSX. Thank you! – Brodan Apr 10 '17 at 15:00
  • You should update this to include adding `source ~/.hg-completion.bash` in your `.bashrc` so that you don't have to run this in every new shell. – Brodan Apr 12 '17 at 21:43
0

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.shinstead 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.)

Dan Ross
  • 87
  • 6
0

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

Serge Stroobandt
  • 28,495
  • 9
  • 107
  • 102
Troydm
  • 2,642
  • 3
  • 24
  • 35
  • 2
    Unfortunately the link above doesn't seem to work anymore - results in a 403. – robjohncox Mar 23 '15 at 12:55
  • I think this is the new location for `bash-completion` (at least according to the Debian Bullseye repo): https://github.com/scop/bash-completion .. heres some more info on it: https://stackoverflow.com/a/74662464/4240654 – alchemy Dec 02 '22 at 23:19