jump to navigation

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.

Comments»

1. stian karlsen - January 28, 2006

good to know!

2. AviDardik.com » Turn on Bash Smart Completion - January 28, 2006

[...] 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 [...]

3. Sionide - January 29, 2006

I love little things like this which make Ubuntu a much better place :)

4. James - January 30, 2006

I need to try this. I’ve been wondering if it was possible to auto-complete command arguments.

5. thetorpedodog - February 3, 2006

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`.

6. ozroc - April 4, 2006

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!

7. bumsbacke - July 26, 2006

ozroc, just switch to root using “sudo su”

8. also-rr - October 18, 2006

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? :)

9. Ronnie - December 14, 2006

ozroc, just switch to root using “sudo su”

“sudo -l” is safer i thought

10. Installing using an RPM file « Ubuntu Blog - April 15, 2007

[...] keep the version number. Otherwise alien adds a “1″ to the version number. - Tip: Use Smart Tab Completion to avoid mistyping the file [...]

11. lundner - May 14, 2007

thanx!thats what i searched ;-)

12. the Jester - June 14, 2007

THANK YOU!!! It was working, reinstalled, and it stopped.

13. rengie - June 21, 2007

Great! Thanks! Indeed a supplement to my learning at http://www.mlmtraining.com

14. Web Hosting - ok it definately php was the splash screen one thing Im concerned about though during the boot I seen a few buffer - October 14, 2007

[...] check this out (better than fixed) http://ubuntu.wordpress.com/2006/01/28/turn-on-bash-smart-completion/ [...]

15. AR - November 28, 2007

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.

16. Linux T&T » Blog Archive » Bash completion Ubuntu - January 22, 2008

[...] http://ubuntu.wordpress.com/2006/01/28/turn-on-bash-smart-completion/ [...]

17. Bash Tip #2 | subprocess - March 13, 2008

[...] 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 [...]

18. Alikus - May 5, 2008

It might help =) http://gentoo-wiki.com/TIP_Use_TAB-completion_when_emerging_packages