Turn on Bash Smart Completion January 28, 2006
Posted by Carthik in administration, commands, snippets, ubuntu.trackback
The Bash shell has this sweet feature where you can use the TAB key to auto-complete certain things. For example, when I am in my home directory, the following command:
$cd Do[TAB-key]
will automatically yield:
$cd Documents
If you are an absolute novice, like I was, not so long ago, discovering tab completion in the terminal can make you go “Wow!”. Wait till you hear the rest now
Though you can use the TAB key to complete the names of files and directories, by default the completion is pretty “dumb”. If you have already typed $cd D you would expect that the tab key would cause only the directory names to be completed, but if I try it on my machine, the tab completion tool uses filenames too.
Now, don’t despair! There is now a smart bash tab completion trick you can use. Smart completion even complete the arguments to commands!!
To enable smart completion, edit your /etc/bash.bashrc file. Uncomment the following lines, by removing the # in the beginning of the lines:
#if [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
#fi
Now you can use tab completion to power your way through commands.
You can even extend bash smart completion to your own favourite commands by using /etc/bash_completion, the “complete” utility and /etc/bash_completion.d . Explaining the nitty-gritty is beyond me. I refer you to the Debian Administration gurus for more information regarding smarter bash completion.







good to know!
[...] Another sweet little tip from the Ubuntu Blog: The Bash shell has this sweet feature where you can use the TAB key to auto-complete certain things. For example, when I am in my home directory, the following command: $cd Do[TAB-key] will automatically yield: $cd Documents If you are an absolute novice, like I was, not so long ago, discovering tab completion in the terminal can make you go “Wow!?. Wait till you hear the rest now [...]
I love little things like this which make Ubuntu a much better place
I need to try this. I’ve been wondering if it was possible to auto-complete command arguments.
You can also edit `~/.bashrc` to enable it only for yourself if you don’t want to disturb anybody else or you don’t have the privileges to edit `/etc/bash.bashrc`.
Oh!…
I was really tired of losing tab completion when running anything under sudo…
I come from Debian and doing sudo just everytime is horrible… This stupid trick makes things much easyer.
Thanks!
ozroc, just switch to root using “sudo su”
This is now turned on by default in Kubuntu at least (as of 6.06) and is a pain in the backside as the behaviour isn’t correct in many situations.
So, here is how to turn it off http://www.revis.co.uk/site/?q=node/110 (and reasons why you should, and some workarounds).
Anyone know where to submit a bug report?
ozroc, just switch to root using “sudo su”
“sudo -l” is safer i thought
[...] keep the version number. Otherwise alien adds a “1″ to the version number. - Tip: Use Smart Tab Completion to avoid mistyping the file [...]
thanx!thats what i searched
THANK YOU!!! It was working, reinstalled, and it stopped.
Great! Thanks! Indeed a supplement to my learning at http://www.mlmtraining.com
[...] check this out (better than fixed) http://ubuntu.wordpress.com/2006/01/28/turn-on-bash-smart-completion/ [...]
How about this line to .bashrc
bind ’set completion-ignore-case on’
Now cd doc[TAB]
yields cd Documents
Somebody likes somebody does not like.
[...] http://ubuntu.wordpress.com/2006/01/28/turn-on-bash-smart-completion/ [...]
[...] and it’s too late in the day for extra caffeine, so that’ll have to be it. But, look here for tips on making your tab completion more powerful. It’ll even complete command line [...]
It might help =) http://gentoo-wiki.com/TIP_Use_TAB-completion_when_emerging_packages