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?
-
2You 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 Answers
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.

- 72,968
- 25
- 171
- 229
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
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

- 28,495
- 9
- 107
- 102
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

- 4,868
- 3
- 28
- 42

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

- 87
- 6
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

- 28,495
- 9
- 107
- 102

- 2,642
- 3
- 24
- 35
-
2Unfortunately 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