OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.3/] [readline/] [doc/] [rluser.texinfo] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.