Enhance Bash Completion feature

Date February 10, 2007

as known pressing tabs in the Command Line Interface will complete commands or filenames for you, it’s a very nice feature in bash, i don’t remember most of the commands without this feature, but does this feature need to enhance? when you write cd [tab] then bash will list all files and directories in the directory you are working in, but you just need the directories to be listed.

Imagine typing ssh [Tab] and being able to complete on hosts from your ~/.ssh/known_hosts files. Or typing man 3 str [Tab] and getting a list of all string handling functions in the UNIX manual.

you can do many things like that with bash built in commands like complete for example:
complete -d pushd -C cd
now when you use cd [tab] then the directories should be listed….
there is a nice tool named bash-completion that combines a lot of nice completion features, in slackware you can find it in the extra folder. i dont know about the other distributions but you can find it here, after you install it, you have to source it with ./etc/bash_completion command or you can put it into your ~/.bashrc file by writing some something like this in it

# enable bash completion in interactive shells
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi

Have Fun!


Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Reddit
  • Webnews
  • MisterWong
  • Y!GG

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>