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" 10which contains both end-user and programmer documentation for the 11GNU Readline Library. 12 13Copyright (C) 1988-1999 Free Software Foundation, Inc. 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 39@ifclear BashFeatures 40@defcodeindex bt 41@end ifclear 42 43@node Command Line Editing 44@chapter Command Line Editing 45 46This chapter describes the basic features of the @sc{gnu} 47command line editing interface. 48@ifset BashFeatures 49Command line editing is provided by the Readline library, which is 50used 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 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 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}. 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}). 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. 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. 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 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 141Sometimes you may mistype a character, and 142not notice the error until you have typed several other characters. In 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 151blank space created by the removal of the text. A list of the bare 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. 159@item @key{DEL} or @key{Backspace} 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. 165@item @key{C-_} or @key{C-x C-u} 166Undo the last editing command. You can undo all the way back to an 167empty line. 168@end table 169 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 176@node Readline Movement Commands 177@subsection Readline Movement Commands 178 179 180The above table describes the most basic keystrokes that you need 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. 212(`Cut' and `paste' are more recent jargon for `kill' and `yank'.) 213 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 233Kill from the cursor to the end of the current word, or, if between 234words, to the end of the next word. 235Word boundaries are the same as those used by @key{M-f}. 236 237@item M-DEL 238Kill from the cursor the start of the previous word, or, if between 239words, to the start of the previous word. 240Word boundaries are the same as those used by @key{M-b}. 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 272sign (@samp{-}), then the sign of the argument will be negative. Once 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. 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 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. 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. 302 303To find other matching entries in the history list, type @key{C-r} or 304@key{C-s} as appropriate. 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 320Although the Readline library comes with a set of Emacs-like 321keybindings installed by default, it is possible to use a different set 322of keybindings. 323Any user can customize programs that use Readline by putting 324commands in an @dfn{inputrc} file, conventionally in his home directory. 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 370@ifset BashFeatures 371The @w{@code{bind -V}} command lists the current Readline variable names 372and values. @xref{Bash Builtins}. 373@end ifset 374 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 412bit and prefixing an @key{ESC} character, converting them to a 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 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 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 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 518simple. First you need to find the name of the command that you 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 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 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 552the key sequence in double quotes. Some @sc{gnu} Emacs style key 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 570The following @sc{gnu} Emacs style escape sequences are available when 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{\"} 583@key{"}, a double quotation mark 584@item @kbd{\'} 585@key{'}, a single quote or apostrophe 586@end table 587 588In addition to the @sc{gnu} Emacs style escape sequences, a second 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} 609the character whose @code{ASCII} code is the octal value @var{nnn} 610(one to three digits) 611@item \x@var{nnn} 612the character whose @code{ASCII} code is the hexadecimal value @var{nnn} 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" 762# prepare to type a quoted word -- insert open and close double quotes 763# and move to just after the open quote 764"\C-x\"": "\"\"\C-b" 765# insert a backslash (testing backslash escapes in sequences and macros) 766"\C-x\\": "\\" 767# Quote the current or previous word 768"\C-xq": "\eb\"\ef\"" 769# Add a binding to refresh the line, which is unbound 770"\C-xr": redraw-current-line 771# Edit variable on current line. 772"\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y=" 773$endif 774 775# use a visible bell if one is available 776set bell-style visible 777 778# don't strip characters to 7 bits when reading 779set input-meta on 780 781# allow iso-latin1 characters to be inserted rather than converted to 782# prefix-meta sequences 783set convert-meta off 784 785# display characters with the eighth bit set directly rather than 786# as meta-prefixed characters 787set output-meta on 788 789# if there are more than 150 possible completions for a word, ask the 790# user if he wants to see all of them 791set completion-query-items 150 792 793# For FTP 794$if Ftp 795"\C-xg": "get \M-?" 796"\C-xt": "put \M-?" 797"\M-.": yank-last-arg 798$endif 799@end example 800 801@node Bindable Readline Commands 802@section Bindable Readline Commands 803 804@menu 805* Commands For Moving:: Moving about the line. 806* Commands For History:: Getting at previous lines. 807* Commands For Text:: Commands for changing text. 808* Commands For Killing:: Commands for killing and yanking. 809* Numeric Arguments:: Specifying numeric arguments, repeat counts. 810* Commands For Completion:: Getting Readline to do the typing for you. 811* Keyboard Macros:: Saving and re-executing typed characters 812* Miscellaneous Commands:: Other miscellaneous commands. 813@end menu 814 815This section describes Readline commands that may be bound to key 816sequences. 817@ifset BashFeatures 818You can list your key bindings by executing 819@w{@code{bind -P}} or, for a more terse format, suitable for an 820@var{inputrc} file, @w{@code{bind -p}}. (@xref{Bash Builtins}.) 821@end ifset 822 823Command names without an accompanying key sequence are unbound by default. 824In the following descriptions, @var{point} refers to the current cursor 825position, and @var{mark} refers to a cursor position saved by the 826@code{set-mark} command. 827The text between the point and mark is referred to as the @var{region}. 828 829@node Commands For Moving 830@subsection Commands For Moving 831@ftable @code 832@item beginning-of-line (C-a) 833Move to the start of the current line. 834 835@item end-of-line (C-e) 836Move to the end of the line. 837 838@item forward-char (C-f) 839Move forward a character. 840 841@item backward-char (C-b) 842Move back a character. 843 844@item forward-word (M-f) 845Move forward to the end of the next word. Words are composed of 846letters and digits. 847 848@item backward-word (M-b) 849Move back to the start of the current or previous word. Words are 850composed of letters and digits. 851 852@item clear-screen (C-l) 853Clear the screen and redraw the current line, 854leaving the current line at the top of the screen. 855 856@item redraw-current-line () 857Refresh the current line. By default, this is unbound. 858 859@end ftable 860 861@node Commands For History 862@subsection Commands For Manipulating The History 863 864@ftable @code 865@item accept-line (Newline, Return) 866@ifset BashFeatures 867Accept the line regardless of where the cursor is. If this line is 868non-empty, add it to the history list according to the setting of 869the @code{HISTCONTROL} and @code{HISTIGNORE} variables. 870If this line was a history line, then restore the history line to its 871original state. 872@end ifset 873@ifclear BashFeatures 874Accept the line regardless of where the cursor is. If this line is 875non-empty, add it to the history list. If this line was a history 876line, then restore the history line to its original state. 877@end ifclear 878 879@item previous-history (C-p) 880Move `up' through the history list. 881 882@item next-history (C-n) 883Move `down' through the history list. 884 885@item beginning-of-history (M-<) 886Move to the first line in the history. 887 888@item end-of-history (M->) 889Move to the end of the input history, i.e., the line currently 890being entered. 891 892@item reverse-search-history (C-r) 893Search backward starting at the current line and moving `up' through 894the history as necessary. This is an incremental search. 895 896@item forward-search-history (C-s) 897Search forward starting at the current line and moving `down' through 898the the history as necessary. This is an incremental search. 899 900@item non-incremental-reverse-search-history (M-p) 901Search backward starting at the current line and moving `up' 902through the history as necessary using a non-incremental search 903for a string supplied by the user. 904 905@item non-incremental-forward-search-history (M-n) 906Search forward starting at the current line and moving `down' 907through the the history as necessary using a non-incremental search 908for a string supplied by the user. 909 910@item history-search-forward () 911Search forward through the history for the string of characters 912between the start of the current line and the point. 913This is a non-incremental search. 914By default, this command is unbound. 915 916@item history-search-backward () 917Search backward through the history for the string of characters 918between the start of the current line and the point. This 919is a non-incremental search. By default, this command is unbound. 920 921@item yank-nth-arg (M-C-y) 922Insert the first argument to the previous command (usually 923the second word on the previous line). With an argument @var{n}, 924insert the @var{n}th word from the previous command (the words 925in the previous command begin with word 0). A negative argument 926inserts the @var{n}th word from the end of the previous command. 927 928@item yank-last-arg (M-., M-_) 929Insert last argument to the previous command (the last word of the 930previous history entry). With an 931argument, behave exactly like @code{yank-nth-arg}. 932Successive calls to @code{yank-last-arg} move back through the history 933list, inserting the last argument of each line in turn. 934 935@end ftable 936 937@node Commands For Text 938@subsection Commands For Changing Text 939 940@ftable @code 941@item delete-char (C-d) 942Delete the character under the cursor. If the cursor is at the 943beginning of the line, there are no characters in the line, and 944the last character typed was not bound to @code{delete-char}, then 945return @code{EOF}. 946 947@item backward-delete-char (Rubout) 948Delete the character behind the cursor. A numeric argument means 949to kill the characters instead of deleting them. 950 951@item forward-backward-delete-char () 952Delete the character under the cursor, unless the cursor is at the 953end of the line, in which case the character behind the cursor is 954deleted. By default, this is not bound to a key. 955 956@item quoted-insert (C-q, C-v) 957Add the next character typed to the line verbatim. This is 958how to insert key sequences like @key{C-q}, for example. 959 960@ifclear BashFeatures 961@item tab-insert (M-TAB) 962Insert a tab character. 963@end ifclear 964 965@item self-insert (a, b, A, 1, !, ...) 966Insert yourself. 967 968@item transpose-chars (C-t) 969Drag the character before the cursor forward over 970the character at the cursor, moving the 971cursor forward as well. If the insertion point 972is at the end of the line, then this 973transposes the last two characters of the line. 974Negative arguments have no effect. 975 976@item transpose-words (M-t) 977Drag the word before point past the word after point, 978moving point past that word as well. 979 980@item upcase-word (M-u) 981Uppercase the current (or following) word. With a negative argument, 982uppercase the previous word, but do not move the cursor. 983 984@item downcase-word (M-l) 985Lowercase the current (or following) word. With a negative argument, 986lowercase the previous word, but do not move the cursor. 987 988@item capitalize-word (M-c) 989Capitalize the current (or following) word. With a negative argument, 990capitalize the previous word, but do not move the cursor. 991 992@end ftable 993 994@node Commands For Killing 995@subsection Killing And Yanking 996 997@ftable @code 998 999@item kill-line (C-k) 1000Kill the text from point to the end of the line. 1001 1002@item backward-kill-line (C-x Rubout) 1003Kill backward to the beginning of the line. 1004 1005@item unix-line-discard (C-u) 1006Kill backward from the cursor to the beginning of the current line. 1007 1008@item kill-whole-line () 1009Kill all characters on the current line, no matter point is. 1010By default, this is unbound. 1011 1012@item kill-word (M-d) 1013Kill from point to the end of the current word, or if between 1014words, to the end of the next word. 1015Word boundaries are the same as @code{forward-word}. 1016 1017@item backward-kill-word (M-DEL) 1018Kill the word behind point. 1019Word boundaries are the same as @code{backward-word}. 1020 1021@item unix-word-rubout (C-w) 1022Kill the word behind point, using white space as a word boundary. 1023The killed text is saved on the kill-ring. 1024 1025@item delete-horizontal-space () 1026Delete all spaces and tabs around point. By default, this is unbound. 1027 1028@item kill-region () 1029Kill the text in the current region. 1030By default, this command is unbound. 1031 1032@item copy-region-as-kill () 1033Copy the text in the region to the kill buffer, so it can be yanked 1034right away. By default, this command is unbound. 1035 1036@item copy-backward-word () 1037Copy the word before point to the kill buffer. 1038The word boundaries are the same as @code{backward-word}. 1039By default, this command is unbound. 1040 1041@item copy-forward-word () 1042Copy the word following point to the kill buffer. 1043The word boundaries are the same as @code{forward-word}. 1044By default, this command is unbound. 1045 1046@item yank (C-y) 1047Yank the top of the kill ring into the buffer at the current 1048cursor position. 1049 1050@item yank-pop (M-y) 1051Rotate the kill-ring, and yank the new top. You can only do this if 1052the prior command is yank or yank-pop. 1053@end ftable 1054 1055@node Numeric Arguments 1056@subsection Specifying Numeric Arguments 1057@ftable @code 1058 1059@item digit-argument (M-0, M-1, ... M--) 1060Add this digit to the argument already accumulating, or start a new 1061argument. @key{M--} starts a negative argument. 1062 1063@item universal-argument () 1064This is another way to specify an argument. 1065If this command is followed by one or more digits, optionally with a 1066leading minus sign, those digits define the argument. 1067If the command is followed by digits, executing @code{universal-argument} 1068again ends the numeric argument, but is otherwise ignored. 1069As a special case, if this command is immediately followed by a 1070character that is neither a digit or minus sign, the argument count 1071for the next command is multiplied by four. 1072The argument count is initially one, so executing this function the 1073first time makes the argument count four, a second time makes the 1074argument count sixteen, and so on. 1075By default, this is not bound to a key. 1076@end ftable 1077 1078@node Commands For Completion 1079@subsection Letting Readline Type For You 1080 1081@ftable @code 1082@item complete (TAB) 1083Attempt to do completion on the text before the cursor. This is 1084application-specific. Generally, if you are typing a filename 1085argument, you can do filename completion; if you are typing a command, 1086you can do command completion; if you are typing in a symbol to GDB, you 1087can do symbol name completion; if you are typing in a variable to Bash, 1088you can do variable name completion, and so on. 1089@ifset BashFeatures 1090Bash attempts completion treating the text as a variable (if the 1091text begins with @samp{$}), username (if the text begins with 1092@samp{~}), hostname (if the text begins with @samp{@@}), or 1093command (including aliases and functions) in turn. If none 1094of these produces a match, filename completion is attempted. 1095@end ifset 1096 1097@item possible-completions (M-?) 1098List the possible completions of the text before the cursor. 1099 1100@item insert-completions (M-*) 1101Insert all completions of the text before point that would have 1102been generated by @code{possible-completions}. 1103 1104@item menu-complete () 1105Similar to @code{complete}, but replaces the word to be completed 1106with a single match from the list of possible completions. 1107Repeated execution of @code{menu-complete} steps through the list 1108of possible completions, inserting each match in turn. 1109At the end of the list of completions, the bell is rung and the 1110original text is restored. 1111An argument of @var{n} moves @var{n} positions forward in the list 1112of matches; a negative argument may be used to move backward 1113through the list. 1114This command is intended to be bound to @code{TAB}, but is unbound 1115by default. 1116 1117@item delete-char-or-list () 1118Deletes the character under the cursor if not at the beginning or 1119end of the line (like @code{delete-char}). 1120If at the end of the line, behaves identically to 1121@code{possible-completions}. 1122This command is unbound by default. 1123 1124@ifset BashFeatures 1125@item complete-filename (M-/) 1126Attempt filename completion on the text before point. 1127 1128@item possible-filename-completions (C-x /) 1129List the possible completions of the text before point, 1130treating it as a filename. 1131 1132@item complete-username (M-~) 1133Attempt completion on the text before point, treating 1134it as a username. 1135 1136@item possible-username-completions (C-x ~) 1137List the possible completions of the text before point, 1138treating it as a username. 1139 1140@item complete-variable (M-$) 1141Attempt completion on the text before point, treating 1142it as a shell variable. 1143 1144@item possible-variable-completions (C-x $) 1145List the possible completions of the text before point, 1146treating it as a shell variable. 1147 1148@item complete-hostname (M-@@) 1149Attempt completion on the text before point, treating 1150it as a hostname. 1151 1152@item possible-hostname-completions (C-x @@) 1153List the possible completions of the text before point, 1154treating it as a hostname. 1155 1156@item complete-command (M-!) 1157Attempt completion on the text before point, treating 1158it as a command name. Command completion attempts to 1159match the text against aliases, reserved words, shell 1160functions, shell builtins, and finally executable filenames, 1161in that order. 1162 1163@item possible-command-completions (C-x !) 1164List the possible completions of the text before point, 1165treating it as a command name. 1166 1167@item dynamic-complete-history (M-TAB) 1168Attempt completion on the text before point, comparing 1169the text against lines from the history list for possible 1170completion matches. 1171 1172@item complete-into-braces (M-@{) 1173Perform filename completion and insert the list of possible completions 1174enclosed within braces so the list is available to the shell 1175(@pxref{Brace Expansion}). 1176 1177@end ifset 1178@end ftable 1179 1180@node Keyboard Macros 1181@subsection Keyboard Macros 1182@ftable @code 1183 1184@item start-kbd-macro (C-x () 1185Begin saving the characters typed into the current keyboard macro. 1186 1187@item end-kbd-macro (C-x )) 1188Stop saving the characters typed into the current keyboard macro 1189and save the definition. 1190 1191@item call-last-kbd-macro (C-x e) 1192Re-execute the last keyboard macro defined, by making the characters 1193in the macro appear as if typed at the keyboard. 1194 1195@end ftable 1196 1197@node Miscellaneous Commands 1198@subsection Some Miscellaneous Commands 1199@ftable @code 1200 1201@item re-read-init-file (C-x C-r) 1202Read in the contents of the @var{inputrc} file, and incorporate 1203any bindings or variable assignments found there. 1204 1205@item abort (C-g) 1206Abort the current editing command and 1207ring the terminal's bell (subject to the setting of 1208@code{bell-style}). 1209 1210@item do-uppercase-version (M-a, M-b, M-@var{x}, @dots{}) 1211If the metafied character @var{x} is lowercase, run the command 1212that is bound to the corresponding uppercase character. 1213 1214@item prefix-meta (ESC) 1215Make the next character typed be metafied. This is for keyboards 1216without a meta key. Typing @samp{ESC f} is equivalent to typing 1217@samp{M-f}. 1218 1219@item undo (C-_, C-x C-u) 1220Incremental undo, separately remembered for each line. 1221 1222@item revert-line (M-r) 1223Undo all changes made to this line. This is like executing the @code{undo} 1224command enough times to get back to the beginning. 1225 1226@ifset BashFeatures 1227@item tilde-expand (M-&) 1228@end ifset 1229@ifclear BashFeatures 1230@item tilde-expand (M-~) 1231@end ifclear 1232Perform tilde expansion on the current word. 1233 1234@item set-mark (C-@@) 1235Set the mark to the current point. If a 1236numeric argument is supplied, the mark is set to that position. 1237 1238@item exchange-point-and-mark (C-x C-x) 1239Swap the point with the mark. The current cursor position is set to 1240the saved position, and the old cursor position is saved as the mark. 1241 1242@item character-search (C-]) 1243A character is read and point is moved to the next occurrence of that 1244character. A negative count searches for previous occurrences. 1245 1246@item character-search-backward (M-C-]) 1247A character is read and point is moved to the previous occurrence 1248of that character. A negative count searches for subsequent 1249occurrences. 1250 1251@item insert-comment (M-#) 1252The value of the @code{comment-begin} 1253variable is inserted at the beginning of the current line, 1254and the line is accepted as if a newline had been typed. 1255@ifset BashFeatures 1256The default value of @code{comment-begin} causes this command 1257to make the current line a shell comment. 1258@end ifset 1259 1260@item dump-functions () 1261Print all of the functions and their key bindings to the 1262Readline output stream. If a numeric argument is supplied, 1263the output is formatted in such a way that it can be made part 1264of an @var{inputrc} file. This command is unbound by default. 1265 1266@item dump-variables () 1267Print all of the settable variables and their values to the 1268Readline output stream. If a numeric argument is supplied, 1269the output is formatted in such a way that it can be made part 1270of an @var{inputrc} file. This command is unbound by default. 1271 1272@item dump-macros () 1273Print all of the Readline key sequences bound to macros and the 1274strings they ouput. If a numeric argument is supplied, 1275the output is formatted in such a way that it can be made part 1276of an @var{inputrc} file. This command is unbound by default. 1277 1278@ifset BashFeatures 1279@item glob-expand-word (C-x *) 1280The word before point is treated as a pattern for pathname expansion, 1281and the list of matching file names is inserted, replacing the word. 1282 1283@item glob-list-expansions (C-x g) 1284The list of expansions that would have been generated by 1285@code{glob-expand-word} is displayed, and the line is redrawn. 1286 1287@item display-shell-version (C-x C-v) 1288Display version information about the current instance of Bash. 1289 1290@item shell-expand-line (M-C-e) 1291Expand the line as the shell does. 1292This performs alias and history expansion as well as all of the shell 1293word expansions (@pxref{Shell Expansions}). 1294 1295@item history-expand-line (M-^) 1296Perform history expansion on the current line. 1297 1298@item magic-space () 1299Perform history expansion on the current line and insert a space 1300(@pxref{History Interaction}). 1301 1302@item alias-expand-line () 1303Perform alias expansion on the current line (@pxref{Aliases}). 1304 1305@item history-and-alias-expand-line () 1306Perform history and alias expansion on the current line. 1307 1308@item insert-last-argument (M-., M-_) 1309A synonym for @code{yank-last-arg}. 1310 1311@item operate-and-get-next (C-o) 1312Accept the current line for execution and fetch the next line 1313relative to the current line from the history for editing. Any 1314argument is ignored. 1315 1316@item emacs-editing-mode (C-e) 1317When in @code{vi} editing mode, this causes a switch back to 1318@code{emacs} editing mode, as if the command @samp{set -o emacs} had 1319been executed. 1320 1321@end ifset 1322 1323@end ftable 1324 1325@node Readline vi Mode 1326@section Readline vi Mode 1327 1328While the Readline library does not have a full set of @code{vi} 1329editing functions, it does contain enough to allow simple editing 1330of the line. The Readline @code{vi} mode behaves as specified in 1331the @sc{POSIX} 1003.2 standard. 1332 1333@ifset BashFeatures 1334In order to switch interactively between @code{emacs} and @code{vi} 1335editing modes, use the @samp{set -o emacs} and @samp{set -o vi} 1336commands (@pxref{The Set Builtin}). 1337@end ifset 1338@ifclear BashFeatures 1339In order to switch interactively between @code{emacs} and @code{vi} 1340editing modes, use the command M-C-j (toggle-editing-mode). 1341@end ifclear 1342The Readline default is @code{emacs} mode. 1343 1344When you enter a line in @code{vi} mode, you are already placed in 1345`insertion' mode, as if you had typed an @samp{i}. Pressing @key{ESC} 1346switches you into `command' mode, where you can edit the text of the 1347line with the standard @code{vi} movement keys, move to previous 1348history lines with @samp{k} and subsequent lines with @samp{j}, and 1349so forth. 1350 1351@ifset BashFeatures 1352@node Programmable Completion 1353@section Programmable Completion 1354@cindex programmable completion 1355 1356When word completion is attempted for an argument to a command for 1357which a completion specification (a @var{compspec}) has been defined 1358using the @code{complete} builtin (@pxref{Programmable Completion Builtins}), 1359the programmable completion facilities are invoked. 1360 1361First, the command name is identified. 1362If a compspec has been defined for that command, the 1363compspec is used to generate the list of possible completions for the word. 1364If the command word is a full pathname, a compspec for the full 1365pathname is searched for first. 1366If no compspec is found for the full pathname, an attempt is made to 1367find a compspec for the portion following the final slash. 1368 1369Once a compspec has been found, it is used to generate the list of 1370matching words. 1371If a compspec is not found, the default Bash completion 1372described above (@pxref{Commands For Completion}) is performed. 1373 1374First, the actions specified by the compspec are used. 1375Only matches which are prefixed by the word being completed are 1376returned. 1377When the @samp{-f} or @samp{-d} option is used for filename or 1378directory name completion, the shell variable @code{FIGNORE} is 1379used to filter the matches. 1380@xref{Bash Variables}, for a description of @code{FIGNORE}. 1381 1382Any completions specified by a filename expansion pattern to the 1383@samp{-G} option are generated next. 1384The words generated by the pattern need not match the word being completed. 1385The @code{GLOBIGNORE} shell variable is not used to filter the matches, 1386but the @code{FIGNORE} shell variable is used. 1387 1388Next, the string specified as the argument to the @samp{-W} option 1389is considered. 1390The string is first split using the characters in the @code{IFS} 1391special variable as delimiters. 1392Shell quoting is honored. 1393Each word is then expanded using 1394brace expansion, tilde expansion, parameter and variable expansion, 1395command substitution, arithmetic expansion, and pathname expansion, 1396as described above (@pxref{Shell Expansions}). 1397The results are split using the rules described above 1398(@pxref{Word Splitting}). 1399The results of the expansion are prefix-matched against the word being 1400completed, and the matching words become the possible completions. 1401 1402After these matches have been generated, any shell function or command 1403specified with the @samp{-F} and @samp{-C} options is invoked. 1404When the command or function is invoked, the @code{COMP_LINE} and 1405@code{COMP_POINT} variables are assigned values as described above 1406(@pxref{Bash Variables}). 1407If a shell function is being invoked, the @code{COMP_WORDS} and 1408@code{COMP_CWORD} variables are also set. 1409When the function or command is invoked, the first argument is the 1410name of the command whose arguments are being completed, the 1411second argument is the word being completed, and the third argument 1412is the word preceding the word being completed on the current command line. 1413No filtering of the generated completions against the word being completed 1414is performed; the function or command has complete freedom in generating 1415the matches. 1416 1417Any function specified with @samp{-F} is invoked first. 1418The function may use any of the shell facilities, including the 1419@code{compgen} builtin described below 1420(@pxref{Programmable Completion Builtins}), to generate the matches. 1421It must put the possible completions in the @code{COMPREPLY} array 1422variable. 1423 1424Next, any command specified with the @samp{-C} option is invoked 1425in an environment equivalent to command substitution. 1426It should print a list of completions, one per line, to 1427the standard output. 1428Backslash may be used to escape a newline, if necessary. 1429 1430After all of the possible completions are generated, any filter 1431specified with the @samp{-X} option is applied to the list. 1432The filter is a pattern as used for pathname expansion; a @samp{&} 1433in the pattern is replaced with the text of the word being completed. 1434A literal @samp{&} may be escaped with a backslash; the backslash 1435is removed before attempting a match. 1436Any completion that matches the pattern will be removed from the list. 1437A leading @samp{!} negates the pattern; in this case any completion 1438not matching the pattern will be removed. 1439 1440Finally, any prefix and suffix specified with the @samp{-P} and @samp{-S} 1441options are added to each member of the completion list, and the result is 1442returned to the Readline completion code as the list of possible 1443completions. 1444 1445If a compspec is found, whatever it generates is returned to the completion 1446code as the full set of possible completions. 1447The default Bash completions are not attempted, and the Readline 1448default of filename completion is disabled. 1449 1450@node Programmable Completion Builtins 1451@section Programmable Completion Builtins 1452@cindex completion builtins 1453 1454Two builtin commands are available to manipulate the programmable completion 1455facilities. 1456 1457@table @code 1458@item compgen 1459@btindex compgen 1460@example 1461@code{compgen [@var{option}] [@var{word}]} 1462@end example 1463 1464Generate possible completion matches for @var{word} according to 1465the @var{option}s, which may be any option accepted by the 1466@code{complete} 1467builtin with the exception of @samp{-p} and @samp{-r}, and write 1468the matches to the standard output. 1469When using the @samp{-F} or @samp{-C} options, the various shell variables 1470set by the programmable completion facilities, while available, will not 1471have useful values. 1472 1473The matches will be generated in the same way as if the programmable 1474completion code had generated them directly from a completion specification 1475with the same flags. 1476If @var{word} is specified, only those completions matching @var{word} 1477will be displayed. 1478 1479The return value is true unless an invalid option is supplied, or no 1480matches were generated. 1481 1482@item complete 1483@btindex complete 1484@example 1485@code{complete [-abcdefjkvu] [-A @var{action}] [-G @var{globpat}] [-W @var{wordlist}] 1486[-P @var{prefix}] [-S @var{suffix}] [-X @var{filterpat}] [-F @var{function}] 1487[-C @var{command}] @var{name} [@var{name} @dots{}]} 1488@code{complete -pr [@var{name} @dots{}]} 1489@end example 1490 1491Specify how arguments to each @var{name} should be completed. 1492If the @samp{-p} option is supplied, or if no options are supplied, existing 1493completion specifications are printed in a way that allows them to be 1494reused as input. 1495The @samp{-r} option removes a completion specification for 1496each @var{name}, or, if no @var{name}s are supplied, all 1497completion specifications. 1498 1499The process of applying these completion specifications when word completion 1500is attempted is described above (@pxref{Programmable Completion}). 1501 1502Other options, if specified, have the following meanings. 1503The arguments to the @samp{-G}, @samp{-W}, and @samp{-X} options 1504(and, if necessary, the @samp{-P} and @samp{-S} options) 1505should be quoted to protect them from expansion before the 1506@code{complete} builtin is invoked. 1507 1508@table @code 1509@item -A @var{action} 1510The @var{action} may be one of the following to generate a list of possible 1511completions: 1512 1513@table @code 1514@item alias 1515Alias names. May also be specified as @samp{-a}. 1516 1517@item arrayvar 1518Array variable names. 1519 1520@item binding 1521Readline key binding names (@pxref{Bindable Readline Commands}). 1522 1523@item builtin 1524Names of shell builtin commands. May also be specified as @samp{-b}. 1525 1526@item command 1527Command names. May also be specified as @samp{-c}. 1528 1529@item directory 1530Directory names. May also be specified as @samp{-d}. 1531 1532@item disabled 1533Names of disabled shell builtins. 1534 1535@item enabled 1536Names of enabled shell builtins. 1537 1538@item export 1539Names of exported shell variables. May also be specified as @samp{-e}. 1540 1541@item file 1542File names. May also be specified as @samp{-f}. 1543 1544@item function 1545Names of shell functions. 1546 1547@item helptopic 1548Help topics as accepted by the @code{help} builtin (@pxref{Bash Builtins}). 1549 1550@item hostname 1551Hostnames, as taken from the file specified by the 1552@code{HOSTFILE} shell variable (@pxref{Bash Variables}). 1553 1554@item job 1555Job names, if job control is active. May also be specified as @samp{-j}. 1556 1557@item keyword 1558Shell reserved words. May also be specified as @samp{-k}. 1559 1560@item running 1561Names of running jobs, if job control is active. 1562 1563@item setopt 1564Valid arguments for the @samp{-o} option to the @code{set} builtin 1565(@pxref{The Set Builtin}). 1566 1567@item shopt 1568Shell option names as accepted by the @code{shopt} builtin 1569(@pxref{Bash Builtins}). 1570 1571@item signal 1572Signal names. 1573 1574@item stopped 1575Names of stopped jobs, if job control is active. 1576 1577@item user 1578User names. May also be specified as @samp{-u}. 1579 1580@item variable 1581Names of all shell variables. May also be specified as @samp{-v}. 1582@end table 1583 1584@item -G @var{globpat} 1585The filename expansion pattern @var{globpat} is expanded to generate 1586the possible completions. 1587 1588@item -W @var{wordlist} 1589The @var{wordlist} is split using the characters in the 1590@code{IFS} special variable as delimiters, and each resultant word 1591is expanded. 1592The possible completions are the members of the resultant list which 1593match the word being completed. 1594 1595@item -C @var{command} 1596@var{command} is executed in a subshell environment, and its output is 1597used as the possible completions. 1598 1599@item -F @var{function} 1600The shell function @var{function} is executed in the current shell 1601environment. 1602When it finishes, the possible completions are retrieved from the value 1603of the @code{COMPREPLY} array variable. 1604 1605@item -X @var{filterpat} 1606@var{filterpat} is a pattern as used for filename expansion. 1607It is applied to the list of possible completions generated by the 1608preceding options and arguments, and each completion matching 1609@var{filterpat} is removed from the list. 1610A leading @samp{!} in @var{filterpat} negates the pattern; in this 1611case, any completion not matching @var{filterpat} is removed. 1612 1613@item -P @var{prefix} 1614@var{prefix} is added at the beginning of each possible completion 1615after all other options have been applied. 1616 1617@item -S @var{suffix} 1618@var{suffix} is appended to each possible completion 1619after all other options have been applied. 1620@end table 1621 1622The return value is true unless an invalid option is supplied, an option 1623other than @samp{-p} or @samp{-r} is supplied without a @var{name} 1624argument, an attempt is made to remove a completion specification for 1625a @var{name} for which no specification exists, or 1626an error occurs adding a completion specification. 1627 1628@end table 1629@end ifset 1630