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:
wordandpatterndescribe how to choose words to be completed.listspecifies 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.suffixlets you specify a suffix other than space or slash to be added to a successful completion.suffixis 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access