Bash Completion

Swobodin's picture
Submitted by Swobodin on Fri, 2006-05-12 10:40. ::
Bash completion is a collection of shell functions that take advantage of the programmable completion feature of bash 2.04 and later.
Installation is easy, type as root
yum install bash-completion
and activate it
source /etc/bashrc
Once you hit "tab" key, completion is more "intelligent", for example:
  • It only displays directory with "cd"
  • Only displays image files with "display"
  • Displays available manual pages with "man"
  • Shows mount points with "mount"
  • Shows commandline options for the most useful commands, eg. "rpm", "ls", "perl", "mkisofs", etc.
  • Displays possible words of dictionary with "look" command
  • Recognizes environment variables, aliases and functions
  • Can find commandlines and binaries in path within a script (a loop "for", "while", ...)
Of course, the program is not intelligent to understand what you want to execute, that's why you may modify, add, delete some features.
For example, to add "SVG" extension to "display", edit /etc/bash_completion and change the line ending with display (Vim search: /^complete.*display$) adding "|SVG" within the entries.
To add extensions to "php" command, append
complete -f -X '!*.@(php|php3|php4|php5|phtml|inc)' php
To disable that feature (I don't see a reason to do it), rename the profile file
mv /etc/profile.d/bash_completion.sh{,.bak}