better bash command line completion on Ubuntu

Asked by Rui Mesquita

How can I alter the default command line beaviour in Ubuntu to include command specific tab auto-complete?

For example, in Knoppix if I write "apt-get install libwin" on the console and then press tab, bash magicly completes the rest of the package name, or shows me the various package names starting with libwine.
This works too for the various command specific options.

At one time (recently) I'm pretty sure I had this feature on a Kubuntu installation, though maybe it was not like that from right after install, I may have installed something from the repositories.

thanks

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Dennis Kaarsemaker (dennis) said :
#1

Uncomment the bash_completion lines in your ~/.bashrc - as of dapper
these are uncommented by default.

Revision history for this message
VinceLe (legoll) said :
#2

I don't really intend to RTFM you, really... ;-)

But if the ubuntu-provided completions doesn't suit you, you could just list the available ones from your knoppix, and then configure your bash shell on ubuntu to have the same:

type "complete I grep apt-get" (the I is the pipe character, I don't have one on my keyboard)
this should output the 'complete' command line to set it up the same way on another bash shell, you'll just have to cut'n'paste it there, or put it in your ".bashrc" file...

For the real RTFM part, you could read the man page for bash, maybe it'll amaze you about the possibilities. I've seen absolutely tremedous things programmed in shell.

Type "man bash", and search for the section explaining completion.
Type "/Programmable Completion" when man outputs its proverbial unix-fu enlarging speech...

Revision history for this message
zank (fernandozank) said :
#3

vi ~/.bashrc and uncoment lines

change this:

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

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

Revision history for this message
zank (fernandozank) said :
#4

vi ~/.bashrc (for the current user) or vi /etc/bash.bahsrc for all user

change this:

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

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

Can you help with this problem?

Provide an answer of your own, or ask Rui Mesquita for more information if necessary.

To post a message you must log in.