Chapter 8: Command Line Editing

132

Since we’d like Bash and Readline to take care of some of the other details for us, we use several other options to tell Bash and Readline what to do. The -o filenames option tells Readline that the possible completions should be treated as filenames, and quoted appropriately. That option will also cause Readline to append a slash to filenames it can determine are directories (which is why we might want to extend _comp_cd to append a slash if we’re using directories found via CDPATH : Readline can’t tell those completions are directories). The -o nospace option tells Readline to not append a space character to the directory name, in case we want to append to it. The -o bashdefault option brings in the rest of the "Bash default" completions – possible completion that Bash adds to the default

Readline set. These include things like command name completion, variable completion for words beginning with ‘{’, completions containing pathname expansion patterns (see

Section 3.5.8 [Filename Expansion], page 30), and so on.

Once installed using complete, _comp_cd will be called every time we attempt word completion for a cd command.

Many more examples – an extensive collection of completions for most of the common

GNU, Unix, and Linux commands – are available as part of the bash completion project.

This is installed by default on many GNU/Linux distributions. Originally written by Ian

Macdonald, the project now lives at http: // bash-completion. alioth. debian. org/ .

There are ports for other systems such as Solaris and Mac OS X.

An older version of the bash completion package is distributed with bash in the examples/complete subdirectory.