]>
Commit | Line | Data |
---|---|---|
d3a24ed2 CR |
1 | @comment %**start of header (This is for running Texinfo on a region.) |
2 | @setfilename rluser.info | |
3 | @comment %**end of header (This is for running Texinfo on a region.) | |
d3a24ed2 CR |
4 | |
5 | @ignore | |
6 | This file documents the end user interface to the GNU command line | |
7 | editing features. It is to be an appendix to manuals for programs which | |
8 | use these features. There is a document entitled "readline.texinfo" | |
9 | which contains both end-user and programmer documentation for the | |
10 | GNU Readline Library. | |
11 | ||
1d0e1a34 | 12 | Copyright (C) 1988--2008 Free Software Foundation, Inc. |
d3a24ed2 CR |
13 | |
14 | Authored by Brian Fox and Chet Ramey. | |
15 | ||
16 | Permission is granted to process this file through Tex and print the | |
17 | results, provided the printed document carries copying permission notice | |
18 | identical to this one except for the removal of this paragraph (this | |
19 | paragraph not being relevant to the printed manual). | |
20 | ||
21 | Permission is granted to make and distribute verbatim copies of this manual | |
22 | provided the copyright notice and this permission notice are preserved on | |
23 | all copies. | |
24 | ||
25 | Permission is granted to copy and distribute modified versions of this | |
26 | manual under the conditions for verbatim copying, provided also that the | |
27 | GNU Copyright statement is available to the distributee, and provided that | |
28 | the entire resulting derived work is distributed under the terms of a | |
29 | permission notice identical to this one. | |
30 | ||
31 | Permission is granted to copy and distribute translations of this manual | |
32 | into another language, under the above conditions for modified versions. | |
33 | @end ignore | |
34 | ||
35 | @comment If you are including this manual as an appendix, then set the | |
36 | @comment variable readline-appendix. | |
37 | ||
38 | @ifclear BashFeatures | |
39 | @defcodeindex bt | |
40 | @end ifclear | |
41 | ||
42 | @node Command Line Editing | |
43 | @chapter Command Line Editing | |
44 | ||
45 | This chapter describes the basic features of the @sc{gnu} | |
46 | command line editing interface. | |
47 | @ifset BashFeatures | |
48 | Command line editing is provided by the Readline library, which is | |
49 | used by several different programs, including Bash. | |
50 | @end ifset | |
51 | ||
52 | @menu | |
53 | * Introduction and Notation:: Notation used in this text. | |
54 | * Readline Interaction:: The minimum set of commands for editing a line. | |
55 | * Readline Init File:: Customizing Readline from a user's view. | |
56 | * Bindable Readline Commands:: A description of most of the Readline commands | |
57 | available for binding | |
58 | * Readline vi Mode:: A short description of how to make Readline | |
59 | behave like the vi editor. | |
60 | @ifset BashFeatures | |
61 | * Programmable Completion:: How to specify the possible completions for | |
62 | a specific command. | |
63 | * Programmable Completion Builtins:: Builtin commands to specify how to | |
64 | complete arguments for a particular command. | |
65 | @end ifset | |
66 | @end menu | |
67 | ||
68 | @node Introduction and Notation | |
69 | @section Introduction to Line Editing | |
70 | ||
71 | The following paragraphs describe the notation used to represent | |
72 | keystrokes. | |
73 | ||
74 | The text @kbd{C-k} is read as `Control-K' and describes the character | |
75 | produced when the @key{k} key is pressed while the Control key | |
76 | is depressed. | |
77 | ||
78 | The text @kbd{M-k} is read as `Meta-K' and describes the character | |
79 | produced when the Meta key (if you have one) is depressed, and the @key{k} | |
80 | key is pressed. | |
81 | The Meta key is labeled @key{ALT} on many keyboards. | |
82 | On keyboards with two keys labeled @key{ALT} (usually to either side of | |
83 | the space bar), the @key{ALT} on the left side is generally set to | |
84 | work as a Meta key. | |
85 | The @key{ALT} key on the right may also be configured to work as a | |
86 | Meta key or may be configured as some other modifier, such as a | |
87 | Compose key for typing accented characters. | |
88 | ||
89 | If you do not have a Meta or @key{ALT} key, or another key working as | |
90 | a Meta key, the identical keystroke can be generated by typing @key{ESC} | |
91 | @emph{first}, and then typing @key{k}. | |
92 | Either process is known as @dfn{metafying} the @key{k} key. | |
93 | ||
94 | The text @kbd{M-C-k} is read as `Meta-Control-k' and describes the | |
95 | character produced by @dfn{metafying} @kbd{C-k}. | |
96 | ||
97 | In addition, several keys have their own names. Specifically, | |
98 | @key{DEL}, @key{ESC}, @key{LFD}, @key{SPC}, @key{RET}, and @key{TAB} all | |
99 | stand for themselves when seen in this text, or in an init file | |
100 | (@pxref{Readline Init File}). | |
101 | If your keyboard lacks a @key{LFD} key, typing @key{C-j} will | |
102 | produce the desired character. | |
103 | The @key{RET} key may be labeled @key{Return} or @key{Enter} on | |
104 | some keyboards. | |
105 | ||
106 | @node Readline Interaction | |
107 | @section Readline Interaction | |
108 | @cindex interaction, readline | |
109 | ||
110 | Often during an interactive session you type in a long line of text, | |
111 | only to notice that the first word on the line is misspelled. The | |
112 | Readline library gives you a set of commands for manipulating the text | |
113 | as you type it in, allowing you to just fix your typo, and not forcing | |
114 | you to retype the majority of the line. Using these editing commands, | |
115 | you move the cursor to the place that needs correction, and delete or | |
116 | insert the text of the corrections. Then, when you are satisfied with | |
117 | the line, you simply press @key{RET}. You do not have to be at the | |
118 | end of the line to press @key{RET}; the entire line is accepted | |
119 | regardless of the location of the cursor within the line. | |
120 | ||
121 | @menu | |
122 | * Readline Bare Essentials:: The least you need to know about Readline. | |
123 | * Readline Movement Commands:: Moving about the input line. | |
124 | * Readline Killing Commands:: How to delete text, and how to get it back! | |
125 | * Readline Arguments:: Giving numeric arguments to commands. | |
126 | * Searching:: Searching through previous lines. | |
127 | @end menu | |
128 | ||
129 | @node Readline Bare Essentials | |
130 | @subsection Readline Bare Essentials | |
131 | @cindex notation, readline | |
132 | @cindex command editing | |
133 | @cindex editing command lines | |
134 | ||
135 | In order to enter characters into the line, simply type them. The typed | |
136 | character appears where the cursor was, and then the cursor moves one | |
137 | space to the right. If you mistype a character, you can use your | |
138 | erase character to back up and delete the mistyped character. | |
139 | ||
140 | Sometimes you may mistype a character, and | |
141 | not notice the error until you have typed several other characters. In | |
142 | that case, you can type @kbd{C-b} to move the cursor to the left, and then | |
143 | correct your mistake. Afterwards, you can move the cursor to the right | |
144 | with @kbd{C-f}. | |
145 | ||
146 | When you add text in the middle of a line, you will notice that characters | |
147 | to the right of the cursor are `pushed over' to make room for the text | |
148 | that you have inserted. Likewise, when you delete text behind the cursor, | |
149 | characters to the right of the cursor are `pulled back' to fill in the | |
150 | blank space created by the removal of the text. A list of the bare | |
151 | essentials for editing the text of an input line follows. | |
152 | ||
153 | @table @asis | |
154 | @item @kbd{C-b} | |
155 | Move back one character. | |
156 | @item @kbd{C-f} | |
157 | Move forward one character. | |
158 | @item @key{DEL} or @key{Backspace} | |
159 | Delete the character to the left of the cursor. | |
160 | @item @kbd{C-d} | |
161 | Delete the character underneath the cursor. | |
162 | @item @w{Printing characters} | |
163 | Insert the character into the line at the cursor. | |
164 | @item @kbd{C-_} or @kbd{C-x C-u} | |
165 | Undo the last editing command. You can undo all the way back to an | |
166 | empty line. | |
167 | @end table | |
168 | ||
169 | @noindent | |
170 | (Depending on your configuration, the @key{Backspace} key be set to | |
171 | delete the character to the left of the cursor and the @key{DEL} key set | |
172 | to delete the character underneath the cursor, like @kbd{C-d}, rather | |
173 | than the character to the left of the cursor.) | |
174 | ||
175 | @node Readline Movement Commands | |
176 | @subsection Readline Movement Commands | |
177 | ||
178 | ||
179 | The above table describes the most basic keystrokes that you need | |
180 | in order to do editing of the input line. For your convenience, many | |
181 | other commands have been added in addition to @kbd{C-b}, @kbd{C-f}, | |
182 | @kbd{C-d}, and @key{DEL}. Here are some commands for moving more rapidly | |
183 | about the line. | |
184 | ||
185 | @table @kbd | |
186 | @item C-a | |
187 | Move to the start of the line. | |
188 | @item C-e | |
189 | Move to the end of the line. | |
190 | @item M-f | |
191 | Move forward a word, where a word is composed of letters and digits. | |
192 | @item M-b | |
193 | Move backward a word. | |
194 | @item C-l | |
195 | Clear the screen, reprinting the current line at the top. | |
196 | @end table | |
197 | ||
198 | Notice how @kbd{C-f} moves forward a character, while @kbd{M-f} moves | |
199 | forward a word. It is a loose convention that control keystrokes | |
200 | operate on characters while meta keystrokes operate on words. | |
201 | ||
202 | @node Readline Killing Commands | |
203 | @subsection Readline Killing Commands | |
204 | ||
205 | @cindex killing text | |
206 | @cindex yanking text | |
207 | ||
208 | @dfn{Killing} text means to delete the text from the line, but to save | |
209 | it away for later use, usually by @dfn{yanking} (re-inserting) | |
210 | it back into the line. | |
211 | (`Cut' and `paste' are more recent jargon for `kill' and `yank'.) | |
212 | ||
213 | If the description for a command says that it `kills' text, then you can | |
214 | be sure that you can get the text back in a different (or the same) | |
215 | place later. | |
216 | ||
217 | When you use a kill command, the text is saved in a @dfn{kill-ring}. | |
218 | Any number of consecutive kills save all of the killed text together, so | |
219 | that when you yank it back, you get it all. The kill | |
220 | ring is not line specific; the text that you killed on a previously | |
221 | typed line is available to be yanked back later, when you are typing | |
222 | another line. | |
223 | @cindex kill ring | |
224 | ||
225 | Here is the list of commands for killing text. | |
226 | ||
227 | @table @kbd | |
228 | @item C-k | |
229 | Kill the text from the current cursor position to the end of the line. | |
230 | ||
231 | @item M-d | |
232 | Kill from the cursor to the end of the current word, or, if between | |
233 | words, to the end of the next word. | |
234 | Word boundaries are the same as those used by @kbd{M-f}. | |
235 | ||
236 | @item M-@key{DEL} | |
237 | Kill from the cursor the start of the current word, or, if between | |
238 | words, to the start of the previous word. | |
239 | Word boundaries are the same as those used by @kbd{M-b}. | |
240 | ||
241 | @item C-w | |
242 | Kill from the cursor to the previous whitespace. This is different than | |
243 | @kbd{M-@key{DEL}} because the word boundaries differ. | |
244 | ||
245 | @end table | |
246 | ||
247 | Here is how to @dfn{yank} the text back into the line. Yanking | |
248 | means to copy the most-recently-killed text from the kill buffer. | |
249 | ||
250 | @table @kbd | |
251 | @item C-y | |
252 | Yank the most recently killed text back into the buffer at the cursor. | |
253 | ||
254 | @item M-y | |
255 | Rotate the kill-ring, and yank the new top. You can only do this if | |
256 | the prior command is @kbd{C-y} or @kbd{M-y}. | |
257 | @end table | |
258 | ||
259 | @node Readline Arguments | |
260 | @subsection Readline Arguments | |
261 | ||
262 | You can pass numeric arguments to Readline commands. Sometimes the | |
263 | argument acts as a repeat count, other times it is the @i{sign} of the | |
264 | argument that is significant. If you pass a negative argument to a | |
265 | command which normally acts in a forward direction, that command will | |
266 | act in a backward direction. For example, to kill text back to the | |
267 | start of the line, you might type @samp{M-- C-k}. | |
268 | ||
269 | The general way to pass numeric arguments to a command is to type meta | |
270 | digits before the command. If the first `digit' typed is a minus | |
271 | sign (@samp{-}), then the sign of the argument will be negative. Once | |
272 | you have typed one meta digit to get the argument started, you can type | |
273 | the remainder of the digits, and then the command. For example, to give | |
274 | the @kbd{C-d} command an argument of 10, you could type @samp{M-1 0 C-d}, | |
275 | which will delete the next ten characters on the input line. | |
276 | ||
277 | @node Searching | |
278 | @subsection Searching for Commands in the History | |
279 | ||
280 | Readline provides commands for searching through the command history | |
281 | @ifset BashFeatures | |
282 | (@pxref{Bash History Facilities}) | |
283 | @end ifset | |
284 | for lines containing a specified string. | |
285 | There are two search modes: @dfn{incremental} and @dfn{non-incremental}. | |
286 | ||
287 | Incremental searches begin before the user has finished typing the | |
288 | search string. | |
289 | As each character of the search string is typed, Readline displays | |
290 | the next entry from the history matching the string typed so far. | |
291 | An incremental search requires only as many characters as needed to | |
292 | find the desired history entry. | |
293 | To search backward in the history for a particular string, type | |
294 | @kbd{C-r}. Typing @kbd{C-s} searches forward through the history. | |
295 | The characters present in the value of the @code{isearch-terminators} variable | |
296 | are used to terminate an incremental search. | |
297 | If that variable has not been assigned a value, the @key{ESC} and | |
298 | @kbd{C-J} characters will terminate an incremental search. | |
299 | @kbd{C-g} will abort an incremental search and restore the original line. | |
300 | When the search is terminated, the history entry containing the | |
301 | search string becomes the current line. | |
302 | ||
303 | To find other matching entries in the history list, type @kbd{C-r} or | |
304 | @kbd{C-s} as appropriate. | |
305 | This will search backward or forward in the history for the next | |
306 | entry matching the search string typed so far. | |
307 | Any other key sequence bound to a Readline command will terminate | |
308 | the search and execute that command. | |
309 | For instance, a @key{RET} will terminate the search and accept | |
310 | the line, thereby executing the command from the history list. | |
311 | A movement command will terminate the search, make the last line found | |
312 | the current line, and begin editing. | |
313 | ||
314 | Readline remembers the last incremental search string. If two | |
315 | @kbd{C-r}s are typed without any intervening characters defining a new | |
316 | search string, any remembered search string is used. | |
317 | ||
318 | Non-incremental searches read the entire search string before starting | |
319 | to search for matching history lines. The search string may be | |
320 | typed by the user or be part of the contents of the current line. | |
321 | ||
322 | @node Readline Init File | |
323 | @section Readline Init File | |
324 | @cindex initialization file, readline | |
325 | ||
326 | Although the Readline library comes with a set of Emacs-like | |
327 | keybindings installed by default, it is possible to use a different set | |
328 | of keybindings. | |
329 | Any user can customize programs that use Readline by putting | |
330 | commands in an @dfn{inputrc} file, conventionally in his home directory. | |
331 | The name of this | |
332 | @ifset BashFeatures | |
333 | file is taken from the value of the shell variable @env{INPUTRC}. If | |
334 | @end ifset | |
335 | @ifclear BashFeatures | |
336 | file is taken from the value of the environment variable @env{INPUTRC}. If | |
337 | @end ifclear | |
8d618825 CR |
338 | that variable is unset, the default is @file{~/.inputrc}. If that |
339 | file does not exist or cannot be read, the ultimate default is | |
340 | @file{/etc/inputrc}. | |
d3a24ed2 CR |
341 | |
342 | When a program which uses the Readline library starts up, the | |
343 | init file is read, and the key bindings are set. | |
344 | ||
345 | In addition, the @code{C-x C-r} command re-reads this init file, thus | |
346 | incorporating any changes that you might have made to it. | |
347 | ||
348 | @menu | |
349 | * Readline Init File Syntax:: Syntax for the commands in the inputrc file. | |
350 | ||
351 | * Conditional Init Constructs:: Conditional key bindings in the inputrc file. | |
352 | ||
353 | * Sample Init File:: An example inputrc file. | |
354 | @end menu | |
355 | ||
356 | @node Readline Init File Syntax | |
357 | @subsection Readline Init File Syntax | |
358 | ||
359 | There are only a few basic constructs allowed in the | |
360 | Readline init file. Blank lines are ignored. | |
361 | Lines beginning with a @samp{#} are comments. | |
362 | Lines beginning with a @samp{$} indicate conditional | |
363 | constructs (@pxref{Conditional Init Constructs}). Other lines | |
364 | denote variable settings and key bindings. | |
365 | ||
366 | @table @asis | |
367 | @item Variable Settings | |
368 | You can modify the run-time behavior of Readline by | |
369 | altering the values of variables in Readline | |
370 | using the @code{set} command within the init file. | |
371 | The syntax is simple: | |
372 | ||
373 | @example | |
374 | set @var{variable} @var{value} | |
375 | @end example | |
376 | ||
377 | @noindent | |
378 | Here, for example, is how to | |
379 | change from the default Emacs-like key binding to use | |
380 | @code{vi} line editing commands: | |
381 | ||
382 | @example | |
383 | set editing-mode vi | |
384 | @end example | |
385 | ||
386 | Variable names and values, where appropriate, are recognized without regard | |
ff247e74 CR |
387 | to case. Unrecognized variable names are ignored. |
388 | ||
389 | Boolean variables (those that can be set to on or off) are set to on if | |
390 | the value is null or empty, @var{on} (case-insensitive), or 1. Any other | |
391 | value results in the variable being set to off. | |
d3a24ed2 CR |
392 | |
393 | @ifset BashFeatures | |
394 | The @w{@code{bind -V}} command lists the current Readline variable names | |
395 | and values. @xref{Bash Builtins}. | |
396 | @end ifset | |
397 | ||
398 | A great deal of run-time behavior is changeable with the following | |
399 | variables. | |
400 | ||
401 | @cindex variables, readline | |
402 | @table @code | |
403 | ||
404 | @item bell-style | |
405 | @vindex bell-style | |
406 | Controls what happens when Readline wants to ring the terminal bell. | |
407 | If set to @samp{none}, Readline never rings the bell. If set to | |
408 | @samp{visible}, Readline uses a visible bell if one is available. | |
409 | If set to @samp{audible} (the default), Readline attempts to ring | |
410 | the terminal's bell. | |
411 | ||
453f278a | 412 | @item bind-tty-special-chars |
eb2bb562 | 413 | @vindex bind-tty-special-chars |
453f278a CR |
414 | If set to @samp{on}, Readline attempts to bind the control characters |
415 | treated specially by the kernel's terminal driver to their Readline | |
416 | equivalents. | |
417 | ||
d3a24ed2 CR |
418 | @item comment-begin |
419 | @vindex comment-begin | |
420 | The string to insert at the beginning of the line when the | |
421 | @code{insert-comment} command is executed. The default value | |
422 | is @code{"#"}. | |
423 | ||
424 | @item completion-ignore-case | |
425 | If set to @samp{on}, Readline performs filename matching and completion | |
426 | in a case-insensitive fashion. | |
427 | The default value is @samp{off}. | |
428 | ||
429 | @item completion-query-items | |
430 | @vindex completion-query-items | |
431 | The number of possible completions that determines when the user is | |
432 | asked whether the list of possibilities should be displayed. | |
433 | If the number of possible completions is greater than this value, | |
434 | Readline will ask the user whether or not he wishes to view | |
435 | them; otherwise, they are simply listed. | |
436 | This variable must be set to an integer value greater than or equal to 0. | |
66e6d7cf | 437 | A negative value means Readline should never ask. |
d3a24ed2 CR |
438 | The default limit is @code{100}. |
439 | ||
440 | @item convert-meta | |
441 | @vindex convert-meta | |
442 | If set to @samp{on}, Readline will convert characters with the | |
443 | eighth bit set to an @sc{ascii} key sequence by stripping the eighth | |
444 | bit and prefixing an @key{ESC} character, converting them to a | |
445 | meta-prefixed key sequence. The default value is @samp{on}. | |
446 | ||
447 | @item disable-completion | |
448 | @vindex disable-completion | |
449 | If set to @samp{On}, Readline will inhibit word completion. | |
450 | Completion characters will be inserted into the line as if they had | |
451 | been mapped to @code{self-insert}. The default is @samp{off}. | |
452 | ||
453 | @item editing-mode | |
454 | @vindex editing-mode | |
455 | The @code{editing-mode} variable controls which default set of | |
456 | key bindings is used. By default, Readline starts up in Emacs editing | |
457 | mode, where the keystrokes are most similar to Emacs. This variable can be | |
458 | set to either @samp{emacs} or @samp{vi}. | |
459 | ||
460 | @item enable-keypad | |
461 | @vindex enable-keypad | |
462 | When set to @samp{on}, Readline will try to enable the application | |
463 | keypad when it is called. Some systems need this to enable the | |
464 | arrow keys. The default is @samp{off}. | |
465 | ||
466 | @item expand-tilde | |
467 | @vindex expand-tilde | |
468 | If set to @samp{on}, tilde expansion is performed when Readline | |
469 | attempts word completion. The default is @samp{off}. | |
470 | ||
a2e7f358 | 471 | @item history-preserve-point |
d3a24ed2 | 472 | @vindex history-preserve-point |
d3ad40de CR |
473 | If set to @samp{on}, the history code attempts to place the point (the |
474 | current cursor position) at the | |
d3a24ed2 | 475 | same location on each history line retrieved with @code{previous-history} |
a2e7f358 | 476 | or @code{next-history}. The default is @samp{off}. |
d3a24ed2 | 477 | |
1d0e1a34 CR |
478 | @item history-size |
479 | @vindex history-size | |
480 | Set the maximum number of history entries saved in the history list. If | |
481 | set to zero, the number of entries in the history list is not limited. | |
482 | ||
d3a24ed2 CR |
483 | @item horizontal-scroll-mode |
484 | @vindex horizontal-scroll-mode | |
485 | This variable can be set to either @samp{on} or @samp{off}. Setting it | |
486 | to @samp{on} means that the text of the lines being edited will scroll | |
487 | horizontally on a single screen line when they are longer than the width | |
488 | of the screen, instead of wrapping onto a new screen line. By default, | |
489 | this variable is set to @samp{off}. | |
490 | ||
491 | @item input-meta | |
492 | @vindex input-meta | |
493 | @vindex meta-flag | |
494 | If set to @samp{on}, Readline will enable eight-bit input (it | |
495 | will not clear the eighth bit in the characters it reads), | |
496 | regardless of what the terminal claims it can support. The | |
497 | default value is @samp{off}. The name @code{meta-flag} is a | |
498 | synonym for this variable. | |
499 | ||
500 | @item isearch-terminators | |
501 | @vindex isearch-terminators | |
502 | The string of characters that should terminate an incremental search without | |
503 | subsequently executing the character as a command (@pxref{Searching}). | |
504 | If this variable has not been given a value, the characters @key{ESC} and | |
505 | @kbd{C-J} will terminate an incremental search. | |
506 | ||
507 | @item keymap | |
508 | @vindex keymap | |
509 | Sets Readline's idea of the current keymap for key binding commands. | |
510 | Acceptable @code{keymap} names are | |
511 | @code{emacs}, | |
512 | @code{emacs-standard}, | |
513 | @code{emacs-meta}, | |
514 | @code{emacs-ctlx}, | |
515 | @code{vi}, | |
516 | @code{vi-move}, | |
517 | @code{vi-command}, and | |
518 | @code{vi-insert}. | |
519 | @code{vi} is equivalent to @code{vi-command}; @code{emacs} is | |
520 | equivalent to @code{emacs-standard}. The default value is @code{emacs}. | |
521 | The value of the @code{editing-mode} variable also affects the | |
522 | default keymap. | |
523 | ||
524 | @item mark-directories | |
525 | If set to @samp{on}, completed directory names have a slash | |
526 | appended. The default is @samp{on}. | |
527 | ||
528 | @item mark-modified-lines | |
529 | @vindex mark-modified-lines | |
530 | This variable, when set to @samp{on}, causes Readline to display an | |
531 | asterisk (@samp{*}) at the start of history lines which have been modified. | |
532 | This variable is @samp{off} by default. | |
533 | ||
534 | @item mark-symlinked-directories | |
535 | @vindex mark-symlinked-directories | |
536 | If set to @samp{on}, completed names which are symbolic links | |
537 | to directories have a slash appended (subject to the value of | |
538 | @code{mark-directories}). | |
539 | The default is @samp{off}. | |
540 | ||
541 | @item match-hidden-files | |
542 | @vindex match-hidden-files | |
543 | This variable, when set to @samp{on}, causes Readline to match files whose | |
544 | names begin with a @samp{.} (hidden files) when performing filename | |
545 | completion, unless the leading @samp{.} is | |
546 | supplied by the user in the filename to be completed. | |
547 | This variable is @samp{on} by default. | |
548 | ||
549 | @item output-meta | |
550 | @vindex output-meta | |
551 | If set to @samp{on}, Readline will display characters with the | |
552 | eighth bit set directly rather than as a meta-prefixed escape | |
553 | sequence. The default is @samp{off}. | |
554 | ||
555 | @item page-completions | |
556 | @vindex page-completions | |
557 | If set to @samp{on}, Readline uses an internal @code{more}-like pager | |
558 | to display a screenful of possible completions at a time. | |
559 | This variable is @samp{on} by default. | |
560 | ||
561 | @item print-completions-horizontally | |
562 | If set to @samp{on}, Readline will display completions with matches | |
563 | sorted horizontally in alphabetical order, rather than down the screen. | |
564 | The default is @samp{off}. | |
565 | ||
566 | @item show-all-if-ambiguous | |
567 | @vindex show-all-if-ambiguous | |
568 | This alters the default behavior of the completion functions. If | |
569 | set to @samp{on}, | |
570 | words which have more than one possible completion cause the | |
571 | matches to be listed immediately instead of ringing the bell. | |
572 | The default value is @samp{off}. | |
573 | ||
574 | @item show-all-if-unmodified | |
575 | @vindex show-all-if-unmodified | |
576 | This alters the default behavior of the completion functions in | |
577 | a fashion similar to @var{show-all-if-ambiguous}. | |
578 | If set to @samp{on}, | |
579 | words which have more than one possible completion without any | |
580 | possible partial completion (the possible completions don't share | |
581 | a common prefix) cause the matches to be listed immediately instead | |
582 | of ringing the bell. | |
583 | The default value is @samp{off}. | |
584 | ||
585 | @item visible-stats | |
586 | @vindex visible-stats | |
587 | If set to @samp{on}, a character denoting a file's type | |
588 | is appended to the filename when listing possible | |
589 | completions. The default is @samp{off}. | |
590 | ||
591 | @end table | |
592 | ||
593 | @item Key Bindings | |
594 | The syntax for controlling key bindings in the init file is | |
595 | simple. First you need to find the name of the command that you | |
596 | want to change. The following sections contain tables of the command | |
597 | name, the default keybinding, if any, and a short description of what | |
598 | the command does. | |
599 | ||
600 | Once you know the name of the command, simply place on a line | |
601 | in the init file the name of the key | |
602 | you wish to bind the command to, a colon, and then the name of the | |
d3ad40de CR |
603 | command. |
604 | There can be no space between the key name and the colon -- that will be | |
605 | interpreted as part of the key name. | |
606 | The name of the key can be expressed in different ways, depending on | |
607 | what you find most comfortable. | |
d3a24ed2 CR |
608 | |
609 | In addition to command names, readline allows keys to be bound | |
610 | to a string that is inserted when the key is pressed (a @var{macro}). | |
611 | ||
612 | @ifset BashFeatures | |
613 | The @w{@code{bind -p}} command displays Readline function names and | |
614 | bindings in a format that can put directly into an initialization file. | |
615 | @xref{Bash Builtins}. | |
616 | @end ifset | |
617 | ||
618 | @table @asis | |
619 | @item @w{@var{keyname}: @var{function-name} or @var{macro}} | |
620 | @var{keyname} is the name of a key spelled out in English. For example: | |
621 | @example | |
622 | Control-u: universal-argument | |
623 | Meta-Rubout: backward-kill-word | |
624 | Control-o: "> output" | |
625 | @end example | |
626 | ||
627 | In the above example, @kbd{C-u} is bound to the function | |
628 | @code{universal-argument}, | |
629 | @kbd{M-DEL} is bound to the function @code{backward-kill-word}, and | |
630 | @kbd{C-o} is bound to run the macro | |
631 | expressed on the right hand side (that is, to insert the text | |
632 | @samp{> output} into the line). | |
633 | ||
634 | A number of symbolic character names are recognized while | |
635 | processing this key binding syntax: | |
636 | @var{DEL}, | |
637 | @var{ESC}, | |
638 | @var{ESCAPE}, | |
639 | @var{LFD}, | |
640 | @var{NEWLINE}, | |
641 | @var{RET}, | |
642 | @var{RETURN}, | |
643 | @var{RUBOUT}, | |
644 | @var{SPACE}, | |
645 | @var{SPC}, | |
646 | and | |
647 | @var{TAB}. | |
648 | ||
649 | @item @w{"@var{keyseq}": @var{function-name} or @var{macro}} | |
650 | @var{keyseq} differs from @var{keyname} above in that strings | |
651 | denoting an entire key sequence can be specified, by placing | |
652 | the key sequence in double quotes. Some @sc{gnu} Emacs style key | |
653 | escapes can be used, as in the following example, but the | |
654 | special character names are not recognized. | |
655 | ||
656 | @example | |
657 | "\C-u": universal-argument | |
658 | "\C-x\C-r": re-read-init-file | |
659 | "\e[11~": "Function Key 1" | |
660 | @end example | |
661 | ||
662 | In the above example, @kbd{C-u} is again bound to the function | |
663 | @code{universal-argument} (just as it was in the first example), | |
664 | @samp{@kbd{C-x} @kbd{C-r}} is bound to the function @code{re-read-init-file}, | |
665 | and @samp{@key{ESC} @key{[} @key{1} @key{1} @key{~}} is bound to insert | |
666 | the text @samp{Function Key 1}. | |
667 | ||
668 | @end table | |
669 | ||
670 | The following @sc{gnu} Emacs style escape sequences are available when | |
671 | specifying key sequences: | |
672 | ||
673 | @table @code | |
674 | @item @kbd{\C-} | |
675 | control prefix | |
676 | @item @kbd{\M-} | |
677 | meta prefix | |
678 | @item @kbd{\e} | |
679 | an escape character | |
680 | @item @kbd{\\} | |
681 | backslash | |
682 | @item @kbd{\"} | |
683 | @key{"}, a double quotation mark | |
684 | @item @kbd{\'} | |
685 | @key{'}, a single quote or apostrophe | |
686 | @end table | |
687 | ||
688 | In addition to the @sc{gnu} Emacs style escape sequences, a second | |
689 | set of backslash escapes is available: | |
690 | ||
691 | @table @code | |
692 | @item \a | |
693 | alert (bell) | |
694 | @item \b | |
695 | backspace | |
696 | @item \d | |
697 | delete | |
698 | @item \f | |
699 | form feed | |
700 | @item \n | |
701 | newline | |
702 | @item \r | |
703 | carriage return | |
704 | @item \t | |
705 | horizontal tab | |
706 | @item \v | |
707 | vertical tab | |
708 | @item \@var{nnn} | |
709 | the eight-bit character whose value is the octal value @var{nnn} | |
710 | (one to three digits) | |
711 | @item \x@var{HH} | |
712 | the eight-bit character whose value is the hexadecimal value @var{HH} | |
713 | (one or two hex digits) | |
714 | @end table | |
715 | ||
716 | When entering the text of a macro, single or double quotes must | |
717 | be used to indicate a macro definition. | |
718 | Unquoted text is assumed to be a function name. | |
719 | In the macro body, the backslash escapes described above are expanded. | |
720 | Backslash will quote any other character in the macro text, | |
721 | including @samp{"} and @samp{'}. | |
722 | For example, the following binding will make @samp{@kbd{C-x} \} | |
723 | insert a single @samp{\} into the line: | |
724 | @example | |
725 | "\C-x\\": "\\" | |
726 | @end example | |
727 | ||
728 | @end table | |
729 | ||
730 | @node Conditional Init Constructs | |
731 | @subsection Conditional Init Constructs | |
732 | ||
733 | Readline implements a facility similar in spirit to the conditional | |
734 | compilation features of the C preprocessor which allows key | |
735 | bindings and variable settings to be performed as the result | |
736 | of tests. There are four parser directives used. | |
737 | ||
738 | @table @code | |
739 | @item $if | |
740 | The @code{$if} construct allows bindings to be made based on the | |
741 | editing mode, the terminal being used, or the application using | |
742 | Readline. The text of the test extends to the end of the line; | |
743 | no characters are required to isolate it. | |
744 | ||
745 | @table @code | |
746 | @item mode | |
747 | The @code{mode=} form of the @code{$if} directive is used to test | |
748 | whether Readline is in @code{emacs} or @code{vi} mode. | |
749 | This may be used in conjunction | |
750 | with the @samp{set keymap} command, for instance, to set bindings in | |
751 | the @code{emacs-standard} and @code{emacs-ctlx} keymaps only if | |
752 | Readline is starting out in @code{emacs} mode. | |
753 | ||
754 | @item term | |
755 | The @code{term=} form may be used to include terminal-specific | |
756 | key bindings, perhaps to bind the key sequences output by the | |
757 | terminal's function keys. The word on the right side of the | |
758 | @samp{=} is tested against both the full name of the terminal and | |
759 | the portion of the terminal name before the first @samp{-}. This | |
760 | allows @code{sun} to match both @code{sun} and @code{sun-cmd}, | |
761 | for instance. | |
762 | ||
763 | @item application | |
764 | The @var{application} construct is used to include | |
765 | application-specific settings. Each program using the Readline | |
766 | library sets the @var{application name}, and you can test for | |
767 | a particular value. | |
768 | This could be used to bind key sequences to functions useful for | |
769 | a specific program. For instance, the following command adds a | |
770 | key sequence that quotes the current or previous word in Bash: | |
771 | @example | |
772 | $if Bash | |
773 | # Quote the current or previous word | |
774 | "\C-xq": "\eb\"\ef\"" | |
775 | $endif | |
776 | @end example | |
777 | @end table | |
778 | ||
779 | @item $endif | |
780 | This command, as seen in the previous example, terminates an | |
781 | @code{$if} command. | |
782 | ||
783 | @item $else | |
784 | Commands in this branch of the @code{$if} directive are executed if | |
785 | the test fails. | |
786 | ||
787 | @item $include | |
788 | This directive takes a single filename as an argument and reads commands | |
789 | and bindings from that file. | |
790 | For example, the following directive reads from @file{/etc/inputrc}: | |
791 | @example | |
792 | $include /etc/inputrc | |
793 | @end example | |
794 | @end table | |
795 | ||
796 | @node Sample Init File | |
797 | @subsection Sample Init File | |
798 | ||
799 | Here is an example of an @var{inputrc} file. This illustrates key | |
800 | binding, variable assignment, and conditional syntax. | |
801 | ||
802 | @example | |
803 | @page | |
804 | # This file controls the behaviour of line input editing for | |
805 | # programs that use the GNU Readline library. Existing | |
806 | # programs include FTP, Bash, and GDB. | |
807 | # | |
808 | # You can re-read the inputrc file with C-x C-r. | |
809 | # Lines beginning with '#' are comments. | |
810 | # | |
811 | # First, include any systemwide bindings and variable | |
812 | # assignments from /etc/Inputrc | |
813 | $include /etc/Inputrc | |
814 | ||
815 | # | |
816 | # Set various bindings for emacs mode. | |
817 | ||
818 | set editing-mode emacs | |
819 | ||
820 | $if mode=emacs | |
821 | ||
822 | Meta-Control-h: backward-kill-word Text after the function name is ignored | |
823 | ||
824 | # | |
825 | # Arrow keys in keypad mode | |
826 | # | |
827 | #"\M-OD": backward-char | |
828 | #"\M-OC": forward-char | |
829 | #"\M-OA": previous-history | |
830 | #"\M-OB": next-history | |
831 | # | |
832 | # Arrow keys in ANSI mode | |
833 | # | |
834 | "\M-[D": backward-char | |
835 | "\M-[C": forward-char | |
836 | "\M-[A": previous-history | |
837 | "\M-[B": next-history | |
838 | # | |
839 | # Arrow keys in 8 bit keypad mode | |
840 | # | |
841 | #"\M-\C-OD": backward-char | |
842 | #"\M-\C-OC": forward-char | |
843 | #"\M-\C-OA": previous-history | |
844 | #"\M-\C-OB": next-history | |
845 | # | |
846 | # Arrow keys in 8 bit ANSI mode | |
847 | # | |
848 | #"\M-\C-[D": backward-char | |
849 | #"\M-\C-[C": forward-char | |
850 | #"\M-\C-[A": previous-history | |
851 | #"\M-\C-[B": next-history | |
852 | ||
853 | C-q: quoted-insert | |
854 | ||
855 | $endif | |
856 | ||
857 | # An old-style binding. This happens to be the default. | |
858 | TAB: complete | |
859 | ||
860 | # Macros that are convenient for shell interaction | |
861 | $if Bash | |
862 | # edit the path | |
863 | "\C-xp": "PATH=$@{PATH@}\e\C-e\C-a\ef\C-f" | |
864 | # prepare to type a quoted word -- | |
865 | # insert open and close double quotes | |
866 | # and move to just after the open quote | |
867 | "\C-x\"": "\"\"\C-b" | |
868 | # insert a backslash (testing backslash escapes | |
869 | # in sequences and macros) | |
870 | "\C-x\\": "\\" | |
871 | # Quote the current or previous word | |
872 | "\C-xq": "\eb\"\ef\"" | |
873 | # Add a binding to refresh the line, which is unbound | |
874 | "\C-xr": redraw-current-line | |
875 | # Edit variable on current line. | |
876 | "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y=" | |
877 | $endif | |
878 | ||
879 | # use a visible bell if one is available | |
880 | set bell-style visible | |
881 | ||
882 | # don't strip characters to 7 bits when reading | |
883 | set input-meta on | |
884 | ||
885 | # allow iso-latin1 characters to be inserted rather | |
886 | # than converted to prefix-meta sequences | |
887 | set convert-meta off | |
888 | ||
889 | # display characters with the eighth bit set directly | |
890 | # rather than as meta-prefixed characters | |
891 | set output-meta on | |
892 | ||
893 | # if there are more than 150 possible completions for | |
894 | # a word, ask the user if he wants to see all of them | |
895 | set completion-query-items 150 | |
896 | ||
897 | # For FTP | |
898 | $if Ftp | |
899 | "\C-xg": "get \M-?" | |
900 | "\C-xt": "put \M-?" | |
901 | "\M-.": yank-last-arg | |
902 | $endif | |
903 | @end example | |
904 | ||
905 | @node Bindable Readline Commands | |
906 | @section Bindable Readline Commands | |
907 | ||
908 | @menu | |
909 | * Commands For Moving:: Moving about the line. | |
910 | * Commands For History:: Getting at previous lines. | |
911 | * Commands For Text:: Commands for changing text. | |
912 | * Commands For Killing:: Commands for killing and yanking. | |
913 | * Numeric Arguments:: Specifying numeric arguments, repeat counts. | |
914 | * Commands For Completion:: Getting Readline to do the typing for you. | |
915 | * Keyboard Macros:: Saving and re-executing typed characters | |
916 | * Miscellaneous Commands:: Other miscellaneous commands. | |
917 | @end menu | |
918 | ||
919 | This section describes Readline commands that may be bound to key | |
920 | sequences. | |
921 | @ifset BashFeatures | |
922 | You can list your key bindings by executing | |
923 | @w{@code{bind -P}} or, for a more terse format, suitable for an | |
924 | @var{inputrc} file, @w{@code{bind -p}}. (@xref{Bash Builtins}.) | |
925 | @end ifset | |
926 | Command names without an accompanying key sequence are unbound by default. | |
927 | ||
928 | In the following descriptions, @dfn{point} refers to the current cursor | |
929 | position, and @dfn{mark} refers to a cursor position saved by the | |
930 | @code{set-mark} command. | |
931 | The text between the point and mark is referred to as the @dfn{region}. | |
932 | ||
933 | @node Commands For Moving | |
934 | @subsection Commands For Moving | |
935 | @ftable @code | |
936 | @item beginning-of-line (C-a) | |
937 | Move to the start of the current line. | |
938 | ||
939 | @item end-of-line (C-e) | |
940 | Move to the end of the line. | |
941 | ||
942 | @item forward-char (C-f) | |
943 | Move forward a character. | |
944 | ||
945 | @item backward-char (C-b) | |
946 | Move back a character. | |
947 | ||
948 | @item forward-word (M-f) | |
949 | Move forward to the end of the next word. Words are composed of | |
950 | letters and digits. | |
951 | ||
952 | @item backward-word (M-b) | |
953 | Move back to the start of the current or previous word. Words are | |
954 | composed of letters and digits. | |
955 | ||
956 | @item clear-screen (C-l) | |
957 | Clear the screen and redraw the current line, | |
958 | leaving the current line at the top of the screen. | |
959 | ||
960 | @item redraw-current-line () | |
961 | Refresh the current line. By default, this is unbound. | |
962 | ||
963 | @end ftable | |
964 | ||
965 | @node Commands For History | |
966 | @subsection Commands For Manipulating The History | |
967 | ||
968 | @ftable @code | |
969 | @item accept-line (Newline or Return) | |
970 | @ifset BashFeatures | |
971 | Accept the line regardless of where the cursor is. | |
972 | If this line is | |
973 | non-empty, add it to the history list according to the setting of | |
974 | the @env{HISTCONTROL} and @env{HISTIGNORE} variables. | |
975 | If this line is a modified history line, then restore the history line | |
976 | to its original state. | |
977 | @end ifset | |
978 | @ifclear BashFeatures | |
979 | Accept the line regardless of where the cursor is. | |
980 | If this line is | |
981 | non-empty, it may be added to the history list for future recall with | |
982 | @code{add_history()}. | |
983 | If this line is a modified history line, the history line is restored | |
984 | to its original state. | |
985 | @end ifclear | |
986 | ||
987 | @item previous-history (C-p) | |
988 | Move `back' through the history list, fetching the previous command. | |
989 | ||
990 | @item next-history (C-n) | |
991 | Move `forward' through the history list, fetching the next command. | |
992 | ||
993 | @item beginning-of-history (M-<) | |
994 | Move to the first line in the history. | |
995 | ||
996 | @item end-of-history (M->) | |
997 | Move to the end of the input history, i.e., the line currently | |
998 | being entered. | |
999 | ||
1000 | @item reverse-search-history (C-r) | |
1001 | Search backward starting at the current line and moving `up' through | |
1002 | the history as necessary. This is an incremental search. | |
1003 | ||
1004 | @item forward-search-history (C-s) | |
1005 | Search forward starting at the current line and moving `down' through | |
1006 | the the history as necessary. This is an incremental search. | |
1007 | ||
1008 | @item non-incremental-reverse-search-history (M-p) | |
1009 | Search backward starting at the current line and moving `up' | |
1010 | through the history as necessary using a non-incremental search | |
1011 | for a string supplied by the user. | |
1012 | ||
1013 | @item non-incremental-forward-search-history (M-n) | |
1014 | Search forward starting at the current line and moving `down' | |
1015 | through the the history as necessary using a non-incremental search | |
1016 | for a string supplied by the user. | |
1017 | ||
1018 | @item history-search-forward () | |
1019 | Search forward through the history for the string of characters | |
1020 | between the start of the current line and the point. | |
1021 | This is a non-incremental search. | |
1022 | By default, this command is unbound. | |
1023 | ||
1024 | @item history-search-backward () | |
1025 | Search backward through the history for the string of characters | |
1026 | between the start of the current line and the point. This | |
1027 | is a non-incremental search. By default, this command is unbound. | |
1028 | ||
1029 | @item yank-nth-arg (M-C-y) | |
1030 | Insert the first argument to the previous command (usually | |
1031 | the second word on the previous line) at point. | |
1032 | With an argument @var{n}, | |
1033 | insert the @var{n}th word from the previous command (the words | |
1034 | in the previous command begin with word 0). A negative argument | |
1035 | inserts the @var{n}th word from the end of the previous command. | |
eb2bb562 CR |
1036 | Once the argument @var{n} is computed, the argument is extracted |
1037 | as if the @samp{!@var{n}} history expansion had been specified. | |
d3a24ed2 CR |
1038 | |
1039 | @item yank-last-arg (M-. or M-_) | |
1040 | Insert last argument to the previous command (the last word of the | |
1041 | previous history entry). With an | |
1042 | argument, behave exactly like @code{yank-nth-arg}. | |
1043 | Successive calls to @code{yank-last-arg} move back through the history | |
1044 | list, inserting the last argument of each line in turn. | |
eb2bb562 CR |
1045 | The history expansion facilities are used to extract the last argument, |
1046 | as if the @samp{!$} history expansion had been specified. | |
d3a24ed2 CR |
1047 | |
1048 | @end ftable | |
1049 | ||
1050 | @node Commands For Text | |
1051 | @subsection Commands For Changing Text | |
1052 | ||
1053 | @ftable @code | |
1054 | @item delete-char (C-d) | |
1055 | Delete the character at point. If point is at the | |
1056 | beginning of the line, there are no characters in the line, and | |
1057 | the last character typed was not bound to @code{delete-char}, then | |
1058 | return @sc{eof}. | |
1059 | ||
1060 | @item backward-delete-char (Rubout) | |
1061 | Delete the character behind the cursor. A numeric argument means | |
1062 | to kill the characters instead of deleting them. | |
1063 | ||
1064 | @item forward-backward-delete-char () | |
1065 | Delete the character under the cursor, unless the cursor is at the | |
1066 | end of the line, in which case the character behind the cursor is | |
1067 | deleted. By default, this is not bound to a key. | |
1068 | ||
1069 | @item quoted-insert (C-q or C-v) | |
1070 | Add the next character typed to the line verbatim. This is | |
1071 | how to insert key sequences like @kbd{C-q}, for example. | |
1072 | ||
1073 | @ifclear BashFeatures | |
1074 | @item tab-insert (M-@key{TAB}) | |
1075 | Insert a tab character. | |
1076 | @end ifclear | |
1077 | ||
1078 | @item self-insert (a, b, A, 1, !, @dots{}) | |
1079 | Insert yourself. | |
1080 | ||
1081 | @item transpose-chars (C-t) | |
1082 | Drag the character before the cursor forward over | |
1083 | the character at the cursor, moving the | |
1084 | cursor forward as well. If the insertion point | |
1085 | is at the end of the line, then this | |
1086 | transposes the last two characters of the line. | |
1087 | Negative arguments have no effect. | |
1088 | ||
1089 | @item transpose-words (M-t) | |
1090 | Drag the word before point past the word after point, | |
1091 | moving point past that word as well. | |
1092 | If the insertion point is at the end of the line, this transposes | |
1093 | the last two words on the line. | |
1094 | ||
1095 | @item upcase-word (M-u) | |
1096 | Uppercase the current (or following) word. With a negative argument, | |
1097 | uppercase the previous word, but do not move the cursor. | |
1098 | ||
1099 | @item downcase-word (M-l) | |
1100 | Lowercase the current (or following) word. With a negative argument, | |
1101 | lowercase the previous word, but do not move the cursor. | |
1102 | ||
1103 | @item capitalize-word (M-c) | |
1104 | Capitalize the current (or following) word. With a negative argument, | |
1105 | capitalize the previous word, but do not move the cursor. | |
1106 | ||
1107 | @item overwrite-mode () | |
1108 | Toggle overwrite mode. With an explicit positive numeric argument, | |
1109 | switches to overwrite mode. With an explicit non-positive numeric | |
1110 | argument, switches to insert mode. This command affects only | |
1111 | @code{emacs} mode; @code{vi} mode does overwrite differently. | |
1112 | Each call to @code{readline()} starts in insert mode. | |
1113 | ||
1114 | In overwrite mode, characters bound to @code{self-insert} replace | |
1115 | the text at point rather than pushing the text to the right. | |
1116 | Characters bound to @code{backward-delete-char} replace the character | |
1117 | before point with a space. | |
1118 | ||
1119 | By default, this command is unbound. | |
1120 | ||
1121 | @end ftable | |
1122 | ||
1123 | @node Commands For Killing | |
1124 | @subsection Killing And Yanking | |
1125 | ||
1126 | @ftable @code | |
1127 | ||
1128 | @item kill-line (C-k) | |
1129 | Kill the text from point to the end of the line. | |
1130 | ||
1131 | @item backward-kill-line (C-x Rubout) | |
1132 | Kill backward to the beginning of the line. | |
1133 | ||
1134 | @item unix-line-discard (C-u) | |
1135 | Kill backward from the cursor to the beginning of the current line. | |
1136 | ||
1137 | @item kill-whole-line () | |
1138 | Kill all characters on the current line, no matter where point is. | |
1139 | By default, this is unbound. | |
1140 | ||
1141 | @item kill-word (M-d) | |
1142 | Kill from point to the end of the current word, or if between | |
1143 | words, to the end of the next word. | |
1144 | Word boundaries are the same as @code{forward-word}. | |
1145 | ||
1146 | @item backward-kill-word (M-@key{DEL}) | |
1147 | Kill the word behind point. | |
1148 | Word boundaries are the same as @code{backward-word}. | |
1149 | ||
1150 | @item unix-word-rubout (C-w) | |
1151 | Kill the word behind point, using white space as a word boundary. | |
1152 | The killed text is saved on the kill-ring. | |
1153 | ||
113d85a4 CR |
1154 | @item unix-filename-rubout () |
1155 | Kill the word behind point, using white space and the slash character | |
1156 | as the word boundaries. | |
1157 | The killed text is saved on the kill-ring. | |
1158 | ||
d3a24ed2 CR |
1159 | @item delete-horizontal-space () |
1160 | Delete all spaces and tabs around point. By default, this is unbound. | |
1161 | ||
1162 | @item kill-region () | |
1163 | Kill the text in the current region. | |
1164 | By default, this command is unbound. | |
1165 | ||
1166 | @item copy-region-as-kill () | |
1167 | Copy the text in the region to the kill buffer, so it can be yanked | |
1168 | right away. By default, this command is unbound. | |
1169 | ||
1170 | @item copy-backward-word () | |
1171 | Copy the word before point to the kill buffer. | |
1172 | The word boundaries are the same as @code{backward-word}. | |
1173 | By default, this command is unbound. | |
1174 | ||
1175 | @item copy-forward-word () | |
1176 | Copy the word following point to the kill buffer. | |
1177 | The word boundaries are the same as @code{forward-word}. | |
1178 | By default, this command is unbound. | |
1179 | ||
1180 | @item yank (C-y) | |
1181 | Yank the top of the kill ring into the buffer at point. | |
1182 | ||
1183 | @item yank-pop (M-y) | |
1184 | Rotate the kill-ring, and yank the new top. You can only do this if | |
1185 | the prior command is @code{yank} or @code{yank-pop}. | |
1186 | @end ftable | |
1187 | ||
1188 | @node Numeric Arguments | |
1189 | @subsection Specifying Numeric Arguments | |
1190 | @ftable @code | |
1191 | ||
1192 | @item digit-argument (@kbd{M-0}, @kbd{M-1}, @dots{} @kbd{M--}) | |
1193 | Add this digit to the argument already accumulating, or start a new | |
1194 | argument. @kbd{M--} starts a negative argument. | |
1195 | ||
1196 | @item universal-argument () | |
1197 | This is another way to specify an argument. | |
1198 | If this command is followed by one or more digits, optionally with a | |
1199 | leading minus sign, those digits define the argument. | |
1200 | If the command is followed by digits, executing @code{universal-argument} | |
1201 | again ends the numeric argument, but is otherwise ignored. | |
1202 | As a special case, if this command is immediately followed by a | |
1203 | character that is neither a digit or minus sign, the argument count | |
1204 | for the next command is multiplied by four. | |
1205 | The argument count is initially one, so executing this function the | |
1206 | first time makes the argument count four, a second time makes the | |
1207 | argument count sixteen, and so on. | |
1208 | By default, this is not bound to a key. | |
1209 | @end ftable | |
1210 | ||
1211 | @node Commands For Completion | |
1212 | @subsection Letting Readline Type For You | |
1213 | ||
1214 | @ftable @code | |
1215 | @item complete (@key{TAB}) | |
1216 | Attempt to perform completion on the text before point. | |
1217 | The actual completion performed is application-specific. | |
1218 | @ifset BashFeatures | |
1219 | Bash attempts completion treating the text as a variable (if the | |
1220 | text begins with @samp{$}), username (if the text begins with | |
1221 | @samp{~}), hostname (if the text begins with @samp{@@}), or | |
1222 | command (including aliases and functions) in turn. If none | |
1223 | of these produces a match, filename completion is attempted. | |
1224 | @end ifset | |
1225 | @ifclear BashFeatures | |
1226 | The default is filename completion. | |
1227 | @end ifclear | |
1228 | ||
1229 | @item possible-completions (M-?) | |
1230 | List the possible completions of the text before point. | |
1231 | ||
1232 | @item insert-completions (M-*) | |
1233 | Insert all completions of the text before point that would have | |
1234 | been generated by @code{possible-completions}. | |
1235 | ||
1236 | @item menu-complete () | |
1237 | Similar to @code{complete}, but replaces the word to be completed | |
1238 | with a single match from the list of possible completions. | |
1239 | Repeated execution of @code{menu-complete} steps through the list | |
1240 | of possible completions, inserting each match in turn. | |
1241 | At the end of the list of completions, the bell is rung | |
1242 | (subject to the setting of @code{bell-style}) | |
1243 | and the original text is restored. | |
1244 | An argument of @var{n} moves @var{n} positions forward in the list | |
1245 | of matches; a negative argument may be used to move backward | |
1246 | through the list. | |
1247 | This command is intended to be bound to @key{TAB}, but is unbound | |
1248 | by default. | |
1249 | ||
1250 | @item delete-char-or-list () | |
1251 | Deletes the character under the cursor if not at the beginning or | |
1252 | end of the line (like @code{delete-char}). | |
1253 | If at the end of the line, behaves identically to | |
1254 | @code{possible-completions}. | |
1255 | This command is unbound by default. | |
1256 | ||
1257 | @ifset BashFeatures | |
1258 | @item complete-filename (M-/) | |
1259 | Attempt filename completion on the text before point. | |
1260 | ||
1261 | @item possible-filename-completions (C-x /) | |
1262 | List the possible completions of the text before point, | |
1263 | treating it as a filename. | |
1264 | ||
1265 | @item complete-username (M-~) | |
1266 | Attempt completion on the text before point, treating | |
1267 | it as a username. | |
1268 | ||
1269 | @item possible-username-completions (C-x ~) | |
1270 | List the possible completions of the text before point, | |
1271 | treating it as a username. | |
1272 | ||
1273 | @item complete-variable (M-$) | |
1274 | Attempt completion on the text before point, treating | |
1275 | it as a shell variable. | |
1276 | ||
1277 | @item possible-variable-completions (C-x $) | |
1278 | List the possible completions of the text before point, | |
1279 | treating it as a shell variable. | |
1280 | ||
1281 | @item complete-hostname (M-@@) | |
1282 | Attempt completion on the text before point, treating | |
1283 | it as a hostname. | |
1284 | ||
1285 | @item possible-hostname-completions (C-x @@) | |
1286 | List the possible completions of the text before point, | |
1287 | treating it as a hostname. | |
1288 | ||
1289 | @item complete-command (M-!) | |
1290 | Attempt completion on the text before point, treating | |
1291 | it as a command name. Command completion attempts to | |
1292 | match the text against aliases, reserved words, shell | |
1293 | functions, shell builtins, and finally executable filenames, | |
1294 | in that order. | |
1295 | ||
1296 | @item possible-command-completions (C-x !) | |
1297 | List the possible completions of the text before point, | |
1298 | treating it as a command name. | |
1299 | ||
1300 | @item dynamic-complete-history (M-@key{TAB}) | |
1301 | Attempt completion on the text before point, comparing | |
1302 | the text against lines from the history list for possible | |
1303 | completion matches. | |
1304 | ||
1305 | @item complete-into-braces (M-@{) | |
1306 | Perform filename completion and insert the list of possible completions | |
1307 | enclosed within braces so the list is available to the shell | |
1308 | (@pxref{Brace Expansion}). | |
1309 | ||
1310 | @end ifset | |
1311 | @end ftable | |
1312 | ||
1313 | @node Keyboard Macros | |
1314 | @subsection Keyboard Macros | |
1315 | @ftable @code | |
1316 | ||
1317 | @item start-kbd-macro (C-x () | |
1318 | Begin saving the characters typed into the current keyboard macro. | |
1319 | ||
1320 | @item end-kbd-macro (C-x )) | |
1321 | Stop saving the characters typed into the current keyboard macro | |
1322 | and save the definition. | |
1323 | ||
1324 | @item call-last-kbd-macro (C-x e) | |
1325 | Re-execute the last keyboard macro defined, by making the characters | |
1326 | in the macro appear as if typed at the keyboard. | |
1327 | ||
1328 | @end ftable | |
1329 | ||
1330 | @node Miscellaneous Commands | |
1331 | @subsection Some Miscellaneous Commands | |
1332 | @ftable @code | |
1333 | ||
1334 | @item re-read-init-file (C-x C-r) | |
1335 | Read in the contents of the @var{inputrc} file, and incorporate | |
1336 | any bindings or variable assignments found there. | |
1337 | ||
1338 | @item abort (C-g) | |
1339 | Abort the current editing command and | |
1340 | ring the terminal's bell (subject to the setting of | |
1341 | @code{bell-style}). | |
1342 | ||
1343 | @item do-uppercase-version (M-a, M-b, M-@var{x}, @dots{}) | |
1344 | If the metafied character @var{x} is lowercase, run the command | |
1345 | that is bound to the corresponding uppercase character. | |
1346 | ||
1347 | @item prefix-meta (@key{ESC}) | |
1348 | Metafy the next character typed. This is for keyboards | |
1349 | without a meta key. Typing @samp{@key{ESC} f} is equivalent to typing | |
1350 | @kbd{M-f}. | |
1351 | ||
1352 | @item undo (C-_ or C-x C-u) | |
1353 | Incremental undo, separately remembered for each line. | |
1354 | ||
1355 | @item revert-line (M-r) | |
1356 | Undo all changes made to this line. This is like executing the @code{undo} | |
1357 | command enough times to get back to the beginning. | |
1358 | ||
1359 | @ifset BashFeatures | |
1360 | @item tilde-expand (M-&) | |
1361 | @end ifset | |
1362 | @ifclear BashFeatures | |
1363 | @item tilde-expand (M-~) | |
1364 | @end ifclear | |
1365 | Perform tilde expansion on the current word. | |
1366 | ||
1367 | @item set-mark (C-@@) | |
1368 | Set the mark to the point. If a | |
1369 | numeric argument is supplied, the mark is set to that position. | |
1370 | ||
1371 | @item exchange-point-and-mark (C-x C-x) | |
1372 | Swap the point with the mark. The current cursor position is set to | |
1373 | the saved position, and the old cursor position is saved as the mark. | |
1374 | ||
1375 | @item character-search (C-]) | |
1376 | A character is read and point is moved to the next occurrence of that | |
1377 | character. A negative count searches for previous occurrences. | |
1378 | ||
1379 | @item character-search-backward (M-C-]) | |
1380 | A character is read and point is moved to the previous occurrence | |
1381 | of that character. A negative count searches for subsequent | |
1382 | occurrences. | |
1383 | ||
1384 | @item insert-comment (M-#) | |
1385 | Without a numeric argument, the value of the @code{comment-begin} | |
1386 | variable is inserted at the beginning of the current line. | |
1387 | If a numeric argument is supplied, this command acts as a toggle: if | |
1388 | the characters at the beginning of the line do not match the value | |
1389 | of @code{comment-begin}, the value is inserted, otherwise | |
1390 | the characters in @code{comment-begin} are deleted from the beginning of | |
1391 | the line. | |
1392 | In either case, the line is accepted as if a newline had been typed. | |
1393 | @ifset BashFeatures | |
1394 | The default value of @code{comment-begin} causes this command | |
1395 | to make the current line a shell comment. | |
1396 | If a numeric argument causes the comment character to be removed, the line | |
1397 | will be executed by the shell. | |
1398 | @end ifset | |
1399 | ||
1400 | @item dump-functions () | |
1401 | Print all of the functions and their key bindings to the | |
1402 | Readline output stream. If a numeric argument is supplied, | |
1403 | the output is formatted in such a way that it can be made part | |
1404 | of an @var{inputrc} file. This command is unbound by default. | |
1405 | ||
1406 | @item dump-variables () | |
1407 | Print all of the settable variables and their values to the | |
1408 | Readline output stream. If a numeric argument is supplied, | |
1409 | the output is formatted in such a way that it can be made part | |
1410 | of an @var{inputrc} file. This command is unbound by default. | |
1411 | ||
1412 | @item dump-macros () | |
1413 | Print all of the Readline key sequences bound to macros and the | |
1414 | strings they output. If a numeric argument is supplied, | |
1415 | the output is formatted in such a way that it can be made part | |
1416 | of an @var{inputrc} file. This command is unbound by default. | |
1417 | ||
1418 | @ifset BashFeatures | |
1419 | @item glob-complete-word (M-g) | |
1420 | The word before point is treated as a pattern for pathname expansion, | |
1421 | with an asterisk implicitly appended. This pattern is used to | |
1422 | generate a list of matching file names for possible completions. | |
1423 | ||
1424 | @item glob-expand-word (C-x *) | |
1425 | The word before point is treated as a pattern for pathname expansion, | |
1426 | and the list of matching file names is inserted, replacing the word. | |
1427 | If a numeric argument is supplied, a @samp{*} is appended before | |
1428 | pathname expansion. | |
1429 | ||
1430 | @item glob-list-expansions (C-x g) | |
1431 | The list of expansions that would have been generated by | |
1432 | @code{glob-expand-word} is displayed, and the line is redrawn. | |
1433 | If a numeric argument is supplied, a @samp{*} is appended before | |
1434 | pathname expansion. | |
1435 | ||
1436 | @item display-shell-version (C-x C-v) | |
1437 | Display version information about the current instance of Bash. | |
1438 | ||
1439 | @item shell-expand-line (M-C-e) | |
1440 | Expand the line as the shell does. | |
1441 | This performs alias and history expansion as well as all of the shell | |
1442 | word expansions (@pxref{Shell Expansions}). | |
1443 | ||
1444 | @item history-expand-line (M-^) | |
1445 | Perform history expansion on the current line. | |
1446 | ||
1447 | @item magic-space () | |
1448 | Perform history expansion on the current line and insert a space | |
1449 | (@pxref{History Interaction}). | |
1450 | ||
1451 | @item alias-expand-line () | |
1452 | Perform alias expansion on the current line (@pxref{Aliases}). | |
1453 | ||
1454 | @item history-and-alias-expand-line () | |
1455 | Perform history and alias expansion on the current line. | |
1456 | ||
1457 | @item insert-last-argument (M-. or M-_) | |
1458 | A synonym for @code{yank-last-arg}. | |
1459 | ||
1460 | @item operate-and-get-next (C-o) | |
1461 | Accept the current line for execution and fetch the next line | |
1462 | relative to the current line from the history for editing. Any | |
1463 | argument is ignored. | |
1464 | ||
1465 | @item edit-and-execute-command (C-xC-e) | |
1466 | Invoke an editor on the current command line, and execute the result as shell | |
1467 | commands. | |
1468 | Bash attempts to invoke | |
de8913bd | 1469 | @code{$VISUAL}, @code{$EDITOR}, and @code{emacs} |
d3a24ed2 CR |
1470 | as the editor, in that order. |
1471 | ||
1472 | @end ifset | |
1473 | ||
1474 | @ifclear BashFeatures | |
1475 | @item emacs-editing-mode (C-e) | |
1476 | When in @code{vi} command mode, this causes a switch to @code{emacs} | |
1477 | editing mode. | |
1478 | ||
1479 | @item vi-editing-mode (M-C-j) | |
1480 | When in @code{emacs} editing mode, this causes a switch to @code{vi} | |
1481 | editing mode. | |
1482 | ||
1483 | @end ifclear | |
1484 | ||
1485 | @end ftable | |
1486 | ||
1487 | @node Readline vi Mode | |
1488 | @section Readline vi Mode | |
1489 | ||
1490 | While the Readline library does not have a full set of @code{vi} | |
1491 | editing functions, it does contain enough to allow simple editing | |
1492 | of the line. The Readline @code{vi} mode behaves as specified in | |
1493 | the @sc{posix} 1003.2 standard. | |
1494 | ||
1495 | @ifset BashFeatures | |
1496 | In order to switch interactively between @code{emacs} and @code{vi} | |
1497 | editing modes, use the @samp{set -o emacs} and @samp{set -o vi} | |
1498 | commands (@pxref{The Set Builtin}). | |
1499 | @end ifset | |
1500 | @ifclear BashFeatures | |
1501 | In order to switch interactively between @code{emacs} and @code{vi} | |
1502 | editing modes, use the command @kbd{M-C-j} (bound to emacs-editing-mode | |
1503 | when in @code{vi} mode and to vi-editing-mode in @code{emacs} mode). | |
1504 | @end ifclear | |
1505 | The Readline default is @code{emacs} mode. | |
1506 | ||
1507 | When you enter a line in @code{vi} mode, you are already placed in | |
1508 | `insertion' mode, as if you had typed an @samp{i}. Pressing @key{ESC} | |
1509 | switches you into `command' mode, where you can edit the text of the | |
1510 | line with the standard @code{vi} movement keys, move to previous | |
1511 | history lines with @samp{k} and subsequent lines with @samp{j}, and | |
1512 | so forth. | |
1513 | ||
1514 | @ifset BashFeatures | |
1515 | @node Programmable Completion | |
1516 | @section Programmable Completion | |
1517 | @cindex programmable completion | |
1518 | ||
1519 | When word completion is attempted for an argument to a command for | |
1520 | which a completion specification (a @var{compspec}) has been defined | |
1521 | using the @code{complete} builtin (@pxref{Programmable Completion Builtins}), | |
1522 | the programmable completion facilities are invoked. | |
1523 | ||
1524 | First, the command name is identified. | |
1525 | If a compspec has been defined for that command, the | |
1526 | compspec is used to generate the list of possible completions for the word. | |
1527 | If the command word is a full pathname, a compspec for the full | |
1528 | pathname is searched for first. | |
1529 | If no compspec is found for the full pathname, an attempt is made to | |
1530 | find a compspec for the portion following the final slash. | |
1531 | ||
1532 | Once a compspec has been found, it is used to generate the list of | |
1533 | matching words. | |
1534 | If a compspec is not found, the default Bash completion | |
1535 | described above (@pxref{Commands For Completion}) is performed. | |
1536 | ||
1537 | First, the actions specified by the compspec are used. | |
1538 | Only matches which are prefixed by the word being completed are | |
1539 | returned. | |
1540 | When the @option{-f} or @option{-d} option is used for filename or | |
1541 | directory name completion, the shell variable @env{FIGNORE} is | |
1542 | used to filter the matches. | |
1543 | @xref{Bash Variables}, for a description of @env{FIGNORE}. | |
1544 | ||
1545 | Any completions specified by a filename expansion pattern to the | |
1546 | @option{-G} option are generated next. | |
1547 | The words generated by the pattern need not match the word being completed. | |
1548 | The @env{GLOBIGNORE} shell variable is not used to filter the matches, | |
1549 | but the @env{FIGNORE} shell variable is used. | |
1550 | ||
1551 | Next, the string specified as the argument to the @option{-W} option | |
1552 | is considered. | |
1553 | The string is first split using the characters in the @env{IFS} | |
1554 | special variable as delimiters. | |
1555 | Shell quoting is honored. | |
1556 | Each word is then expanded using | |
1557 | brace expansion, tilde expansion, parameter and variable expansion, | |
6e70dbff | 1558 | command substitution, and arithmetic expansion, |
d3a24ed2 CR |
1559 | as described above (@pxref{Shell Expansions}). |
1560 | The results are split using the rules described above | |
1561 | (@pxref{Word Splitting}). | |
1562 | The results of the expansion are prefix-matched against the word being | |
1563 | completed, and the matching words become the possible completions. | |
1564 | ||
1565 | After these matches have been generated, any shell function or command | |
1566 | specified with the @option{-F} and @option{-C} options is invoked. | |
d3ad40de CR |
1567 | When the command or function is invoked, the @env{COMP_LINE}, |
1568 | @env{COMP_POINT}, @env{COMP_KEY}, and @env{COMP_TYPE} variables are | |
1569 | assigned values as described above (@pxref{Bash Variables}). | |
d3a24ed2 CR |
1570 | If a shell function is being invoked, the @env{COMP_WORDS} and |
1571 | @env{COMP_CWORD} variables are also set. | |
1572 | When the function or command is invoked, the first argument is the | |
1573 | name of the command whose arguments are being completed, the | |
1574 | second argument is the word being completed, and the third argument | |
1575 | is the word preceding the word being completed on the current command line. | |
1576 | No filtering of the generated completions against the word being completed | |
1577 | is performed; the function or command has complete freedom in generating | |
1578 | the matches. | |
1579 | ||
1580 | Any function specified with @option{-F} is invoked first. | |
1581 | The function may use any of the shell facilities, including the | |
6fbe7620 | 1582 | @code{compgen} and @code{compopt} builtins described below |
d3a24ed2 CR |
1583 | (@pxref{Programmable Completion Builtins}), to generate the matches. |
1584 | It must put the possible completions in the @env{COMPREPLY} array | |
1585 | variable. | |
1586 | ||
1587 | Next, any command specified with the @option{-C} option is invoked | |
1588 | in an environment equivalent to command substitution. | |
1589 | It should print a list of completions, one per line, to | |
1590 | the standard output. | |
1591 | Backslash may be used to escape a newline, if necessary. | |
1592 | ||
1593 | After all of the possible completions are generated, any filter | |
1594 | specified with the @option{-X} option is applied to the list. | |
1595 | The filter is a pattern as used for pathname expansion; a @samp{&} | |
1596 | in the pattern is replaced with the text of the word being completed. | |
1597 | A literal @samp{&} may be escaped with a backslash; the backslash | |
1598 | is removed before attempting a match. | |
1599 | Any completion that matches the pattern will be removed from the list. | |
1600 | A leading @samp{!} negates the pattern; in this case any completion | |
1601 | not matching the pattern will be removed. | |
1602 | ||
1603 | Finally, any prefix and suffix specified with the @option{-P} and @option{-S} | |
1604 | options are added to each member of the completion list, and the result is | |
1605 | returned to the Readline completion code as the list of possible | |
1606 | completions. | |
1607 | ||
1608 | If the previously-applied actions do not generate any matches, and the | |
1609 | @option{-o dirnames} option was supplied to @code{complete} when the | |
1610 | compspec was defined, directory name completion is attempted. | |
1611 | ||
1612 | If the @option{-o plusdirs} option was supplied to @code{complete} when | |
1613 | the compspec was defined, directory name completion is attempted and any | |
1614 | matches are added to the results of the other actions. | |
1615 | ||
1616 | By default, if a compspec is found, whatever it generates is returned to | |
1617 | the completion code as the full set of possible completions. | |
1618 | The default Bash completions are not attempted, and the Readline default | |
1619 | of filename completion is disabled. | |
1620 | If the @option{-o bashdefault} option was supplied to @code{complete} when | |
1621 | the compspec was defined, the default Bash completions are attempted | |
1622 | if the compspec generates no matches. | |
1623 | If the @option{-o default} option was supplied to @code{complete} when the | |
1624 | compspec was defined, Readline's default completion will be performed | |
1625 | if the compspec (and, if attempted, the default Bash completions) | |
1626 | generate no matches. | |
1627 | ||
1628 | When a compspec indicates that directory name completion is desired, | |
1629 | the programmable completion functions force Readline to append a slash | |
1630 | to completed names which are symbolic links to directories, subject to | |
1631 | the value of the @var{mark-directories} Readline variable, regardless | |
1632 | of the setting of the @var{mark-symlinked-directories} Readline variable. | |
1633 | ||
1634 | @node Programmable Completion Builtins | |
1635 | @section Programmable Completion Builtins | |
1636 | @cindex completion builtins | |
1637 | ||
1638 | Two builtin commands are available to manipulate the programmable completion | |
1639 | facilities. | |
1640 | ||
1641 | @table @code | |
1642 | @item compgen | |
1643 | @btindex compgen | |
1644 | @example | |
1645 | @code{compgen [@var{option}] [@var{word}]} | |
1646 | @end example | |
1647 | ||
1648 | Generate possible completion matches for @var{word} according to | |
1649 | the @var{option}s, which may be any option accepted by the | |
1650 | @code{complete} | |
1651 | builtin with the exception of @option{-p} and @option{-r}, and write | |
1652 | the matches to the standard output. | |
1653 | When using the @option{-F} or @option{-C} options, the various shell variables | |
1654 | set by the programmable completion facilities, while available, will not | |
1655 | have useful values. | |
1656 | ||
1657 | The matches will be generated in the same way as if the programmable | |
1658 | completion code had generated them directly from a completion specification | |
1659 | with the same flags. | |
1660 | If @var{word} is specified, only those completions matching @var{word} | |
1661 | will be displayed. | |
1662 | ||
1663 | The return value is true unless an invalid option is supplied, or no | |
1664 | matches were generated. | |
1665 | ||
1666 | @item complete | |
1667 | @btindex complete | |
1668 | @example | |
1669 | @code{complete [-abcdefgjksuv] [-o @var{comp-option}] [-A @var{action}] [-G @var{globpat}] [-W @var{wordlist}] | |
d3ad40de CR |
1670 | [-F @var{function}] [-C @var{command}] [-X @var{filterpat}] |
1671 | [-P @var{prefix}] [-S @var{suffix}] @var{name} [@var{name} @dots{}]} | |
d3a24ed2 CR |
1672 | @code{complete -pr [@var{name} @dots{}]} |
1673 | @end example | |
1674 | ||
1675 | Specify how arguments to each @var{name} should be completed. | |
1676 | If the @option{-p} option is supplied, or if no options are supplied, existing | |
1677 | completion specifications are printed in a way that allows them to be | |
1678 | reused as input. | |
1679 | The @option{-r} option removes a completion specification for | |
1680 | each @var{name}, or, if no @var{name}s are supplied, all | |
1681 | completion specifications. | |
1682 | ||
1683 | The process of applying these completion specifications when word completion | |
1684 | is attempted is described above (@pxref{Programmable Completion}). | |
1685 | ||
1686 | Other options, if specified, have the following meanings. | |
1687 | The arguments to the @option{-G}, @option{-W}, and @option{-X} options | |
1688 | (and, if necessary, the @option{-P} and @option{-S} options) | |
1689 | should be quoted to protect them from expansion before the | |
1690 | @code{complete} builtin is invoked. | |
1691 | ||
1692 | ||
1693 | @table @code | |
1694 | @item -o @var{comp-option} | |
1695 | The @var{comp-option} controls several aspects of the compspec's behavior | |
1696 | beyond the simple generation of completions. | |
1697 | @var{comp-option} may be one of: | |
1698 | ||
1699 | @table @code | |
1700 | ||
1701 | @item bashdefault | |
1702 | Perform the rest of the default Bash completions if the compspec | |
1703 | generates no matches. | |
1704 | ||
1705 | @item default | |
1706 | Use Readline's default filename completion if the compspec generates | |
1707 | no matches. | |
1708 | ||
1709 | @item dirnames | |
1710 | Perform directory name completion if the compspec generates no matches. | |
1711 | ||
1712 | @item filenames | |
1713 | Tell Readline that the compspec generates filenames, so it can perform any | |
1714 | filename-specific processing (like adding a slash to directory names or | |
1715 | suppressing trailing spaces). This option is intended to be used with | |
1716 | shell functions specified with @option{-F}. | |
1717 | ||
1718 | @item nospace | |
1719 | Tell Readline not to append a space (the default) to words completed at | |
1720 | the end of the line. | |
301e2142 CR |
1721 | |
1722 | @item plusdirs | |
1723 | After any matches defined by the compspec are generated, | |
1724 | directory name completion is attempted and any | |
1725 | matches are added to the results of the other actions. | |
1726 | ||
d3a24ed2 CR |
1727 | @end table |
1728 | ||
1729 | @item -A @var{action} | |
1730 | The @var{action} may be one of the following to generate a list of possible | |
1731 | completions: | |
1732 | ||
1733 | @table @code | |
1734 | @item alias | |
1735 | Alias names. May also be specified as @option{-a}. | |
1736 | ||
1737 | @item arrayvar | |
1738 | Array variable names. | |
1739 | ||
1740 | @item binding | |
1741 | Readline key binding names (@pxref{Bindable Readline Commands}). | |
1742 | ||
1743 | @item builtin | |
1744 | Names of shell builtin commands. May also be specified as @option{-b}. | |
1745 | ||
1746 | @item command | |
1747 | Command names. May also be specified as @option{-c}. | |
1748 | ||
1749 | @item directory | |
1750 | Directory names. May also be specified as @option{-d}. | |
1751 | ||
1752 | @item disabled | |
1753 | Names of disabled shell builtins. | |
1754 | ||
1755 | @item enabled | |
1756 | Names of enabled shell builtins. | |
1757 | ||
1758 | @item export | |
1759 | Names of exported shell variables. May also be specified as @option{-e}. | |
1760 | ||
1761 | @item file | |
1762 | File names. May also be specified as @option{-f}. | |
1763 | ||
1764 | @item function | |
1765 | Names of shell functions. | |
1766 | ||
1767 | @item group | |
1768 | Group names. May also be specified as @option{-g}. | |
1769 | ||
1770 | @item helptopic | |
1771 | Help topics as accepted by the @code{help} builtin (@pxref{Bash Builtins}). | |
1772 | ||
1773 | @item hostname | |
1774 | Hostnames, as taken from the file specified by the | |
1775 | @env{HOSTFILE} shell variable (@pxref{Bash Variables}). | |
1776 | ||
1777 | @item job | |
1778 | Job names, if job control is active. May also be specified as @option{-j}. | |
1779 | ||
1780 | @item keyword | |
1781 | Shell reserved words. May also be specified as @option{-k}. | |
1782 | ||
1783 | @item running | |
1784 | Names of running jobs, if job control is active. | |
1785 | ||
1786 | @item service | |
1787 | Service names. May also be specified as @option{-s}. | |
1788 | ||
1789 | @item setopt | |
1790 | Valid arguments for the @option{-o} option to the @code{set} builtin | |
1791 | (@pxref{The Set Builtin}). | |
1792 | ||
1793 | @item shopt | |
1794 | Shell option names as accepted by the @code{shopt} builtin | |
1795 | (@pxref{Bash Builtins}). | |
1796 | ||
1797 | @item signal | |
1798 | Signal names. | |
1799 | ||
1800 | @item stopped | |
1801 | Names of stopped jobs, if job control is active. | |
1802 | ||
1803 | @item user | |
1804 | User names. May also be specified as @option{-u}. | |
1805 | ||
1806 | @item variable | |
1807 | Names of all shell variables. May also be specified as @option{-v}. | |
1808 | @end table | |
1809 | ||
1810 | @item -G @var{globpat} | |
1811 | The filename expansion pattern @var{globpat} is expanded to generate | |
1812 | the possible completions. | |
1813 | ||
1814 | @item -W @var{wordlist} | |
1815 | The @var{wordlist} is split using the characters in the | |
1816 | @env{IFS} special variable as delimiters, and each resultant word | |
1817 | is expanded. | |
1818 | The possible completions are the members of the resultant list which | |
1819 | match the word being completed. | |
1820 | ||
1821 | @item -C @var{command} | |
1822 | @var{command} is executed in a subshell environment, and its output is | |
1823 | used as the possible completions. | |
1824 | ||
1825 | @item -F @var{function} | |
1826 | The shell function @var{function} is executed in the current shell | |
1827 | environment. | |
1828 | When it finishes, the possible completions are retrieved from the value | |
1829 | of the @env{COMPREPLY} array variable. | |
1830 | ||
1831 | @item -X @var{filterpat} | |
1832 | @var{filterpat} is a pattern as used for filename expansion. | |
1833 | It is applied to the list of possible completions generated by the | |
1834 | preceding options and arguments, and each completion matching | |
1835 | @var{filterpat} is removed from the list. | |
1836 | A leading @samp{!} in @var{filterpat} negates the pattern; in this | |
1837 | case, any completion not matching @var{filterpat} is removed. | |
1838 | ||
1839 | @item -P @var{prefix} | |
1840 | @var{prefix} is added at the beginning of each possible completion | |
1841 | after all other options have been applied. | |
1842 | ||
1843 | @item -S @var{suffix} | |
1844 | @var{suffix} is appended to each possible completion | |
1845 | after all other options have been applied. | |
1846 | @end table | |
1847 | ||
1848 | The return value is true unless an invalid option is supplied, an option | |
1849 | other than @option{-p} or @option{-r} is supplied without a @var{name} | |
1850 | argument, an attempt is made to remove a completion specification for | |
1851 | a @var{name} for which no specification exists, or | |
1852 | an error occurs adding a completion specification. | |
1853 | ||
1854 | @end table | |
6fbe7620 CR |
1855 | |
1856 | @item compopt | |
1857 | @btindex compopt | |
1858 | @example | |
1859 | @code{compopt} [-o @var{option}] [+o @var{option}] [@var{name}] | |
1860 | @end example | |
1861 | Modify completion options for each @var{name} according to the | |
1862 | @var{option}s, or for the currently-execution completion if no @var{name}s | |
1863 | are supplied. | |
1864 | If no @var{option}s are given, display the completion options for each | |
1865 | @var{name} or the current completion. | |
1866 | The possible values of @var{option} are those valid for the @code{complete} | |
1867 | builtin described above. | |
1868 | ||
1869 | The return value is true unless an invalid option is supplied, an attempt | |
1870 | is made to modify the options for a @var{name} for which no completion | |
1871 | specification exists, or an output error occurs. | |
1872 | ||
d3a24ed2 | 1873 | @end ifset |