/usr/share/doc/zsh-common/html/Completion-Widgets.html is in zsh-doc 5.4.2-3ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>19 Completion Widgets (zsh)</title>
<meta name="description" content="19 Completion Widgets (zsh)">
<meta name="keywords" content="19 Completion Widgets (zsh)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2any">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en">
<a name="Completion-Widgets"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="Zsh-Line-Editor.html#Zsh-Line-Editor" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="Zsh-Line-Editor.html#Character-Highlighting" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Description-2" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left">[<a href="Completion-System.html#Completion-System" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Completion-Widgets-1"></a>
<h1 class="chapter">19 Completion Widgets</h1>
<p><a name="index-completion_002c-widgets"></a>
<a name="index-completion_002c-programmable"></a>
<a name="index-completion_002c-controlling"></a>
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Completion-Special-Parameters">19.2 Completion Special Parameters</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Completion-Builtin-Commands">19.3 Completion Builtin Commands</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Completion-Condition-Codes">19.4 Completion Condition Codes</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Completion-Matching-Control">19.5 Completion Matching Control</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Completion-Widget-Example">19.6 Completion Widget Example</a></td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Description-2"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-Widgets" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Widgets" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Widgets" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Special-Parameters" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left">[<a href="Completion-System.html#Completion-System" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">19.1 Description</h2>
<p>The shell’s programmable completion mechanism can be manipulated in two
ways; here the low-level features supporting the newer, function-based
mechanism are defined. A complete set of shell functions based on these
features is described in
the next chapter, <a href="Completion-System.html#Completion-System">Completion System</a>,
and users with no interest in adding to that system (or, potentially,
writing their own — see dictionary entry for ‘hubris’) should skip
the current section. The older system based on the <tt>compctl</tt> builtin
command is described in
<a href="Completion-Using-compctl.html#Completion-Using-compctl">Completion Using compctl</a>.
</p>
<p>Completion widgets are defined by the <tt>-C</tt> option to the <tt>zle</tt>
builtin command provided by the <tt>zsh/zle</tt> module (see
<a href="Zsh-Modules.html#The-zsh_002fzle-Module">The zsh/zle Module</a>). For example,
</p>
<div class="example">
<pre class="example">zle -C complete expand-or-complete completer
</pre></div>
<p>defines a widget named ‘<tt>complete</tt>’. The second argument is the name
of any of the builtin widgets that handle completions:
<tt>complete-word</tt>, <tt>expand-or-complete</tt>,
<tt>expand-or-complete-prefix</tt>, <tt>menu-complete</tt>,
<tt>menu-expand-or-complete</tt>, <tt>reverse-menu-complete</tt>,
<tt>list-choices</tt>, or <tt>delete-char-or-list</tt>. Note that this will still
work even if the widget in question has been re-bound.
</p>
<p>When this newly defined widget is bound to a key
using the <tt>bindkey</tt> builtin command defined in the <tt>zsh/zle</tt> module
(<a href="Zsh-Line-Editor.html#Zsh-Line-Editor">Zsh Line Editor</a>), typing that key will call the shell function ‘<tt>completer</tt>’. This
function is responsible for generating the possible matches using the
builtins described below. As with other ZLE widgets, the function is
called with its standard input closed.
</p>
<p>Once the function returns, the completion code takes over control again
and treats the matches in the same manner as the specified builtin
widget, in this case <tt>expand-or-complete</tt>.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Completion-Special-Parameters">19.2 Completion Special Parameters</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Completion-Builtin-Commands">19.3 Completion Builtin Commands</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Completion-Condition-Codes">19.4 Completion Condition Codes</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Completion-Matching-Control">19.5 Completion Matching Control</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Completion-Widget-Example">19.6 Completion Widget Example</a></td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Completion-Special-Parameters"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-Widgets" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Description-2" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Widgets" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Builtin-Commands" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left">[<a href="Completion-System.html#Completion-System" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Completion-Special-Parameters-1"></a>
<h2 class="section">19.2 Completion Special Parameters</h2>
<p>The parameters <tt>ZLE_REMOVE_SUFFIX_CHARS</tt> and <tt>ZLE_SPACE_SUFFIX_CHARS</tt>
are used by the completion mechanism, but are not special. See
<a href="Parameters.html#Parameters-Used-By-The-Shell">Parameters Used By The Shell</a>.
</p>
<p>Inside completion widgets, and any functions called from them, some
parameters have special meaning; outside these functions they are not
special to the shell in any way. These parameters are used to pass
information between the completion code and the completion widget. Some of
the builtin commands and the condition codes use or change the current
values of these parameters. Any existing values will be hidden during
execution of completion widgets; except for <tt>compstate</tt>, the parameters
are reset on each function exit (including nested function calls from
within the completion widget) to the values they had when the function was
entered.
</p>
<dl compact="compact">
<dd><a name="index-CURRENT"></a>
</dd>
<dt><tt>CURRENT</tt></dt>
<dd><p>This is the number of the current word, i.e. the word the cursor is
currently on in the <tt>words</tt> array. Note that this value is only
correct if the <tt>ksharrays</tt> option is not set.
</p>
<a name="index-IPREFIX"></a>
</dd>
<dt><tt>IPREFIX</tt></dt>
<dd><p>Initially this will be set to the empty string. This parameter functions
like <tt>PREFIX</tt>; it contains a string which precedes the one in <tt>PREFIX</tt>
and is not considered part of the list of matches. Typically, a string is
transferred from the beginning of <tt>PREFIX</tt> to the end of <tt>IPREFIX</tt>, for
example:
</p>
<div class="example">
<pre class="example">IPREFIX=${PREFIX%%\=*}=
PREFIX=${PREFIX#*=}
</pre></div>
<p>causes the part of the prefix up to and including the first equal sign not
to be treated as part of a matched string. This can be done automatically
by the <tt>compset</tt> builtin, see below.
</p>
<a name="index-ISUFFIX"></a>
</dd>
<dt><tt>ISUFFIX</tt></dt>
<dd><p>As <tt>IPREFIX</tt>, but for a suffix that should not be considered part
of the matches; note that the <tt>ISUFFIX</tt> string follows the <tt>SUFFIX</tt>
string.
</p>
<a name="index-PREFIX"></a>
</dd>
<dt><tt>PREFIX</tt></dt>
<dd><p>Initially this will be set to the part of the current word from the
beginning of the word up to the position of the cursor; it may be altered
to give a common prefix for all matches.
</p>
<a name="index-QIPREFIX"></a>
</dd>
<dt><tt>QIPREFIX</tt></dt>
<dd><p>This parameter is read-only and contains the quoted string up to the
word being completed. E.g. when completing ‘<tt>"foo</tt>’, this parameter
contains the double quote. If the <tt>-q</tt> option of <tt>compset</tt> is used
(see below), and the original string was ‘<tt>"foo bar</tt>’ with the
cursor on the ‘<tt>bar</tt>’, this parameter contains ‘<tt>"foo </tt>’.
</p>
<a name="index-QISUFFIX"></a>
</dd>
<dt><tt>QISUFFIX</tt></dt>
<dd><p>Like <tt>QIPREFIX</tt>, but containing the suffix.
</p>
<a name="index-SUFFIX"></a>
</dd>
<dt><tt>SUFFIX</tt></dt>
<dd><p>Initially this will be set to the part of the current word from the
cursor position to the end; it may be altered to give a common suffix for
all matches. It is most useful when the option <tt>COMPLETE_IN_WORD</tt> is
set, as otherwise the whole word on the command line is treated as a
prefix.
</p>
<a name="index-compstate"></a>
<a name="index-completion-widgets_002c-examining-and-setting-state-in"></a>
</dd>
<dt><tt>compstate</tt></dt>
<dd><p>This is an associative array with various keys and values that the
completion code uses to exchange information with the completion widget.
The keys are:
</p>
<dl compact="compact">
<dd><a name="index-all_005fquotes_002c-compstate"></a>
</dd>
<dt><tt>all_quotes</tt></dt>
<dd><p>The <tt>-q</tt> option of the <tt>compset</tt> builtin command (see below)
allows a quoted string to be broken into separate words; if the cursor is
on one of those words, that word will be completed, possibly invoking
‘<tt>compset -q</tt>’ recursively. With this key it is possible to test the
types of quoted strings which are currently broken into parts in this
fashion. Its value contains one character for each quoting level. The
characters are a single quote or a double quote for strings quoted with
these characters, a dollars sign for strings quoted with
<tt>$'</tt><var>...</var><tt>'</tt> and a backslash for strings not starting with a
quote character. The first character in the value always corresponds to the
innermost quoting level.
</p>
<a name="index-context_002c-compstate"></a>
</dd>
<dt><tt>context</tt></dt>
<dd><p>This will be set by the completion code to the overall context
in which completion is attempted. Possible values are:
</p>
<dl compact="compact">
<dt><tt>array_value</tt></dt>
<dd><p>when completing inside the value of an array parameter assignment; in
this case the <tt>words</tt> array contains the words inside the parentheses.
</p>
</dd>
<dt><tt>brace_parameter</tt></dt>
<dd><p>when completing the name of a parameter in a parameter expansion beginning
with <tt>${</tt>. This context will also be set when completing parameter
flags following <tt>${(</tt>; the full command line argument is presented
and the handler must test the value to be completed to ascertain that
this is the case.
</p>
</dd>
<dt><tt>assign_parameter</tt></dt>
<dd><p>when completing the name of a parameter in a parameter assignment.
</p>
</dd>
<dt><tt>command</tt></dt>
<dd><p>when completing for a normal command (either in command position or for
an argument of the command).
</p>
</dd>
<dt><tt>condition</tt></dt>
<dd><p>when completing inside a ‘<tt>[[</tt>...<tt>]]</tt>’ conditional expression; in
this case the <tt>words</tt> array contains only the words inside the
conditional expression.
</p>
</dd>
<dt><tt>math</tt></dt>
<dd><p>when completing in a mathematical environment such as a
‘<tt>((</tt>...<tt>))</tt>’ construct.
</p>
</dd>
<dt><tt>parameter</tt></dt>
<dd><p>when completing the name of a parameter in a parameter expansion beginning
with <tt>$</tt> but not <tt>${</tt>.
</p>
</dd>
<dt><tt>redirect</tt></dt>
<dd><p>when completing after a redirection operator.
</p>
</dd>
<dt><tt>subscript</tt></dt>
<dd><p>when completing inside a parameter subscript.
</p>
</dd>
<dt><tt>value</tt></dt>
<dd><p>when completing the value of a parameter assignment.
</p>
</dd>
</dl>
<a name="index-exact_002c-compstate"></a>
</dd>
<dt><tt>exact</tt></dt>
<dd><p>Controls the behaviour when the <tt>REC_EXACT</tt> option is set. It will be
set to <tt>accept</tt> if an exact match would be accepted, and will be unset
otherwise.
</p>
<p>If it was set when at least one match equal to the string on the line
was generated, the match is accepted.
</p>
<a name="index-exact_005fstring_002c-compstate"></a>
</dd>
<dt><tt>exact_string</tt></dt>
<dd><p>The string of an exact match if one was found, otherwise unset.
</p>
<a name="index-ignored_002c-compstate"></a>
</dd>
<dt><tt>ignored</tt></dt>
<dd><p>The number of words that were ignored because they matched one of the
patterns given with the <tt>-F</tt> option to the <tt>compadd</tt> builtin
command.
</p>
<a name="index-insert_002c-compstate"></a>
</dd>
<dt><tt>insert</tt></dt>
<dd><p>This controls the manner in which a match is inserted into the command
line. On entry to the widget function, if it is unset the command line is
not to be changed; if set to <tt>unambiguous</tt>, any prefix common to all
matches is to be inserted; if set to <tt>automenu-unambiguous</tt>, the
common prefix is to be inserted and the next invocation of the
completion code may start menu completion (due to the <tt>AUTO_MENU</tt>
option being set); if set to <tt>menu</tt> or <tt>automenu</tt> menu completion
will be started for the matches currently generated (in the
latter case this will happen because the <tt>AUTO_MENU</tt> is set). The
value may also contain the string ‘<tt>tab</tt>’ when the completion code
would normally not really do completion, but only insert the TAB
character.
</p>
<p>On exit it may be set to any of the values above (where setting it to
the empty string is the same as unsetting it), or to a number, in which
case the match whose number is given will be inserted into the command line.
Negative numbers count backward from the last match (with ‘<tt>-1</tt>’
selecting the last match) and out-of-range values are wrapped
around, so that a value of zero selects the last match and a value
one more than the maximum selects the first. Unless the value of this
key ends in a space, the match is inserted as in a menu completion,
i.e. without automatically appending a space.
</p>
<p>Both <tt>menu</tt> and <tt>automenu</tt> may also specify the number of the
match to insert, given after a colon. For example, ‘<tt>menu:2</tt>’ says
to start menu completion, beginning with the second match.
</p>
<p>Note that a value containing the substring ‘<tt>tab</tt>’ makes the
matches generated be ignored and only the TAB be inserted.
</p>
<p>Finally, it may also be set to <tt>all</tt>, which makes all matches
generated be inserted into the line.
</p>
<a name="index-insert_005fpositions_002c-compstate"></a>
</dd>
<dt><tt>insert_positions</tt></dt>
<dd><p>When the completion system inserts an unambiguous string into the
line, there may be multiple places where characters are missing or
where the character inserted differs from at least one match. The
value of this key contains a colon separated list of all these
positions, as indexes into the command line.
</p>
<a name="index-last_005fprompt_002c-compstate"></a>
</dd>
<dt><tt>last_prompt</tt></dt>
<dd><p>If this is set to a non-empty string for every match added, the
completion code will move the cursor back to the previous prompt after
the list of completions has been displayed. Initially this is set or
unset according to the <tt>ALWAYS_LAST_PROMPT</tt> option.
</p>
<a name="index-list_002c-compstate"></a>
</dd>
<dt><tt>list</tt></dt>
<dd><p>This controls whether or how the list of matches will be displayed. If it
is unset or empty they will never be listed; if its value begins with
<tt>list</tt>, they will always be listed; if it begins with <tt>autolist</tt>
or <tt>ambiguous</tt>, they will be listed when the <tt>AUTO_LIST</tt> or
<tt>LIST_AMBIGUOUS</tt> options respectively would normally cause them to
be.
</p>
<p>If the substring <tt>force</tt> appears in the value, this makes the
list be shown even if there is only one match. Normally, the list
would be shown only if there are at least two matches.
</p>
<p>The value contains the substring <tt>packed</tt> if the <tt>LIST_PACKED</tt>
option is set. If this substring is given for all matches added to a
group, this group will show the <tt>LIST_PACKED</tt> behavior. The same is
done for the <tt>LIST_ROWS_FIRST</tt> option with the substring <tt>rows</tt>.
</p>
<p>Finally, if the value contains the string <tt>explanations</tt>, only the
explanation strings, if any, will be listed and if it contains
<tt>messages</tt>, only the messages (added with the <tt>-x</tt> option of
<tt>compadd</tt>) will be listed. If it contains both <tt>explanations</tt> and
<tt>messages</tt> both kinds of explanation strings will be listed. It
will be set appropriately on entry to a completion widget and may be
changed there.
</p>
<a name="index-list_005flines_002c-compstate"></a>
</dd>
<dt><tt>list_lines</tt></dt>
<dd><p>This gives the number of lines that are needed to display the full
list of completions. Note that to calculate the total number of lines
to display you need to add the number of lines needed for the command
line to this value, this is available as the value of the <tt>BUFFERLINES</tt>
special parameter.
</p>
<a name="index-list_005fmax_002c-compstate"></a>
</dd>
<dt><tt>list_max</tt></dt>
<dd><p>Initially this is set to the value of the <tt>LISTMAX</tt> parameter.
It may be set to any other value; when the widget exits this value
will be used in the same way as the value of <tt>LISTMAX</tt>.
</p>
<a name="index-nmatches_002c-compstate"></a>
</dd>
<dt><tt>nmatches</tt></dt>
<dd><p>The number of matches generated and accepted by the completion code so
far.
</p>
<a name="index-old_005finsert_002c-compstate"></a>
</dd>
<dt><tt>old_insert</tt></dt>
<dd><p>On entry to the widget this will be set to the number of the match of
an old list of completions that is currently inserted into the command
line. If no match has been inserted, this is unset.
</p>
<p>As with <tt>old_list</tt>, the value of this key will only be used if it is the
string <tt>keep</tt>. If it was set to this value by the widget and there was an
old match inserted into the command line, this match will be kept and if
the value of the <tt>insert</tt> key specifies that another match should be
inserted, this will be inserted after the old one.
</p>
<a name="index-old_005flist_002c-compstate"></a>
</dd>
<dt><tt>old_list</tt></dt>
<dd><p>This is set to <tt>yes</tt> if there is still a valid list of completions
from a previous completion at the time the widget is invoked. This will
usually be the case if and only if the previous editing operation was a
completion widget or one of the builtin completion functions. If there is a
valid list and it is also currently shown on the screen, the value of this
key is <tt>shown</tt>.
</p>
<p>After the widget has exited the value of this key is only used if it
was set to <tt>keep</tt>. In this case the completion code will continue
to use this old list. If the widget generated new matches, they will
not be used.
</p>
<a name="index-parameter_002c-compstate"></a>
</dd>
<dt><tt>parameter</tt></dt>
<dd><p>The name of the parameter when completing in a subscript or in the
value of a parameter assignment.
</p>
<a name="index-pattern_005finsert_002c-compstate"></a>
</dd>
<dt><tt>pattern_insert</tt></dt>
<dd><p>Normally this is set to <tt>menu</tt>, which specifies that menu completion will
be used whenever a set of matches was generated using pattern matching. If
it is set to any other non-empty string by the user and menu completion is
not selected by other option settings, the code will instead insert any
common prefix for the generated matches as with normal completion.
</p>
<a name="index-pattern_005fmatch_002c-compstate"></a>
</dd>
<dt><tt>pattern_match</tt></dt>
<dd><p>Locally controls the behaviour given by the <tt>GLOB_COMPLETE</tt> option.
Initially it is set to ‘<tt>*</tt>’ if and only if the option is set.
The completion widget may set it to this value, to an empty string
(which has the same effect as unsetting it), or to any
other non-empty string. If it is non-empty, unquoted metacharacters on the
command line will be treated as patterns; if it is ‘<tt>*</tt>’, then
additionally a wildcard ‘<tt>*</tt>’ is assumed at the cursor position; if
it is empty or unset, metacharacters will be treated literally.
</p>
<p>Note that the matcher specifications given to the <tt>compadd</tt> builtin
command are not used if this is set to a non-empty string.
</p>
<a name="index-quote_002c-compstate"></a>
</dd>
<dt><tt>quote</tt></dt>
<dd><p>When completing inside quotes, this contains the quotation character
(i.e. either a single quote, a double quote, or a backtick). Otherwise it
is unset.
</p>
<a name="index-quoting_002c-compstate"></a>
</dd>
<dt><tt>quoting</tt></dt>
<dd><p>When completing inside single quotes, this is set to the string
<tt>single</tt>; inside double quotes, the string
<tt>double</tt>; inside backticks, the string <tt>backtick</tt>.
Otherwise it is unset.
</p>
<a name="index-redirect_002c-compstate"></a>
</dd>
<dt><tt>redirect</tt></dt>
<dd><p>The redirection operator when completing in a redirection position,
i.e. one of <tt><</tt>, <tt>></tt>, etc.
</p>
<a name="index-restore_002c-compstate"></a>
</dd>
<dt><tt>restore</tt></dt>
<dd><p>This is set to <tt>auto</tt> before a function is entered, which forces the
special parameters mentioned above (<tt>words</tt>, <tt>CURRENT</tt>, <tt>PREFIX</tt>,
<tt>IPREFIX</tt>, <tt>SUFFIX</tt>, and <tt>ISUFFIX</tt>) to be restored to their
previous values when the function exits. If a function unsets it or
sets it to any other string, they will not be restored.
</p>
<a name="index-to_005fend_002c-compstate"></a>
</dd>
<dt><tt>to_end</tt></dt>
<dd><p>Specifies the occasions on which the cursor is moved to the end of a string
when a match is inserted. On entry to a widget function, it may be
<tt>single</tt> if this will happen when a single unambiguous match was inserted
or <tt>match</tt> if it will happen any time a match is inserted (for example,
by menu completion; this is likely to be the effect of the <tt>ALWAYS_TO_END</tt>
option).
</p>
<p>On exit, it may be set to <tt>single</tt> as above. It may also be set to
<tt>always</tt>, or to the empty string or unset; in those cases the cursor will
be moved to the end of the string always or never respectively. Any
other string is treated as <tt>match</tt>.
</p>
<a name="index-unambiguous_002c-compstate"></a>
</dd>
<dt><tt>unambiguous</tt></dt>
<dd><p>This key is read-only and will always be set to the common (unambiguous)
prefix the completion code has generated for all matches added so far.
</p>
<a name="index-unambiguous_005fcursor_002c-compstate"></a>
</dd>
<dt><tt>unambiguous_cursor</tt></dt>
<dd><p>This gives the position the cursor would be placed at if the
common prefix in the <tt>unambiguous</tt> key were inserted, relative to
the value of that key. The cursor would be placed before the character
whose index is given by this key.
</p>
<a name="index-unambiguous_005fpositions_002c-compstate"></a>
</dd>
<dt><tt>unambiguous_positions</tt></dt>
<dd><p>This contains all positions where characters in the unambiguous string
are missing or where the character inserted differs from at least one
of the matches. The positions are given as indexes into the string
given by the value of the <tt>unambiguous</tt> key.
</p>
<a name="index-vared_002c-compstate"></a>
</dd>
<dt><tt>vared</tt></dt>
<dd><p>If completion is called while editing a line using the <tt>vared</tt>
builtin, the value of this key is set to the name of the parameter
given as an argument to <tt>vared</tt>. This key is only set while a <tt>vared</tt>
command is active.
</p>
</dd>
</dl>
<a name="index-words"></a>
</dd>
<dt><tt>words</tt></dt>
<dd><p>This array contains the words present on the command line currently being
edited.
</p>
</dd>
</dl>
<hr>
<a name="Completion-Builtin-Commands"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-Widgets" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Special-Parameters" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Widgets" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Condition-Codes" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left">[<a href="Completion-System.html#Completion-System" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Completion-Builtin-Commands-1"></a>
<h2 class="section">19.3 Completion Builtin Commands</h2>
<dl compact="compact">
<dd><a name="index-compadd"></a>
<a name="index-completion-widgets_002c-adding-specified-matches"></a>
</dd>
<dt><tt>compadd </tt>[ <tt>-akqQfenUlo12C</tt> ] [ <tt>-F</tt> <var>array</var> ]</dt>
<dt><tt> </tt>[<tt>-P</tt> <var>prefix</var> ] [ <tt>-S</tt> <var>suffix</var> ]</dt>
<dt><tt> </tt>[<tt>-p</tt> <var>hidden-prefix</var> ] [ <tt>-s</tt> <var>hidden-suffix</var> ]</dt>
<dt><tt> </tt>[<tt>-i</tt> <var>ignored-prefix</var> ] [ <tt>-I</tt> <var>ignored-suffix</var> ]</dt>
<dt><tt> </tt>[<tt>-W</tt> <var>file-prefix</var> ] [ <tt>-d</tt> <var>array</var> ]</dt>
<dt><tt> </tt>[<tt>-J</tt> <var>name</var> ] [ <tt>-V</tt> <var>name</var> ] [ <tt>-X</tt> <var>explanation</var> ] [ <tt>-x</tt> <var>message</var> ]</dt>
<dt><tt> </tt>[<tt>-r</tt> <var>remove-chars</var> ] [ <tt>-R</tt> <var>remove-func</var> ]</dt>
<dt><tt> </tt>[<tt>-D</tt> <var>array</var> ] [ <tt>-O</tt> <var>array</var> ] [ <tt>-A</tt> <var>array</var> ]</dt>
<dt><tt> </tt>[<tt>-E</tt> <var>number</var> ]</dt>
<dt><tt> </tt>[<tt>-M</tt> <var>match-spec</var> ] [ <tt>-</tt><tt>-</tt> ] [ <var>words</var> ... ]</dt>
<dd>
<p>This builtin command can be used to add matches directly and control
all the information the completion code stores with each possible
match. The return status is zero if at least one match was added and
non-zero if no matches were added.
</p>
<p>The completion code breaks the string to complete into seven fields in
the order:
</p>
<blockquote>
<p><var><ipre><apre><hpre><word><hsuf><asuf><isuf></var>
</p></blockquote>
<p>The first field
is an ignored prefix taken from the command line, the contents of the
<tt>IPREFIX</tt> parameter plus the string given with the <tt>-i</tt>
option. With the <tt>-U</tt> option, only the string from the <tt>-i</tt>
option is used. The field <var><apre></var> is an optional prefix string
given with the <tt>-P</tt> option. The <var><hpre></var> field is a string
that is considered part of the match but that should not be shown when
listing completions, given with the <tt>-p</tt> option; for example,
functions that do filename generation might specify
a common path prefix this way. <var><word></var> is the part of the match that
should appear in the list of completions, i.e. one of the <var>words</var> given
at the end of the <tt>compadd</tt> command line. The suffixes <var><hsuf></var>,
<var><asuf></var> and <var><isuf></var> correspond to the prefixes <var><hpre></var>,
<var><apre></var> and <var><ipre></var> and are given by the options <tt>-s</tt>, <tt>-S</tt> and
<tt>-I</tt>, respectively.
</p>
<p>The supported flags are:
</p>
<dl compact="compact">
<dt><tt>-P</tt> <var>prefix</var></dt>
<dd><p>This gives a string to be inserted before the given <var>words</var>. The
string given is not considered as part of the match and any shell
metacharacters in it will not be quoted when the string is inserted.
</p>
</dd>
<dt><tt>-S</tt> <var>suffix</var></dt>
<dd><p>Like <tt>-P</tt>, but gives a string to be inserted after the match.
</p>
</dd>
<dt><tt>-p</tt> <var>hidden-prefix</var></dt>
<dd><p>This gives a string that should be inserted into the command line before the
match but that should not appear in the list of matches. Unless the
<tt>-U</tt> option is given, this string must be matched as part of the string
on the command line.
</p>
</dd>
<dt><tt>-s</tt> <var>hidden-suffix</var></dt>
<dd><p>Like ‘<tt>-p</tt>’, but gives a string to insert after the match.
</p>
</dd>
<dt><tt>-i</tt> <var>ignored-prefix</var></dt>
<dd><p>This gives a string to insert into the command line just before any
string given with the ‘<tt>-P</tt>’ option. Without ‘<tt>-P</tt>’ the string is
inserted before the string given with ‘<tt>-p</tt>’ or directly before the
match.
</p>
</dd>
<dt><tt>-I</tt> <var>ignored-suffix</var></dt>
<dd><p>Like <tt>-i</tt>, but gives an ignored suffix.
</p>
</dd>
<dt><tt>-a</tt></dt>
<dd><p>With this flag the <var>words</var> are taken as names of arrays and the
possible matches are their values. If only some elements of the
arrays are needed, the <var>words</var> may also contain subscripts, as in
‘<tt>foo[2,-1]</tt>’.
</p>
</dd>
<dt><tt>-k</tt></dt>
<dd><p>With this flag the <var>words</var> are taken as names of associative arrays
and the possible matches are their keys. As for <tt>-a</tt>, the
<var>words</var> may also contain subscripts, as in ‘<tt>foo[(R)*bar*]</tt>’.
</p>
</dd>
<dt><tt>-d</tt> <var>array</var></dt>
<dd><p>This adds per-match display strings. The <var>array</var> should contain one
element per <var>word</var> given. The completion code will then display the
first element instead of the first <var>word</var>, and so on. The
<var>array</var> may be given as the name of an array parameter or directly
as a space-separated list of words in parentheses.
</p>
<p>If there are fewer display strings than <var>words</var>, the leftover
<var>words</var> will be displayed unchanged and if there are more display
strings than <var>words</var>, the leftover display strings will be silently
ignored.
</p>
</dd>
<dt><tt>-l</tt></dt>
<dd><p>This option only has an effect if used together with the <tt>-d</tt>
option. If it is given, the display strings are listed one per line,
not arrayed in columns.
</p>
</dd>
<dt><tt>-o</tt></dt>
<dd><p>This option only has an effect if used together with the <tt>-d</tt>
option. If it is given, the order of the output is determined by the
match strings; otherwise it is determined by the display strings
(i.e. the strings given by the <tt>-d</tt> option).
</p>
</dd>
<dt><tt>-J</tt> <var>name</var></dt>
<dd><p>Gives the name of the group of matches the words should be stored in.
</p>
</dd>
<dt><tt>-V</tt> <var>name</var></dt>
<dd><p>Like <tt>-J</tt> but naming an unsorted group. These are in a different name
space than groups created with the <tt>-J</tt> flag.
</p>
</dd>
<dt><tt>-1</tt></dt>
<dd><p>If given together with the <tt>-V</tt> option, makes
only consecutive duplicates in the group be removed. If combined with
the <tt>-J</tt> option, this has no visible effect. Note that groups
with and without this flag are in different name spaces.
</p>
</dd>
<dt><tt>-2</tt></dt>
<dd><p>If given together with the <tt>-J</tt> or <tt>-V</tt> option, makes all
duplicates be kept. Again, groups with and without this flag are in
different name spaces.
</p>
</dd>
<dt><tt>-X</tt> <var>explanation</var></dt>
<dd><p>The <var>explanation</var> string will be printed with the list of matches,
above the group currently selected.
</p>
</dd>
<dt><tt>-x</tt> <var>message</var></dt>
<dd><p>Like <tt>-X</tt>, but the <var>message</var> will be printed even if there are no
matches in the group.
</p>
</dd>
<dt><tt>-q</tt></dt>
<dd><p>The suffix given with <tt>-S</tt> will be automatically removed if
the next character typed is a blank or does not insert anything, or if
the suffix consists of only one character and the next character typed
is the same character.
</p>
</dd>
<dt><tt>-r</tt> <var>remove-chars</var></dt>
<dd><p>This is a more versatile form of the <tt>-q</tt> option.
The suffix given with <tt>-S</tt> or the slash automatically added after
completing directories will be automatically removed if
the next character typed inserts one of the characters given in the
<var>remove-chars</var>. This string is parsed as a characters class and
understands the backslash sequences used by the <tt>print</tt> command. For
example, ‘<tt>-r "a-z\t"</tt>’ removes the suffix if the next character typed
inserts a lower case character or a TAB, and ‘<tt>-r "^0-9"</tt>’ removes the
suffix if the next character typed inserts anything but a digit. One extra
backslash sequence is understood in this string: ‘<tt>\-</tt>’ stands for
all characters that insert nothing. Thus ‘<tt>-S "=" -q</tt>’ is the same
as ‘<tt>-S "=" -r "= \t\n\-"</tt>’.
</p>
<p>This option may also be used without the <tt>-S</tt> option; then any
automatically added space will be removed when one of the characters in the
list is typed.
</p>
</dd>
<dt><tt>-R</tt> <var>remove-func</var></dt>
<dd><p>This is another form of the <tt>-r</tt> option. When a suffix
has been inserted and the completion accepted, the function
<var>remove-func</var> will be called after the next character typed. It is
passed the length of the suffix as an argument and can use the special
parameters available in ordinary (non-completion) zle widgets (see
<a href="Zsh-Line-Editor.html#Zsh-Line-Editor">Zsh Line Editor</a>) to analyse and modify the command line.
</p>
</dd>
<dt><tt>-f</tt></dt>
<dd><p>If this flag is given, all of the matches built from <var>words</var> are
marked as being the names of files. They are not required to be actual
filenames, but if they are, and the option <tt>LIST_TYPES</tt> is set, the
characters describing the types of the files in the completion lists will
be shown. This also forces a slash to be added when the name of a
directory is completed.
</p>
</dd>
<dt><tt>-e</tt></dt>
<dd><p>This flag can be used to tell the completion code that the matches
added are parameter names for a parameter expansion. This will make
the <tt>AUTO_PARAM_SLASH</tt> and <tt>AUTO_PARAM_KEYS</tt> options be used for
the matches.
</p>
</dd>
<dt><tt>-W</tt> <var>file-prefix</var></dt>
<dd><p>This string is a pathname that will be
prepended to each of the matches formed by the given <var>words</var> together
with any prefix specified by the <tt>-p</tt> option to form a complete filename
for testing. Hence it is only useful if combined with the <tt>-f</tt> flag, as
the tests will not otherwise be performed.
</p>
</dd>
<dt><tt>-F</tt> <var>array</var></dt>
<dd><p>Specifies an array containing patterns. Words matching one of these
patterns are ignored, i.e. not considered to be possible matches.
</p>
<p>The <var>array</var> may be the name of an array parameter or a list of
literal patterns enclosed in parentheses and quoted, as in ‘<tt>-F "(*?.o
*?.h)"</tt>’. If the name of an array is given, the elements of the array are
taken as the patterns.
</p>
</dd>
<dt><tt>-Q</tt></dt>
<dd><p>This flag instructs the completion
code not to quote any metacharacters in the words when inserting them
into the command line.
</p>
</dd>
<dt><tt>-M</tt> <var>match-spec</var></dt>
<dd><p>This gives local match specifications as described below in
<a href="#Completion-Matching-Control">Completion Matching Control</a>. This option may be given more than once.
In this case all <var>match-spec</var>s given are concatenated with spaces
between them to form the specification string to use.
Note that they will only be used if the <tt>-U</tt> option is not given.
</p>
</dd>
<dt><tt>-n</tt></dt>
<dd><p>Specifies that the words added are to be used as possible
matches, but are not to appear in the completion listing.
</p>
</dd>
<dt><tt>-U</tt></dt>
<dd><p>If this flag is given, all words given will be accepted and no matching
will be done by the completion code. Normally this is used in
functions that do the matching themselves.
</p>
</dd>
<dt><tt>-O</tt> <var>array</var></dt>
<dd><p>If this option is given, the <var>words</var> are <em>not</em> added to the set of
possible completions. Instead, matching is done as usual and all of the
<var>words</var> given as arguments that match the string on the command line
will be stored in the array parameter whose name is given as <var>array</var>.
</p>
</dd>
<dt><tt>-A</tt> <var>array</var></dt>
<dd><p>As the <tt>-O</tt> option, except that instead of those of the <var>words</var> which
match being stored in <var>array</var>, the strings generated internally by the
completion code are stored. For example,
with a matching specification of ‘<tt>-M "L:|no="</tt>’, the string ‘<tt>nof</tt>’
on the command line and the string ‘<tt>foo</tt>’ as one of the <var>words</var>, this
option stores the string ‘<tt>nofoo</tt>’ in the array, whereas the <tt>-O</tt>
option stores the ‘<tt>foo</tt>’ originally given.
</p>
</dd>
<dt><tt>-D</tt> <var>array</var></dt>
<dd><p>As with <tt>-O</tt>, the <var>words</var> are not added to the set of possible
completions. Instead, the completion code tests whether each <var>word</var>
in turn matches what is on the line. If the <var>n</var>th <var>word</var> does not
match, the <var>n</var>th element of the <var>array</var> is removed. Elements
for which the corresponding <var>word</var> is matched are retained.
</p>
</dd>
<dt><tt>-C</tt></dt>
<dd><p>This option adds a special match which expands to all other matches
when inserted into the line, even those that are added after this
option is used. Together with the <tt>-d</tt> option it is possible to
specify a string that should be displayed in the list for this special
match. If no string is given, it will be shown as a string containing
the strings that would be inserted for the other matches, truncated to
the width of the screen.
</p>
</dd>
<dt><tt>-E</tt> <var>number</var></dt>
<dd><p>This option adds <var>number</var> empty matches after the <var>words</var> have
been added. An empty match takes up space in completion listings but
will never be inserted in the line and can’t be selected with menu
completion or menu selection. This makes empty matches only useful to
format completion lists and to make explanatory string be shown in
completion lists (since empty matches can be given display strings
with the <tt>-d</tt> option). And because all but one empty string would
otherwise be removed, this option implies the <tt>-V</tt> and <tt>-2</tt>
options (even if an explicit <tt>-J</tt> option is given). This can be
important to note as it affects the name space into which matches are
added.
</p>
</dd>
<dt><tt>-</tt></dt>
<dt><tt>-</tt><tt>-</tt></dt>
<dd><p>This flag ends the list of flags and options. All arguments after it
will be taken as the words to use as matches even if they begin with
hyphens.
</p>
</dd>
</dl>
<p>Except for the <tt>-M</tt> flag, if any of these flags is given more than
once, the first one (and its argument) will be used.
</p>
<a name="index-compset"></a>
<a name="index-completion-widgets_002c-modifying-special-parameters"></a>
</dd>
<dt><tt>compset -p</tt> <var>number</var></dt>
<dt><tt>compset -P</tt> [ <var>number</var> ] <var>pattern</var></dt>
<dt><tt>compset -s</tt> <var>number</var></dt>
<dt><tt>compset -S</tt> [ <var>number</var> ] <var>pattern</var></dt>
<dt><tt>compset -n</tt> <var>begin</var> [ <var>end</var> ]</dt>
<dt><tt>compset -N</tt> <var>beg-pat</var> [ <var>end-pat</var> ]</dt>
<dt><tt>compset -q</tt></dt>
<dd><p>This command simplifies modification of the special parameters,
while its return status allows tests on them to be carried out.
</p>
<p>The options are:
</p>
<dl compact="compact">
<dt><tt>-p</tt> <var>number</var></dt>
<dd><p>If the contents of the <tt>PREFIX</tt> parameter is longer than <var>number</var>
characters, the first <var>number</var> characters are removed from it and
appended to the contents of the <tt>IPREFIX</tt> parameter.
</p>
</dd>
<dt><tt>-P</tt> [ <var>number</var> ] <var>pattern</var></dt>
<dd><p>If the value of the <tt>PREFIX</tt> parameter begins with anything that
matches the <var>pattern</var>, the matched portion is removed from
<tt>PREFIX</tt> and appended to <tt>IPREFIX</tt>.
</p>
<p>Without the optional <var>number</var>, the longest match is taken, but
if <var>number</var> is given, anything up to the <var>number</var>th match is
moved. If the <var>number</var> is negative, the <var>number</var>th longest
match is moved. For example, if <tt>PREFIX</tt> contains the string
‘<tt>a=b=c</tt>’, then <tt>compset -P '*\='</tt> will move the string ‘<tt>a=b=</tt>’
into the <tt>IPREFIX</tt> parameter, but <tt>compset -P 1 '*\='</tt> will move only
the string ‘<tt>a=</tt>’.
</p>
</dd>
<dt><tt>-s</tt> <var>number</var></dt>
<dd><p>As <tt>-p</tt>, but transfer the last <var>number</var> characters from the
value of <tt>SUFFIX</tt> to the front of the value of <tt>ISUFFIX</tt>.
</p>
</dd>
<dt><tt>-S</tt> [ <var>number</var> ] <var>pattern</var></dt>
<dd><p>As <tt>-P</tt>, but match the last portion of <tt>SUFFIX</tt> and transfer the
matched portion to the front of the value of <tt>ISUFFIX</tt>.
</p>
</dd>
<dt><tt>-n</tt> <var>begin</var> [ <var>end</var> ]</dt>
<dd><p>If the current word position as specified by the parameter <tt>CURRENT</tt>
is greater than or equal to <var>begin</var>, anything up to the
<var>begin</var>th word is removed from the <tt>words</tt> array and the value
of the parameter <tt>CURRENT</tt> is decremented by <var>begin</var>.
</p>
<p>If the optional <var>end</var> is given, the modification is done only if
the current word position is also less than or equal to <var>end</var>. In
this case, the words from position <var>end</var> onwards are also removed from
the <tt>words</tt> array.
</p>
<p>Both <var>begin</var> and <var>end</var> may be negative to count backwards
from the last element of the <tt>words</tt> array.
</p>
</dd>
<dt><tt>-N</tt> <var>beg-pat</var> [ <var>end-pat</var> ]</dt>
<dd><p>If one of the elements of the <tt>words</tt> array before the one at the
index given by the value of the parameter <tt>CURRENT</tt> matches the
pattern <var>beg-pat</var>, all elements up to and including the matching one are
removed from the <tt>words</tt> array and the value of <tt>CURRENT</tt> is changed to
point to the same word in the changed array.
</p>
<p>If the optional pattern <var>end-pat</var> is also given, and there is an
element in the <tt>words</tt> array matching this pattern, the parameters
are modified only if the index of this word is higher than the one
given by the <tt>CURRENT</tt> parameter (so that the matching word has
to be after the cursor). In this case, the words starting with the one
matching <tt>end-pat</tt> are also removed from the <tt>words</tt>
array. If <tt>words</tt> contains no word matching <var>end-pat</var>, the
testing and modification is performed as if it were not given.
</p>
</dd>
<dt><tt>-q</tt></dt>
<dd><p>The word
currently being completed is split on spaces into separate words,
respecting the usual shell quoting conventions. The
resulting words are stored in the <tt>words</tt> array, and <tt>CURRENT</tt>,
<tt>PREFIX</tt>, <tt>SUFFIX</tt>, <tt>QIPREFIX</tt>, and <tt>QISUFFIX</tt> are modified to
reflect the word part that is completed.
</p>
</dd>
</dl>
<p>In all the above cases the return status is zero if the test succeeded
and the parameters were modified and non-zero otherwise. This allows
one to use this builtin in tests such as:
</p>
<div class="example">
<pre class="example">if compset -P '*\='; then ...
</pre></div>
<p>This forces anything up to and including the last equal sign to be
ignored by the completion code.
</p>
</dd>
<dt><tt>compcall</tt> [ <tt>-TD</tt> ]</dt>
<dd><p>This allows the use of completions defined with the <tt>compctl</tt> builtin
from within completion widgets. The list of matches will be generated as
if one of the non-widget completion functions (<tt>complete-word</tt>, etc.)
had been called, except that only <tt>compctl</tt>s given for specific commands
are used. To force the code to try completions defined with the <tt>-T</tt>
option of <tt>compctl</tt> and/or the default completion (whether defined by
<tt>compctl -D</tt> or the builtin default) in the appropriate places, the
<tt>-T</tt> and/or <tt>-D</tt> flags can be passed to <tt>compcall</tt>.
</p>
<p>The return status can be used to test if a matching <tt>compctl</tt>
definition was found. It is non-zero if a <tt>compctl</tt> was found and
zero otherwise.
</p>
<p>Note that this builtin is defined by the <tt>zsh/compctl</tt> module.
</p>
</dd>
</dl>
<hr>
<a name="Completion-Condition-Codes"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-Widgets" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Builtin-Commands" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Widgets" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Matching-Control" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left">[<a href="Completion-System.html#Completion-System" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Completion-Condition-Codes-1"></a>
<h2 class="section">19.4 Completion Condition Codes</h2>
<p><a name="index-completion-widgets_002c-condition-codes"></a>
</p>
<p>The following additional condition codes for use within the <tt>[[</tt> <var>...</var> <tt>]]</tt>
construct are available in completion widgets. These work on the special
parameters. All of these tests can also be performed by the <tt>compset</tt>
builtin, but in the case of the condition codes the contents of the special
parameters are not modified.
</p>
<dl compact="compact">
<dt><tt>-prefix</tt> [ <var>number</var> ] <var>pattern</var></dt>
<dd><p>true if the test for the <tt>-P</tt> option of <tt>compset</tt> would succeed.
</p>
</dd>
<dt><tt>-suffix</tt> [ <var>number</var> ] <var>pattern</var></dt>
<dd><p>true if the test for the <tt>-S</tt> option of <tt>compset</tt> would succeed.
</p>
</dd>
<dt><tt>-after</tt> <var>beg-pat</var></dt>
<dd><p>true if the test of the <tt>-N</tt> option with only the <var>beg-pat</var> given
would succeed.
</p>
</dd>
<dt><tt>-between</tt> <var>beg-pat end-pat</var></dt>
<dd><p>true if the test for the <tt>-N</tt> option with both patterns would succeed.
</p>
</dd>
</dl>
<hr>
<a name="Completion-Matching-Control"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-Widgets" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Condition-Codes" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Widgets" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Widget-Example" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left">[<a href="Completion-System.html#Completion-System" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Completion-Matching-Control-1"></a>
<h2 class="section">19.5 Completion Matching Control</h2>
<p>It is possible by use of the
<tt>-M</tt> option of the <tt>compadd</tt> builtin command to specify how the
characters in the string to be completed (referred to here as the
command line) map onto the characters in the list of matches produced by
the completion code (referred to here as the trial completions). Note
that this is not used if the command line contains a glob pattern and
the <tt>GLOB_COMPLETE</tt> option is set or the <tt>pattern_match</tt> of the
<tt>compstate</tt> special association is set to a non-empty string.
</p>
<p>The <var>match-spec</var> given as the argument to the <tt>-M</tt> option (see
<a href="#Completion-Builtin-Commands">Completion Builtin Commands</a>) consists of one or more matching descriptions separated by
whitespace. Each description consists of a letter followed by a colon
and then the patterns describing which character sequences on the line match
which character sequences in the trial completion. Any sequence of
characters not handled in this fashion must match exactly, as usual.
</p>
<p>The forms of <var>match-spec</var> understood are as follows. In each case, the
form with an upper case initial character retains the string already
typed on the command line as the final result of completion, while with
a lower case initial character the string on the command line is changed
into the corresponding part of the trial completion.
</p>
<dl compact="compact">
<dt><tt>m:</tt><var>lpat</var><tt>=</tt><var>tpat</var></dt>
<dt><tt>M:</tt><var>lpat</var><tt>=</tt><var>tpat</var></dt>
<dd><p>Here, <var>lpat</var> is a pattern that matches on the command line,
corresponding to <var>tpat</var> which matches in the trial completion.
</p>
</dd>
<dt><tt>l:</tt><var>lanchor</var><tt>|</tt><var>lpat</var><tt>=</tt><var>tpat</var></dt>
<dt><tt>L:</tt><var>lanchor</var><tt>|</tt><var>lpat</var><tt>=</tt><var>tpat</var></dt>
<dt><tt>l:</tt><var>lanchor</var><tt>||</tt><var>ranchor</var><tt>=</tt><var>tpat</var></dt>
<dt><tt>L:</tt><var>lanchor</var><tt>||</tt><var>ranchor</var><tt>=</tt><var>tpat</var></dt>
<dt><tt>b:</tt><var>lpat</var><tt>=</tt><var>tpat</var></dt>
<dt><tt>B:</tt><var>lpat</var><tt>=</tt><var>tpat</var></dt>
<dd><p>These letters are for patterns that are anchored by another pattern on
the left side. Matching for <var>lpat</var> and <var>tpat</var> is as for <tt>m</tt> and
<tt>M</tt>, but the pattern <var>lpat</var> matched on the command line must be
preceded by the pattern <var>lanchor</var>. The <var>lanchor</var> can be blank to
anchor the match to the start of the command line string; otherwise the
anchor can occur anywhere, but must match in both the command line and
trial completion strings.
</p>
<p>If no <var>lpat</var> is given but a <var>ranchor</var> is, this matches the gap
between substrings matched by <var>lanchor</var> and <var>ranchor</var>. Unlike
<var>lanchor</var>, the <var>ranchor</var> only needs to match the trial
completion string.
</p>
<p>The <tt>b</tt> and <tt>B</tt> forms are similar to <tt>l</tt> and <tt>L</tt> with an empty
anchor, but need to match only the beginning of the word on the command line
or trial completion, respectively.
</p>
</dd>
<dt><tt>r:</tt><var>lpat</var><tt>|</tt><var>ranchor</var><tt>=</tt><var>tpat</var></dt>
<dt><tt>R:</tt><var>lpat</var><tt>|</tt><var>ranchor</var><tt>=</tt><var>tpat</var></dt>
<dt><tt>r:</tt><var>lanchor</var><tt>||</tt><var>ranchor</var><tt>=</tt><var>tpat</var></dt>
<dt><tt>R:</tt><var>lanchor</var><tt>||</tt><var>ranchor</var><tt>=</tt><var>tpat</var></dt>
<dt><tt>e:</tt><var>lpat</var><tt>=</tt><var>tpat</var></dt>
<dt><tt>E:</tt><var>lpat</var><tt>=</tt><var>tpat</var></dt>
<dd><p>As <tt>l</tt>, <tt>L</tt>, <tt>b</tt> and <tt>B</tt>, with the difference that the command
line and trial completion patterns are anchored on the right side.
Here an empty <var>ranchor</var> and the <tt>e</tt> and <tt>E</tt> forms force the
match to the end of the command line or trial completion string.
</p>
</dd>
<dt><tt>x:</tt></dt>
<dd><p>This form is used to mark the end of matching specifications:
subsequent specifications are ignored. In a single standalone list
of specifications this has no use but where matching specifications
are accumulated, such as from nested function calls, it can allow one
function to override another.
</p>
</dd>
</dl>
<p>Each <var>lpat</var>, <var>tpat</var> or <var>anchor</var> is either an empty string or
consists of a sequence of literal characters (which may be quoted with a
backslash), question marks, character classes, and correspondence
classes; ordinary shell patterns are not used. Literal characters match
only themselves, question marks match any character, and character
classes are formed as for globbing and match any character in the given
set.
</p>
<p>Correspondence classes are defined like character classes, but with two
differences: they are delimited by a pair of braces, and negated classes
are not allowed, so the characters <tt>!</tt> and <tt>^</tt> have no special
meaning directly after the opening brace. They indicate that a range of
characters on the line match a range of characters in the trial
completion, but (unlike ordinary character classes) paired according to
the corresponding position in the sequence. For example, to make any
ASCII lower case letter on the line match the corresponding upper case
letter in the trial completion, you can use ‘<tt>m:{a-z}={A-Z}</tt>’
(however, see below for the recommended form for this). More
than one pair of classes can occur, in which case the first class before
the <tt>=</tt> corresponds to the first after it, and so on. If one side has
more such classes than the other side, the superfluous classes behave
like normal character classes. In anchor patterns correspondence classes
also behave like normal character classes.
</p>
<p>The standard ‘<tt>[:</tt><var>name</var><tt>:]</tt>’ forms described for standard shell
patterns (see
<a href="Expansion.html#Filename-Generation">Filename Generation</a>)
may appear in correspondence classes as well as normal character
classes. The only special behaviour in correspondence classes is if
the form on the left and the form on the right are each one of
<tt>[:upper:]</tt>, <tt>[:lower:]</tt>. In these cases the
character in the word and the character on the line must be the same up
to a difference in case. Hence to make any lower case character on the
line match the corresponding upper case character in the trial
completion you can use ‘<tt>m:{[:lower:]}={[:upper:]}</tt>’. Although the
matching system does not yet handle multibyte characters, this is likely
to be a future extension, at which point this syntax will handle
arbitrary alphabets; hence this form, rather than the use of explicit
ranges, is the recommended form. In other cases
‘<tt>[:</tt><var>name</var><tt>:]</tt>’ forms are allowed. If the two forms on the left
and right are the same, the characters must match exactly. In remaining
cases, the corresponding tests are applied to both characters, but they
are not otherwise constrained; any matching character in one set goes
with any matching character in the other set: this is equivalent to the
behaviour of ordinary character classes.
</p>
<p>The pattern <var>tpat</var> may also be one or two stars, ‘<tt>*</tt>’ or
‘<tt>**</tt>’. This means that the pattern on the command line can match
any number of characters in the trial completion. In this case the
pattern must be anchored (on either side); in the case of a single
star, the <var>anchor</var> then determines how much of the trial completion
is to be included — only the characters up to the next appearance of
the anchor will be matched. With two stars, substrings matched by the
anchor can be matched, too.
</p>
<p>Examples:
</p>
<p>The keys of the <tt>options</tt> association defined by the <tt>parameter</tt>
module are the option names in all-lower-case form, without
underscores, and without the optional <tt>no</tt> at the beginning even
though the builtins <tt>setopt</tt> and <tt>unsetopt</tt> understand option names
with upper case letters, underscores, and the optional <tt>no</tt>. The
following alters the matching rules so that the prefix <tt>no</tt> and any
underscore are ignored when trying to match the trial completions
generated and upper case letters on the line match the corresponding
lower case letters in the words:
</p>
<div class="example">
<pre class="example">compadd -M 'L:|[nN][oO]= M:_= M:{[:upper:]}={[:lower:]}' - \
${(k)options}
</pre></div>
<p>The first part says that the pattern ‘<tt>[nN][oO]</tt>’ at the beginning
(the empty anchor before the pipe symbol) of the string on the
line matches the empty string in the list of words generated by
completion, so it will be ignored if present. The second part does the
same for an underscore anywhere in the command line string, and the
third part uses correspondence classes so that any
upper case letter on the line matches the corresponding lower case
letter in the word. The use of the upper case forms of the
specification characters (<tt>L</tt> and <tt>M</tt>) guarantees that what has
already been typed on the command line (in particular the prefix
<tt>no</tt>) will not be deleted.
</p>
<p>Note that the use of <tt>L</tt> in the first part means that it matches
only when at the beginning of both the command line string and the
trial completion. I.e., the string ‘<tt>_NO_f</tt>’ would not be
completed to ‘<tt>_NO_foo</tt>’, nor would ‘<tt>NONO_f</tt>’ be completed to
‘<tt>NONO_foo</tt>’ because of the leading underscore or the second
‘<tt>NO</tt>’ on the line which makes the pattern fail even though they are
otherwise ignored. To fix this, one would use ‘<tt>B:[nN][oO]=</tt>’
instead of the first part. As described above, this matches at the
beginning of the trial completion, independent of other characters or
substrings at the beginning of the command line word which are ignored
by the same or other <var>match-spec</var>s.
</p>
<p>The second example makes completion case insensitive. This is just
the same as in the option example, except here we wish to retain the
characters in the list of completions:
</p>
<div class="example">
<pre class="example">compadd -M 'm:{[:lower:]}={[:upper:]}' ...
</pre></div>
<p>This makes lower case letters match their upper case counterparts.
To make upper case letters match the lower case forms as well:
</p>
<div class="example">
<pre class="example">compadd -M 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' ...
</pre></div>
<p>A nice example for the use of <tt>*</tt> patterns is partial word
completion. Sometimes you would like to make strings like ‘<tt>c.s.u</tt>’
complete to strings like ‘<tt>comp.source.unix</tt>’, i.e. the word on the
command line consists of multiple parts, separated by a dot in this
example, where each part should be completed separately — note,
however, that the case where each part of the word, i.e. ‘<tt>comp</tt>’,
‘<tt>source</tt>’ and ‘<tt>unix</tt>’ in this example, is to be completed from
separate sets of matches
is a different problem to be solved by the implementation of the
completion widget. The example can be handled by:
</p>
<div class="example">
<pre class="example">compadd -M 'r:|.=* r:|=*' \
- comp.sources.unix comp.sources.misc ...
</pre></div>
<p>The first specification says that <var>lpat</var> is the empty string, while
<var>anchor</var> is a dot; <var>tpat</var> is <tt>*</tt>, so this can match anything
except for the ‘<tt>.</tt>’ from the anchor in
the trial completion word. So in ‘<tt>c.s.u</tt>’, the matcher sees ‘<tt>c</tt>’,
followed by the empty string, followed by the anchor ‘<tt>.</tt>’, and
likewise for the second dot, and replaces the empty strings before the
anchors, giving ‘<tt>c</tt>[<tt>omp</tt>]<tt>.s</tt>[<tt>ources</tt>]<tt>.u</tt>[<tt>nix</tt>]’, where
the last part of the completion is just as normal.
</p>
<p>With the pattern shown above, the string ‘<tt>c.u</tt>’ could not be
completed to ‘<tt>comp.sources.unix</tt>’ because the single star means
that no dot (matched by the anchor) can be skipped. By using two stars
as in ‘<tt>r:|.=**</tt>’, however, ‘<tt>c.u</tt>’ could be completed to
‘<tt>comp.sources.unix</tt>’. This also shows that in some cases,
especially if the anchor is a real pattern, like a character class,
the form with two stars may result in more matches than one would like.
</p>
<p>The second specification is needed to make this work when the cursor is
in the middle of the string on the command line and the option
<tt>COMPLETE_IN_WORD</tt> is set. In this case the completion code would
normally try to match trial completions that end with the string as
typed so far, i.e. it will only insert new characters at the cursor
position rather than at the end. However in our example we would like
the code to recognise matches which contain extra characters after the
string on the line (the ‘<tt>nix</tt>’ in the example). Hence we say that the
empty string at the end of the string on the line matches any characters
at the end of the trial completion.
</p>
<p>More generally, the specification
</p>
<div class="example">
<pre class="example">compadd -M 'r:|[.,_-]=* r:|=*' ...
</pre></div>
<p>allows one to complete words with abbreviations before any of the
characters in the square brackets. For example, to
complete <tt>veryverylongfile.c</tt> rather than <tt>veryverylongheader.h</tt>
with the above in effect, you can just type <tt>very.c</tt> before attempting
completion.
</p>
<p>The specifications with both a left and a right anchor are useful to
complete partial words whose parts are not separated by some
special character. For example, in some places strings have to be
completed that are formed ‘<tt>LikeThis</tt>’ (i.e. the separate parts are
determined by a leading upper case letter) or maybe one has to
complete strings with trailing numbers. Here one could use the simple
form with only one anchor as in:
</p>
<div class="example">
<pre class="example">compadd -M 'r:|[[:upper:]0-9]=* r:|=*' LikeTHIS FooHoo 5foo123 5bar234
</pre></div>
<p>But with this, the string ‘<tt>H</tt>’ would neither complete to ‘<tt>FooHoo</tt>’
nor to ‘<tt>LikeTHIS</tt>’ because in each case there is an upper case
letter before the ‘<tt>H</tt>’ and that is matched by the anchor. Likewise,
a ‘<tt>2</tt>’ would not be completed. In both cases this could be changed
by using ‘<tt>r:|[[:upper:]0-9]=**</tt>’, but then ‘<tt>H</tt>’ completes to both
‘<tt>LikeTHIS</tt>’ and ‘<tt>FooHoo</tt>’ and a ‘<tt>2</tt>’ matches the other
strings because characters can be inserted before every upper case
letter and digit. To avoid this one would use:
</p>
<div class="example">
<pre class="example">compadd -M 'r:[^[:upper:]0-9]||[[:upper:]0-9]=** r:|=*' \
LikeTHIS FooHoo foo123 bar234
</pre></div>
<p>By using these two anchors, a ‘<tt>H</tt>’ matches only upper case ‘<tt>H</tt>’s that
are immediately preceded by something matching the left anchor
‘<tt>[^[:upper:]0-9]</tt>’. The effect is, of course, that ‘<tt>H</tt>’ matches only
the string ‘<tt>FooHoo</tt>’, a ‘<tt>2</tt>’ matches only ‘<tt>bar234</tt>’ and so on.
</p>
<p>When using the completion system (see
<a href="Completion-System.html#Completion-System">Completion System</a>), users can define match specifications that are to be used for
specific contexts by using the <tt>matcher</tt> and <tt>matcher-list</tt>
styles. The values for the latter will be used everywhere.
</p>
<hr>
<a name="Completion-Widget-Example"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-Widgets" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Matching-Control" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Completion-Widgets" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Completion-System.html#Completion-System" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left">[<a href="Completion-System.html#Completion-System" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Completion-Widget-Example-1"></a>
<h2 class="section">19.6 Completion Widget Example</h2>
<p><a name="index-completion-widgets_002c-example"></a>
</p>
<p>The first step is to define the widget:
</p>
<div class="example">
<pre class="example">zle -C complete complete-word complete-files
</pre></div>
<p>Then the widget can be bound to a key using the <tt>bindkey</tt> builtin
command:
</p>
<div class="example">
<pre class="example">bindkey '^X\t' complete
</pre></div>
<p>After that the shell function <tt>complete-files</tt> will be invoked
after typing control-X and TAB. The function should then generate the
matches, e.g.:
</p>
<div class="example">
<pre class="example">complete-files () { compadd - * }
</pre></div>
<p>This function will complete files in the current directory matching the
current word.
</p><hr>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Completion-Widgets" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="Completion-System.html#Completion-System" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p><font size="-1">
This document was generated on <em>April 6, 2018</em> using <a href="http://www.gnu.org/software/texinfo/"><em>texi2any</em></a>.
</font></p>
<font size="-1">Zsh version 5.4.2, released on August 27, 2017.</font>
</body>
</html>
|