Programmable Completion in bash

O'Reilly Bash Book Cover

This is one that’s really only going to interest people who use the bash command shell. You may already know how to use filename completion in bash, but this package adds much more flexible argument completion.

One of the wonderful features of DEC’s old TOPS-10 and TOPS-20 operating systems was their ability to complete commands when you typed the escape key (oddly, I remember it as the tab key but maybe UNIX command completion has corrupted my memory).

The bash shell and other shells under UNIX have long supported basic command and filename completion… you’re typing the command name, press the tab key and the system will complete as much of it as it can unambiguously by matching against the set of available command names. If you’re typing the arguments to the command, bash assumes these arguments are filenames and does the same thing against the list of available filenames that start with what you’ve already typed.

Not all command arguments are filenames, though. Some are hostnames, usernames or other things.

The bash_completion package is a simple add-on which lets bash to complete arguments more helpfully. For instance, if I type

ssh apoca

and hit tab, bash will now look in the file that contains known ssh hosts that I’ve used in order to complete “apoca”. This is much more likely to get the result that I want.

It’s a messy solution. It would be best if the applications carried this information themselves; instead, it’s bundled together for a variety of applications and then glued into bash. It’s like the talking dog; the wonder is that it talks at all.

I use bash_completion under Mac OS X and Linux; it should also work well under the various BSD’s, other UNIX implementations and bash under CygWin for Windows.

You can download bash_completion from http://www.caliban.org/bash/index.shtml#completion.

| Print This Post Print This Post

Comments are closed.

Sponsored Links

Warning: include(/home/romkey/cache/apocablog.html) [function.include]: failed to open stream: Permission denied in /web/bfr/www/shinythings.romkey.com/wp-content/themes/bfrblog2/leftbar.php on line 40

Warning: include() [function.include]: Failed opening '/home/romkey/cache/apocablog.html' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /web/bfr/www/shinythings.romkey.com/wp-content/themes/bfrblog2/leftbar.php on line 40

Warning: include(/home/romkey/cache/bfrblog.html) [function.include]: failed to open stream: Permission denied in /web/bfr/www/shinythings.romkey.com/wp-content/themes/bfrblog2/leftbar.php on line 46

Warning: include() [function.include]: Failed opening '/home/romkey/cache/bfrblog.html' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /web/bfr/www/shinythings.romkey.com/wp-content/themes/bfrblog2/leftbar.php on line 46