1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
|
.TH "ZSHCOMPCTL" "1" "June 2, 1997" "zsh 3\&.1\&.2"
.SH ""NAME
.'
zshcompctl \- zsh programmable completion
.\" Yodl file: Zsh/compctl.yo
.'
.'
.'
.'
.'
.SH ""DESCRIPTION
.'
.PD 0
.TP
\fBcompctl\fP [ \fB\-CDT\fP ] \fIoptions\fP [ \fIcommand\fP \&.\&.\&. ]
.TP
\fBcompctl\fP [ \fB\-CDT\fP ] \fIoptions\fP [ \fB\-x\fP \fIpattern\fP \fIoptions\fP \fB\-\fP \&.\&.\&. \fB\-\-\fP ] [ \fB+\fP \fIoptions\fP [ \fB\-x\fP \&.\&.\&. \fB\-\-\fP ] \&.\&.\&. [\fB+\fP] ] [ \fIcommand\fP \&.\&.\&. ]
.TP
\fBcompctl\fP \fB\-L\fP [ \fB\-CDT\fP ] [ \fIcommand\fP \&.\&.\&. ]
.TP
\fBcompctl\fP \fB+\fP \fIcommand\fP \&.\&.\&.
.PD
.PP
Control the editor's completion behavior according to the supplied set
of \fIoptions\fP\&. Various editing commands, notably
\fBexpand\-or\-complete\-word\fP, usually bound to tab, will
attempt to complete a word typed by the user, while others, notably
\fBdelete\-char\-or\-list\fP, usually bound to ^D in EMACS editing
mode, list the possibilities; \fBcompctl\fP controls what those
possibilities are\&. They may for example be filenames (the most common
case, and hence the default), shell variables, or words from a
user\-specified list\&.
.'
.'
.'
.'
.'
.'
.'
.'
.SH ""COMMAND FLAGS
.'
Completion of the arguments of a command may be different for each
command or may use the default\&. The behavior when completing the
command word itself may also be separately specified\&. These
correspond to the following flags and arguments, all of which (except
for \fB\-L\fP) may be combined with any combination of the
\fIoptions\fP described subsequently in the section `Option Flags':
.PP
.PD 0
.TP
.PD
\fIcommand\fP \&.\&.\&.
controls completion for the named commands, which must be listed last
on the command line\&. If completion is attempted for a command with a
pathname containing slashes and no completion definition is found, the
search is retried with the last pathname component\&. Note that aliases
are expanded before the command name is determined unless the
\fBCOMPLETE_ALIASES\fP option is set\&. Commands should not be combined
with the \fB\-C\fP, \fB\-D\fP or \fB\-T\fP flags\&.
.'
.TP
\fB\-C\fP
controls completion when the command word itself is being completed\&.
If no \fBcompctl \-C\fP command has been issued, the names of any
executable command (whether in the path or specific to the shell, such
as aliases or functions) are completed\&.
.'
.TP
\fB\-D\fP
controls default completion behavior for the arguments of commands not
assigned any special behavior\&. If no \fBcompctl \-D\fP command has
been issued, filenames are completed\&.
.'
.TP
\fB\-T\fP
supplies completion flags to be used before any other processing is
done, even those given to specific commands with other compctl
definitions\&. This is only useful when combined with extended
completion (the \fB\-x\fP flag, see the section `Extended Completion' below)\&.
Using this flag you can define default behavior
which will apply to all commands without exception, or you can alter
the standard behavior for all commands\&. For example, if your access
to the user database is too slow and/or it contains too many users (so
that completion after `\fB~\fP' is too slow to be usable), you can use
.RS
.PP
.nf
\fBcompctl \-Tx 'C[0,*/*]' \-f \- 's[~]' \-k friends \-S/\fP
.fi
.PP
to complete the strings in the array \fBfriends\fP after a `\fB~\fP'\&.
The first argument is necessary so that this form of ~\-completion is
not tried after the directory name is finished\&.
.RE
.TP
\fB\-L\fP
lists the existing completion behavior in a manner suitable for
putting into a start\-up script; the existing behavior is not changed\&.
Any combination of the above forms may be specified, otherwise all
defined completions are listed\&. Any other flags supplied
are ignored\&.
.'
.TP
\fIno argument\fP
If no argument is given, \fBcompctl\fP lists all defined completions
in an abbreviated form; with a list of \fIoptions\fP, all completions
with those flags set (not counting extended completion) are listed\&.
.'
.PD
.RS
.PP
If the \fB+\fP flag is alone and followed immediately by the \fIcommand\fP
list, the completion behavior for all the commands in the list is reset to
the default\&. In other words, completion will subsequently use the
options specified by the \fB\-D\fP flag\&.
.'
.SH ""OPTION FLAGS
.'
.PD 0
.TP
[ \fB\-fcFBdeaRGovNAIOPZEnbjrzu\fP ]
.TP
[ \fB\-k\fP \fIarray\fP ] [ \fB\-g\fP \fIglobstring\fP ] [ \fB\-s\fP \fIsubststring\fP ]
.TP
[ \fB\-K\fP \fIfunction\fP ] [ \fB\-H\fP \fInum pattern\fP ]
.TP
[ \fB\-Q\fP ] [ \fB\-P\fP \fIprefix\fP ] [ \fB\-S\fP \fIsuffix\fP ]
.TP
[ \fB\-q\fP ] [ \fB\-X\fP \fIexplanation\fP ]
.TP
[ \fB\-l\fP \fIcmd\fP ] [ \fB\-U\fP ]
.PD
.PP
The remaining \fIoptions\fP specify the type of command arguments
to look for during completion\&. Any combination of these flags may be
specified; the result is a sorted list of all the possibilities\&. The
options are as follows\&.
.'
.'
.'
.'
.'
.'
.SS "Simple Flags"
.'
These produce completion lists made up by the shell itself:
.PP
.PD 0
.TP
.PD
\fB\-f\fP
Filenames and filesystem paths\&.
.'
.TP
\fB\-c\fP
Command names, including aliases, shell functions, builtins
and reserved words\&.
.'
.TP
\fB\-F\fP
Function names\&.
.'
.TP
\fB\-B\fP
Names of builtin commands\&.
.'
.TP
\fB\-m\fP
Names of external commands\&.
.'
.TP
\fB\-w\fP
Reserved words\&.
.'
.TP
\fB\-a\fP
Alias names\&.
.'
.TP
\fB\-R\fP
Names of regular (non\-global) aliases\&.
.'
.TP
\fB\-G\fP
Names of global aliases\&.
.'
.TP
\fB\-d\fP
This can be combined with \fB\-F\fP, \fB\-B\fP, \fB\-w\fP,
\fB\-a\fP, \fB\-R\fP and \fB\-G\fP to get names of disabled
functions, builtins, reserved words or aliases\&.
.'
.TP
\fB\-e\fP
This option (to show enabled commands) is in effect by default, but
may be combined with \fB\-d\fP; \fB\-de\fP in combination with
\fB\-F\fP, \fB\-B\fP, \fB\-w\fP, \fB\-a\fP, \fB\-R\fP and \fB\-G\fP
will complete names of functions, builtins, reserved words or aliases
whether or not they are disabled\&.
.'
.TP
\fB\-o\fP
Names of shell options (see
\fIzshoptions\fP(1))\&.
.'
.TP
\fB\-v\fP
Names of any variable defined in the shell\&.
.'
.TP
\fB\-N\fP
Names of scalar (non\-array) parameters\&.
.'
.TP
\fB\-A\fP
Array names\&.
.'
.TP
\fB\-I\fP
Names of integer variables\&.
.'
.TP
\fB\-O\fP
Names of read\-only variables\&.
.'
.TP
\fB\-p\fP
Names of parameters used by the shell (including special parameters)\&.
.'
.TP
\fB\-Z\fP
Names of shell special parameters\&.
.'
.TP
\fB\-E\fP
Names of environment variables\&.
.'
.TP
\fB\-n\fP
Named directories\&.
.'
.TP
\fB\-b\fP
Key binding names\&.
.'
.TP
\fB\-j\fP
Job names: the first word of the job leader's command line\&. This is useful
with the \fBkill\fP builtin\&.
.'
.TP
\fB\-r\fP
Names of running jobs\&.
.'
.TP
\fB\-z\fP
Names of suspended jobs\&.
.'
.TP
\fB\-u\fP
User names\&.
.'
.'
.'
.SS "Flags with Arguments"
.'
These have user supplied arguments to determine how the list of
completions is to be made up:
.PP
.PD 0
.TP
.PD
\fB\-k\fP \fIarray\fP
Names taken from the elements of \fB$\fP\fIarray\fP (note that the `\fB$\fP'
does not appear on the command line)\&.
Alternatively, the argument \fIarray\fP itself may be a set
of space\- or comma\-separated values in parentheses, in which any
delimiter may be escaped with a backslash; in this case the argument
should be quoted\&. For example,
.RS
.PP
.nf
\fBcompctl \-k "(cputime filesize datasize stacksize
coredumpsize resident descriptors)" limit\fP
.fi
.RE
.TP
\fB\-g\fP \fIglobstring\fP
The \fIglobstring\fP is expanded using filename globbing; it should be
quoted to protect it from immediate expansion\&. The resulting
filenames are taken as the possible completions\&. Use `\fB*(/)\fP' instead of
`\fB*/\fP' for directories\&. The \fBfignore\fP special parameter is not
applied to the resulting files\&. More than one pattern may be given
separated by blanks\&. (Note that brace expansion is \fInot\fP part of
globbing\&. Use the syntax `\fB(either|or)\fP' to match alternatives\&.)
.'
.TP
\fB\-s\fP \fIsubststring\fP
The \fIsubststring\fP is split into words and these words are than
expanded using all shell expansion mechanisms (see
\fIzshexpn\fP(1))\&. The resulting words are taken as possible
completions\&. The \fBfignore\fP special parameter is not applied to the
resulting files\&. Note that \fB\-g\fP is faster for filenames\&.
.'
.TP
\fB\-K\fP \fIfunction\fP
Call the given function to get the completions\&. The function is
passed two arguments: the prefix and the suffix of the word on which
completion is to be attempted, in other words those characters before
the cursor position, and those from the cursor position onwards\&. The
function should set the variable \fBreply\fP to an array containing
the completions (one completion per element); note that \fBreply\fP
should not be made local to the function\&. From such a function the
command line can be accessed with the \fB\-c\fP and \fB\-l\fP flags to
the \fBread\fP builtin\&. For example,
.RS
.PP
.nf
\fBfunction whoson { reply=(`users`); }
compctl \-K whoson talk\fP
.fi
.PP
completes only logged\-on users after `\fBtalk\fP'\&. Note that `\fBwhoson\fP' must
return an array, so `\fBreply=`users`\fP' would be incorrect\&.
.RE
.TP
\fB\-H\fP \fInum pattern\fP
The possible completions are taken from the last \fInum\fP history
lines\&. Only words matching \fIpattern\fP are taken\&. If \fInum\fP is
zero or negative the whole history is searched and if \fIpattern\fP is
the empty string all words are taken (as with `\fB*\fP')\&. A typical
use is
.RS
.PP
.nf
\fBcompctl \-D \-f + \-H 0 '' \-X '(No file found; using history)'\fP
.fi
.PP
which forces completion to look back in the history list for a word if
no filename matches\&. The explanation string is useful as it tells
the user that no file of that name exists, which is otherwise
ambiguous\&. (See the next section for \fB\-X\fP)\&.
.RE
.RE
.'
.SS "Control Flags"
.'
These do not directly specify types of name to be completed, but
manipulate the options that do:
.PP
.PD 0
.TP
.PD
\fB\-Q\fP
This instructs the shell not to quote any metacharacters in the possible
completions\&. Normally the results of a completion are inserted into
the command line with any metacharacters quoted so that they are
interpreted as normal characters\&. This is appropriate for filenames
and ordinary strings\&. However, for special effects, such as inserting
a backquoted expression from a completion array (\fB\-k\fP) so that
the expression will not be evaluated until the complete line is
executed, this option must be used\&.
.'
.TP
\fB\-P\fP \fIprefix\fP
The \fIprefix\fP is inserted just before the completed string; any
initial part already typed will be completed and the whole \fIprefix\fP
ignored for completion purposes\&. For example,
.RS
.PP
.nf
\fBcompctl \-j \-P "%" kill\fP
.fi
.PP
inserts a `%' after the kill command and then completes job names\&.
.RE
.TP
\fB\-S\fP \fIsuffix\fP
When a completion is found the \fIsuffix\fP is inserted after
the completed string\&. In the case of menu completion the suffix is
inserted immediately, but it is still possible to cycle through the
list of completions by repeatedly hitting the same key\&.
.'
.TP
\fB\-q\fP
If used with a suffix as specified by the previous option, this
causes the suffix to be removed if the next character typed is a blank
or does not insert anything (the same rule as used for the
\fBAUTO_REMOVE_SLASH\fP option)\&. The option is most useful for list
separators (comma, colon, etc\&.)\&.
.'
.TP
\fB\-l\fP \fIcmd\fP
This option cannot be combined with any other\&. It restricts the range
of command line words that are considered to be arguments\&. If
combined with one of the extended completion patterns `\fBp[\fP\&.\&.\&.\fB]\fP',
`\fBr[\fP\&.\&.\&.\fB]\fP', or `\fBR[\fP\&.\&.\&.\fB]\fP' (see the section `Extended Completion'
below) the range is restricted to the range of arguments
specified in the brackets\&. Completion is then performed as if these
had been given as arguments to the \fIcmd\fP supplied with the
option\&. If the \fIcmd\fP string is empty the first word in the range
is instead taken as the command name, and command name completion
performed on the first word in the range\&. For example,
.RS
.PP
.nf
\fBcompctl \-x 'r[\-exec,;]' \-l '' \-\- find\fP
.fi
.PP
completes arguments between `\fB\-exec\fP' and the following `\fB;\fP' (or the end
of the command line if there is no such string) as if they were
a separate command line\&.
.RE
.TP
\fB\-U\fP
Use the whole list of possible completions, whether or not they
actually match the word on the command line\&. The word typed so far
will be deleted\&. This is most useful with a function (given by the
\fB\-K\fP option) which can examine the word components passed to it
(or via the \fBread\fP builtin's \fB\-c\fP and \fB\-l\fP flags) and
use its own criteria to decide what matches\&. If there is no
completion, the original word is retained\&.
.'
.TP
\fB\-X\fP \fIexplanation\fP
Print \fIexplanation\fP when trying completion on the current set of
options\&. A `\fB%n\fP' in this string is replaced by the number of matches\&.
.'
.'
.'
.SH ""ALTERNATIVE COMPLETION
.'
.PD 0
.TP
\fBcompctl\fP [ \fB\-CDT\fP ] \fIoptions\fP \fB+\fP \fIoptions\fP [ \fB+\fP \&.\&.\&. ] [ \fB+\fP ] \fIcommand\fP \&.\&.\&.
.PD
.PP
The form with `\fB+\fP' specifies alternative options\&. Completion is
tried with the options before the first `\fB+\fP'\&. If this produces no
matches completion is tried with the flags after the `\fB+\fP' and so on\&. If
there are no flags after the last `\fB+\fP' and a match has not been found
up to that point, default completion is tried\&.
.'
.SH ""EXTENDED COMPLETION
.'
.PD 0
.TP
\fBcompctl\fP [ \fB\-CDT\fP ] \fIoptions\fP \fB\-x\fP \fIpattern\fP \fIoptions\fP \fB\-\fP \&.\&.\&. \fB\-\-\fP [ \fIcommand\fP \&.\&.\&. ]
.TP
\fBcompctl\fP [ \fB\-CDT\fP ] \fIoptions\fP [ \fB\-x\fP \fIpattern\fP \fIoptions\fP \fB\-\fP \&.\&.\&. \fB\-\-\fP ] [ \fB+\fP \fIoptions\fP [ \fB\-x\fP \&.\&.\&. \fB\-\-\fP ] \&.\&.\&. [\fB+\fP] ] [ \fIcommand\fP \&.\&.\&. ]
.PD
.PP
The form with `\fB\-x\fP' specifies extended completion for the
commands given; as shown, it may be combined with alternative
completion using `\fB+\fP'\&. Each \fIpattern\fP is examined in turn; when a
match is found, the corresponding \fIoptions\fP, as described in
the section `Option Flags' above, are used to generate possible
completions\&. If no \fIpattern\fP matches, the \fIoptions\fP given
before the \fB\-x\fP are used\&.
.PP
Note that each pattern should be supplied as a single argument and
should be quoted to prevent expansion of metacharacters by the
shell\&.
.PP
A \fIpattern\fP is built of sub\-patterns separated by commas; it
matches if at least one of these sub\-patterns matches (they are
`or'ed)\&. These sub\-patterns are in turn composed of other
sub\-patterns separated by white spaces which match if all of the
sub\-patterns match (they are `and'ed)\&. An element of the
sub\-patterns is of the form `\fIc\fP\fB[\fP\&.\&.\&.\fB][\fP\&.\&.\&.\fB]\fP', where the pairs of
brackets may be repeated as often as necessary, and matches if any of
the sets of brackets match (an `or')\&. The example below makes this
clearer\&.
.PP
The elements may be any of the following:
.PP
.PD 0
.TP
.PD
\fBs[\fP\fIstring\fP\fB]\fP\&.\&.\&.
Matches if the current word on the command line starts with
one of the strings given in brackets\&. The \fIstring\fP is not removed
and is not part of the completion\&.
.'
.TP
\fBS[\fP\fIstring\fP\fB]\fP\&.\&.\&.
Like \fBs[\fP\fIstring\fP\fB]\fP except that the \fIstring\fP is part of the
completion\&.
.'
.TP
\fBp[\fP\fIfrom\fP\fB,\fP\fIto\fP\fB]\fP\&.\&.\&.
Matches if the number of the current word is between one of
the \fIfrom\fP and \fIto\fP pairs inclusive\&. The comma and \fIto\fP
are optional; \fIto\fP defaults to the same value as \fIfrom\fP\&. The
numbers may be negative: \fB\-\fP\fIn\fP refers to the \fIn\fP'th last word
on the line\&.
.'
.TP
\fBc[\fP\fIoffset\fP\fB,\fP\fIstring\fP\fB]\fP\&.\&.\&.
Matches if the \fIstring\fP matches the word offset by
\fIoffset\fP from the current word position\&. Usually \fIoffset\fP
will be negative\&.
.'
.TP
\fBC[\fP\fIoffset\fP\fB,\fP\fIpattern\fP\fB]\fP\&.\&.\&.
Like \fBc\fP but using pattern matching instead\&.
.'
.TP
\fBw[\fP\fIindex\fP\fB,\fP\fIstring\fP\fB]\fP\&.\&.\&.
Matches if the word in position \fIindex\fP is equal
to the corresponding \fIstring\fP\&. Note that the word count is made
after any alias expansion\&.
.'
.TP
\fBW[\fP\fIindex\fP\fB,\fP\fIpattern\fP\fB]\fP\&.\&.\&.
Like \fBw\fP but using pattern matching instead\&.
.'
.TP
\fBn[\fP\fIindex\fP\fB,\fP\fIstring\fP\fB]\fP\&.\&.\&.
Matches if the current word contains \fIstring\fP\&. Anything up to and
including the \fIindex\fPth occurrence of this string will not be
considered part of the completion, but the rest will\&. \fIindex\fP may
be negative to count from the end: in most cases, \fIindex\fP will be
1 or \-1\&.
.'
.TP
\fBN[\fP\fIindex\fP\fB,\fP\fIstring\fP\fB]\fP\&.\&.\&.
Like \fBn\fP except that the string will be
taken as a character class\&. Anything up to and including the
\fIindex\fPth occurrence of any of the characters in \fIstring\fP
will not be considered part of the completion\&.
.'
.TP
\fBm[\fP\fImin\fP\fB,\fP\fImax\fP\fB]\fP\&.\&.\&.
Matches if the total number of words lies between \fImin\fP and
\fImax\fP inclusive\&.
.'
.TP
\fBr[\fP\fIstr1\fP\fB,\fP\fIstr2\fP\fB]\fP\&.\&.\&.
Matches if the cursor is after a word with prefix \fIstr1\fP\&. If there
is also a word with prefix \fIstr2\fP on the command line it matches
only if the cursor is before this word\&.
.'
.TP
\fBR[\fP\fIstr1\fP\fB,\fP\fIstr2\fP\fB]\fP\&.\&.\&.
Like \fBr\fP but using pattern matching instead\&.
.'
.'
.'
.SH ""EXAMPLE
.'
.nf
\fBcompctl \-u \-x 's[\fB+\fP] c[\-1,\-f],s[\-f+]' \-g '~/Mail/*(:t)' \e
\- 's[\-f],c[\-1,\-f]' \-f \-\- mail\fP
.fi
.PP
This is to be interpreted as follows:
.PP
If the current command is \fBmail\fP, then
.PP
.RS
if ((the current word begins with \fB+\fP and the previous word is \fB\-f\fP)
or (the current word begins with \fB\-f+\fP)), then complete the
non\-directory part (the `\fB:t\fP' glob modifier) of files in the directory
\fB~/Mail\fP; else
.PP
if the current word begins with \fB\-f\fP or the previous word was \fB\-f\fP, then
complete any file; else
.PP
complete user names\&.
.RE
.' (avoiding a yodl bug)
|