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.
Thanks Carthik, I do believe this is the solution. First turn on smart autocompletion, check to see if your favourite commands autocomplete, and if not, then create a file containing these commands using the link provided.
UPDATE: Working with history in Bash
No comments:
Post a Comment