How To Add Bash Completion In Debian

Author: Stephan Jau
Revision: v1.0
Last Change: April 26 2009

Introduction

Bash completion is a useful tool for completion of file paths, commands etc. By default it is enabled on Ubuntu but not on Debian. With two simple steps it can also be enabled on Debian.

 

1. Install bash-completion

First of all we need the install the according package:

apt-get install bash-completion

 

2. Add it to the bash profile

Either edit the ~/.bash_profile file to enable it only for a given user or edit /etc/profile to add it system-wide. Add the following code:

if [ -f /etc/bash_completion ]; then
 . /etc/bash_completion
fi

 

3. Try it

In order for it to work you have to log out and relogin and then you can make use of bash completion the usual way. E.g. issue:

apt-g

and then press the TAB key once and the command will be completed to apt-get. Or issue this:

apt

and then press TAB key twice. You can also try with

apt-get install apa

and then press TAB key once to complete as far as possible and a second time to list all options.

Share this page:

15 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: Alex

I've just installed my Debian and the completion works out-of-the-box for all options and filenames. The bash_completion package was installed by default.

By:

did you install a minimal system or just default server?

By: Stuart

Only bash completion for filenames and directories is enabled by default -- bash completion for options and restricting filenames requires the installation of the bash-completion package from lenny onwards.

The completion of "apt-get i" to "apt-get install" will work only with the bash-completion package installed... unless you have a file called "install" in that directory.

   apt-cache show bash-completion

(read first, reply second)

By: nadavkav

as far as i can remember it was always ON :-)

but it is always good to know how to turn it off too.

thanks !

By: Russ

Why would you install an external package? I mean, the completion support is already there. You uncomment the bash completion part in /etc/bash.bashrc and then just source this file in /etc/profile

By: Piki

Ekhm? I have always thought that the completion system was always ON in Debian? I have never needed to turn it on?

By: Anonymous

Hi, please, check out bash completion script for clearcase UNIX tools. Cheers, Jan.

http://jan.tomka.name/project/clearcase-completion-bash

By: Alain

Good evening

I followed the above instructions and copy and paste the informations as asked.

I logged out and i am now unable to logon back

I use a Debian 8.2 upgradeg to 8.5

Regards

 

By: Raymond

Same here. Unable to log back in. Anybody got a solution?

By: Marino

On Jessie (Debian 8) install only the bash-completion package (step 1) and stop here (all else is already set up in your ~/.bashrc file if it's still unmodified after install - you can check if is present the part starting with "enable programmable completion features"). Log off and back on again and try, it should work ...if you're late and can't log back in then press ctrl+alt+f2 to change pts, login by shell and then remove last modify done on your profile file either in /etc or in your home (aka remove step 2) and you should be fine.

By: Alex

Today install on virtualbox debian stretch -- bash autocomplete properly work for regular users. Try to perform this actions: launch a terminal, type su (not sudo!) enter a password and trying to type something like this apt install nginx. Or type something like that: nano ~/.bashrc (under root!). Bash completion don't properly work.

By: sew

You do not need to log out and in again.

Just type this:

. .bashrc

It chould re'source' your environmental settings, including the changes you've just made

By: Stephen

Thanks for this. Worked like a charm.

By: Ruben Alves

# How I solved it

 

I had auto completion problems trying to autocomplete `wget` with `apt-get install wg[TAB][TAB]` and I managed to solve it by removing the `--no-generate` parameter from the flies below:

 

```

/usr/share/bash-completion/completions/apt-cache

/usr/share/bash-completion/completions/apt-get

```

 

It is worth mentioning that these files are available only after you install `bash-completion`.

 

The `--no-generate` parameter I'm referring to can be seen in the line below, but I removed ALL  `--no-generate`, not only from this line: 

https://github.com/scop/bash-completion/blob/master/completions/apt-get#L28

 

# How did I come to this point?

 

I got to this point after running `set -v` previous to `apt-get install wg[TAB][TAB]`, which showed that the command executed was:

```

apt-cache --no-generate pkgnames wg

```

and the output was an error:

```

E: Could not open file  - open (2: No such file or directory)

```

When I executed `apt-cache pkgnames wg` without the `--no-generate` I correctly got the list for autocompletion:

```

[email protected]:/# apt-cache pkgnames wg

wgalician-minimos

wget2

wgaelic

wget

wgerman-medical

wget2-dev

```

Hope this helps.

By: fir

you made me break my profile, i had to fix it