Enable bash tab completion for Mercurial (hg)
Asked Answered
F

6

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?

Fuentes answered 24/10, 2011 at 20:28 Comment(1)
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: launchpad.net/~mercurial-ppa/+archive/releasesTodo
C
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.

Candide answered 19/1, 2012 at 7:35 Comment(0)
R
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

Rodriques answered 5/10, 2013 at 20:47 Comment(0)
W
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
Worrell answered 7/2, 2021 at 18:50 Comment(0)
P
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
Pritchard answered 10/9, 2015 at 17:2 Comment(2)
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 ;-).Huntsman
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.Giffy
A
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

Amphibrach answered 24/10, 2011 at 20:48 Comment(2)
Unfortunately the link above doesn't seem to work anymore - results in a 403.Gabriella
I think this is the new location for bash-completion (at least according to the Debian Bullseye repo): github.com/scop/bash-completion .. heres some more info on it: https://mcmap.net/q/519128/-multi-level-bash-completionSpurt
S
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.)

Sobriquet answered 26/11, 2014 at 1:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.