Using Subversion on the command-line, it intelligently tab-completes available subcommands, etc:

$ svn c<tab>
cat         checkout    cl          co          copy        
changelist  ci          cleanup     commit      cp  

Mercurial, on the other hand, doesn't seem to have tab-completion, at least out of the box:

$ hg c<tab> 
[nothing happens]

Is Bash completion for Mercurial available at all? What's the simplest way to get it working? I'm on Ubuntu 11.04.


In Ubuntu 10.04 it works out of the box for me. In bash:

$ hg c
cat       checkout  clone     commit    copy

Or in zsh:

$ hg c
cat       checkout  ci        clone     co        commit    copy      cp

Perhaps you have a package missing (or you hit a bug).

On my system the completion file is provided by the mercurial package:

$ dpkg -S /etc/bash_completion.d/mercurial 
mercurial: /etc/bash_completion.d/mercurial
  • Thanks - the reason it wasn't working for me was that I had just installed the "mercurial" package and bashrc hadn't been re-read! So e.g. opening a new terminal tab or just typing bash got it working. Well, I'm glad it works without any extra tweaking needed. :) – Jonik Jun 17 '11 at 9:11

Mercurial ships it's own bash completion - see contrib/bash_completion in the tarball. At least on openSUSE, this file is installed to /etc/bash_completion.d/, so that bash completion for mercurial is working automatically. You might need to check Ubuntu's mercurial package, if it installs the completion script.

  • +1, the file /etc/bash_completion.d/mercurial seems to be available indeed in the "mercurial" package on Ubuntu too. See my comment to maxschlepzig's answer... – Jonik Jun 17 '11 at 9:07

I built mercurial from a source release and had to install the completion script myself. This is how to do this:

$ cd
$ wget http://selenic.com/hg/raw-file/25e4d2f35965/contrib/bash_completion -P opt/packages/mercurial
$ echo ". opt/packages/mercurial/bash_completion" >> .bashrc
$ . opt/packages/mercurial/bash_completion

Completion is ON.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.