GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||
GeezerVison is showing tldp.org — An Introduction to Programmable Completion Appendix J. An Introduction to Programmable CompletionThe programmable completion feature in Bash permits typing a partial command, then pressing the [Tab] key to auto-complete the command sequence. [1] If multiple completions are possible, then [Tab] lists them all. Let's see how it works.
Tab completion also works for variables and path names.
The Bash complete and compgen builtins make it possible for tab completion to recognize partial parameters and options to commands. In a very simple case, we can use complete from the command-line to specify a short list of acceptable parameters.
The -f option to complete specifies filenames, and -X the filter pattern. For anything more complex, we could write a script that specifies a list of acceptable command-line parameters. The compgen builtin expands a list of arguments to generate completion matches. Let us take a modified version of the UseGetOpt.sh script as an example command. This script accepts a number of command-line parameters, preceded by either a single or double dash. And here is the corresponding completion script, by convention given a filename corresponding to its associated command. Example J-1. Completion script for UseGetOpt.sh
Now, let's try it.
We begin by sourcing the "completion script." This sets the command-line parameters. [2] In the first instance, hitting [Tab] after a single dash, the output is all the possible parameters preceded by one or more dashes. Hitting [Tab] after two dashes gives the possible parameters preceded by two or more dashes. Now, just what is the point of having to jump through flaming hoops to enable command-line tab completion? It saves keystrokes. [3] -- Resources: Bash programmable completion project Mitch Frazier's Linux Journal article, More on Using the Bash Complete Command Steve's excellent two-part article, "An Introduction to Bash Completion": Part 1 and Part 2 Notes
| |||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |