7

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.

Jonik
  • 1,460
  • 3
  • 13
  • 17

3 Answers3

7

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.

Petr Uzel
  • 7,157
  • 4
  • 30
  • 26
  • +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 09:07
6

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.

Paolo
  • 16,955
  • 11
  • 31
  • 40
4

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
maxschlepzig
  • 56,316
  • 50
  • 205
  • 279
  • 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 09:11