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