Syntax of the complete Command
Now that we've seen some examples, we're in a better position to consider the syntax of the complete command more systematically. complete has several elements because it needs several kinds of information:
completecommand word
/pattern
/list
/suffix
command
is the name of the command to be completed. The argument following it is the rule describing how to complete words for the command.
Completion rules consist of the following parts:
word
andpattern
describe how to choose words to be completed.list
specifies the word list from which to choose completions, e.g., names of files, users, groups, or variables. Alternatively, you can supply your own list of words or run a command to generate them.suffix
lets you specify a suffix other than space or slash to be added to a successful completion.suffix
is optional, but should be a single character if given. To specify explicitly that no suffix at all should be added, include another slash immediately following the one afterlist
.
A completion rule should be quoted if it contains characters like *
that are special to the shell. I find it easiest simply to quote all my rules.
The parts of a completion rule are usually delimited with slashes, but you can use a different character, as shown below:
complete man 'p,*,c,' Comma delimiter complete cd 'p:1:d:' Colon delimiter
Selecting the Word To Be Completed
The word
and pattern
values work together to determine which word or words the completion rule applies to. You can ...
Get Using csh & tcsh now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.