1136644Sache@comment %**start of header (This is for running Texinfo on a region.) 2136644Sache@setfilename rluser.info 3136644Sache@comment %**end of header (This is for running Texinfo on a region.) 4136644Sache@setchapternewpage odd 5136644Sache 6136644Sache@ignore 7136644SacheThis file documents the end user interface to the GNU command line 8136644Sacheediting features. It is to be an appendix to manuals for programs which 9136644Sacheuse these features. There is a document entitled "readline.texinfo" 10136644Sachewhich contains both end-user and programmer documentation for the 11136644SacheGNU Readline Library. 12136644Sache 13165670SacheCopyright (C) 1988-2006 Free Software Foundation, Inc. 14136644Sache 15136644SacheAuthored by Brian Fox and Chet Ramey. 16136644Sache 17136644SachePermission is granted to process this file through Tex and print the 18136644Sacheresults, provided the printed document carries copying permission notice 19136644Sacheidentical to this one except for the removal of this paragraph (this 20136644Sacheparagraph not being relevant to the printed manual). 21136644Sache 22136644SachePermission is granted to make and distribute verbatim copies of this manual 23136644Sacheprovided the copyright notice and this permission notice are preserved on 24136644Sacheall copies. 25136644Sache 26136644SachePermission is granted to copy and distribute modified versions of this 27136644Sachemanual under the conditions for verbatim copying, provided also that the 28136644SacheGNU Copyright statement is available to the distributee, and provided that 29136644Sachethe entire resulting derived work is distributed under the terms of a 30136644Sachepermission notice identical to this one. 31136644Sache 32136644SachePermission is granted to copy and distribute translations of this manual 33136644Sacheinto another language, under the above conditions for modified versions. 34136644Sache@end ignore 35136644Sache 36136644Sache@comment If you are including this manual as an appendix, then set the 37136644Sache@comment variable readline-appendix. 38136644Sache 39136644Sache@ifclear BashFeatures 40136644Sache@defcodeindex bt 41136644Sache@end ifclear 42136644Sache 43136644Sache@node Command Line Editing 44136644Sache@chapter Command Line Editing 45136644Sache 46136644SacheThis chapter describes the basic features of the @sc{gnu} 47136644Sachecommand line editing interface. 48136644Sache@ifset BashFeatures 49136644SacheCommand line editing is provided by the Readline library, which is 50136644Sacheused by several different programs, including Bash. 51136644Sache@end ifset 52136644Sache 53136644Sache@menu 54136644Sache* Introduction and Notation:: Notation used in this text. 55136644Sache* Readline Interaction:: The minimum set of commands for editing a line. 56136644Sache* Readline Init File:: Customizing Readline from a user's view. 57136644Sache* Bindable Readline Commands:: A description of most of the Readline commands 58136644Sache available for binding 59136644Sache* Readline vi Mode:: A short description of how to make Readline 60136644Sache behave like the vi editor. 61136644Sache@ifset BashFeatures 62136644Sache* Programmable Completion:: How to specify the possible completions for 63136644Sache a specific command. 64136644Sache* Programmable Completion Builtins:: Builtin commands to specify how to 65136644Sache complete arguments for a particular command. 66136644Sache@end ifset 67136644Sache@end menu 68136644Sache 69136644Sache@node Introduction and Notation 70136644Sache@section Introduction to Line Editing 71136644Sache 72136644SacheThe following paragraphs describe the notation used to represent 73136644Sachekeystrokes. 74136644Sache 75136644SacheThe text @kbd{C-k} is read as `Control-K' and describes the character 76136644Sacheproduced when the @key{k} key is pressed while the Control key 77136644Sacheis depressed. 78136644Sache 79136644SacheThe text @kbd{M-k} is read as `Meta-K' and describes the character 80136644Sacheproduced when the Meta key (if you have one) is depressed, and the @key{k} 81136644Sachekey is pressed. 82136644SacheThe Meta key is labeled @key{ALT} on many keyboards. 83136644SacheOn keyboards with two keys labeled @key{ALT} (usually to either side of 84136644Sachethe space bar), the @key{ALT} on the left side is generally set to 85136644Sachework as a Meta key. 86136644SacheThe @key{ALT} key on the right may also be configured to work as a 87136644SacheMeta key or may be configured as some other modifier, such as a 88136644SacheCompose key for typing accented characters. 89136644Sache 90136644SacheIf you do not have a Meta or @key{ALT} key, or another key working as 91136644Sachea Meta key, the identical keystroke can be generated by typing @key{ESC} 92136644Sache@emph{first}, and then typing @key{k}. 93136644SacheEither process is known as @dfn{metafying} the @key{k} key. 94136644Sache 95136644SacheThe text @kbd{M-C-k} is read as `Meta-Control-k' and describes the 96136644Sachecharacter produced by @dfn{metafying} @kbd{C-k}. 97136644Sache 98136644SacheIn addition, several keys have their own names. Specifically, 99136644Sache@key{DEL}, @key{ESC}, @key{LFD}, @key{SPC}, @key{RET}, and @key{TAB} all 100136644Sachestand for themselves when seen in this text, or in an init file 101136644Sache(@pxref{Readline Init File}). 102136644SacheIf your keyboard lacks a @key{LFD} key, typing @key{C-j} will 103136644Sacheproduce the desired character. 104136644SacheThe @key{RET} key may be labeled @key{Return} or @key{Enter} on 105136644Sachesome keyboards. 106136644Sache 107136644Sache@node Readline Interaction 108136644Sache@section Readline Interaction 109136644Sache@cindex interaction, readline 110136644Sache 111136644SacheOften during an interactive session you type in a long line of text, 112136644Sacheonly to notice that the first word on the line is misspelled. The 113136644SacheReadline library gives you a set of commands for manipulating the text 114136644Sacheas you type it in, allowing you to just fix your typo, and not forcing 115136644Sacheyou to retype the majority of the line. Using these editing commands, 116136644Sacheyou move the cursor to the place that needs correction, and delete or 117136644Sacheinsert the text of the corrections. Then, when you are satisfied with 118136644Sachethe line, you simply press @key{RET}. You do not have to be at the 119136644Sacheend of the line to press @key{RET}; the entire line is accepted 120136644Sacheregardless of the location of the cursor within the line. 121136644Sache 122136644Sache@menu 123136644Sache* Readline Bare Essentials:: The least you need to know about Readline. 124136644Sache* Readline Movement Commands:: Moving about the input line. 125136644Sache* Readline Killing Commands:: How to delete text, and how to get it back! 126136644Sache* Readline Arguments:: Giving numeric arguments to commands. 127136644Sache* Searching:: Searching through previous lines. 128136644Sache@end menu 129136644Sache 130136644Sache@node Readline Bare Essentials 131136644Sache@subsection Readline Bare Essentials 132136644Sache@cindex notation, readline 133136644Sache@cindex command editing 134136644Sache@cindex editing command lines 135136644Sache 136136644SacheIn order to enter characters into the line, simply type them. The typed 137136644Sachecharacter appears where the cursor was, and then the cursor moves one 138136644Sachespace to the right. If you mistype a character, you can use your 139136644Sacheerase character to back up and delete the mistyped character. 140136644Sache 141136644SacheSometimes you may mistype a character, and 142136644Sachenot notice the error until you have typed several other characters. In 143136644Sachethat case, you can type @kbd{C-b} to move the cursor to the left, and then 144136644Sachecorrect your mistake. Afterwards, you can move the cursor to the right 145136644Sachewith @kbd{C-f}. 146136644Sache 147136644SacheWhen you add text in the middle of a line, you will notice that characters 148136644Sacheto the right of the cursor are `pushed over' to make room for the text 149136644Sachethat you have inserted. Likewise, when you delete text behind the cursor, 150136644Sachecharacters to the right of the cursor are `pulled back' to fill in the 151136644Sacheblank space created by the removal of the text. A list of the bare 152136644Sacheessentials for editing the text of an input line follows. 153136644Sache 154136644Sache@table @asis 155136644Sache@item @kbd{C-b} 156136644SacheMove back one character. 157136644Sache@item @kbd{C-f} 158136644SacheMove forward one character. 159136644Sache@item @key{DEL} or @key{Backspace} 160136644SacheDelete the character to the left of the cursor. 161136644Sache@item @kbd{C-d} 162136644SacheDelete the character underneath the cursor. 163136644Sache@item @w{Printing characters} 164136644SacheInsert the character into the line at the cursor. 165136644Sache@item @kbd{C-_} or @kbd{C-x C-u} 166136644SacheUndo the last editing command. You can undo all the way back to an 167136644Sacheempty line. 168136644Sache@end table 169136644Sache 170136644Sache@noindent 171136644Sache(Depending on your configuration, the @key{Backspace} key be set to 172136644Sachedelete the character to the left of the cursor and the @key{DEL} key set 173136644Sacheto delete the character underneath the cursor, like @kbd{C-d}, rather 174136644Sachethan the character to the left of the cursor.) 175136644Sache 176136644Sache@node Readline Movement Commands 177136644Sache@subsection Readline Movement Commands 178136644Sache 179136644Sache 180136644SacheThe above table describes the most basic keystrokes that you need 181136644Sachein order to do editing of the input line. For your convenience, many 182136644Sacheother commands have been added in addition to @kbd{C-b}, @kbd{C-f}, 183136644Sache@kbd{C-d}, and @key{DEL}. Here are some commands for moving more rapidly 184136644Sacheabout the line. 185136644Sache 186136644Sache@table @kbd 187136644Sache@item C-a 188136644SacheMove to the start of the line. 189136644Sache@item C-e 190136644SacheMove to the end of the line. 191136644Sache@item M-f 192136644SacheMove forward a word, where a word is composed of letters and digits. 193136644Sache@item M-b 194136644SacheMove backward a word. 195136644Sache@item C-l 196136644SacheClear the screen, reprinting the current line at the top. 197136644Sache@end table 198136644Sache 199136644SacheNotice how @kbd{C-f} moves forward a character, while @kbd{M-f} moves 200136644Sacheforward a word. It is a loose convention that control keystrokes 201136644Sacheoperate on characters while meta keystrokes operate on words. 202136644Sache 203136644Sache@node Readline Killing Commands 204136644Sache@subsection Readline Killing Commands 205136644Sache 206136644Sache@cindex killing text 207136644Sache@cindex yanking text 208136644Sache 209136644Sache@dfn{Killing} text means to delete the text from the line, but to save 210136644Sacheit away for later use, usually by @dfn{yanking} (re-inserting) 211136644Sacheit back into the line. 212136644Sache(`Cut' and `paste' are more recent jargon for `kill' and `yank'.) 213136644Sache 214136644SacheIf the description for a command says that it `kills' text, then you can 215136644Sachebe sure that you can get the text back in a different (or the same) 216136644Sacheplace later. 217136644Sache 218136644SacheWhen you use a kill command, the text is saved in a @dfn{kill-ring}. 219136644SacheAny number of consecutive kills save all of the killed text together, so 220136644Sachethat when you yank it back, you get it all. The kill 221136644Sachering is not line specific; the text that you killed on a previously 222136644Sachetyped line is available to be yanked back later, when you are typing 223136644Sacheanother line. 224136644Sache@cindex kill ring 225136644Sache 226136644SacheHere is the list of commands for killing text. 227136644Sache 228136644Sache@table @kbd 229136644Sache@item C-k 230136644SacheKill the text from the current cursor position to the end of the line. 231136644Sache 232136644Sache@item M-d 233136644SacheKill from the cursor to the end of the current word, or, if between 234136644Sachewords, to the end of the next word. 235136644SacheWord boundaries are the same as those used by @kbd{M-f}. 236136644Sache 237136644Sache@item M-@key{DEL} 238136644SacheKill from the cursor the start of the current word, or, if between 239136644Sachewords, to the start of the previous word. 240136644SacheWord boundaries are the same as those used by @kbd{M-b}. 241136644Sache 242136644Sache@item C-w 243136644SacheKill from the cursor to the previous whitespace. This is different than 244136644Sache@kbd{M-@key{DEL}} because the word boundaries differ. 245136644Sache 246136644Sache@end table 247136644Sache 248136644SacheHere is how to @dfn{yank} the text back into the line. Yanking 249136644Sachemeans to copy the most-recently-killed text from the kill buffer. 250136644Sache 251136644Sache@table @kbd 252136644Sache@item C-y 253136644SacheYank the most recently killed text back into the buffer at the cursor. 254136644Sache 255136644Sache@item M-y 256136644SacheRotate the kill-ring, and yank the new top. You can only do this if 257136644Sachethe prior command is @kbd{C-y} or @kbd{M-y}. 258136644Sache@end table 259136644Sache 260136644Sache@node Readline Arguments 261136644Sache@subsection Readline Arguments 262136644Sache 263136644SacheYou can pass numeric arguments to Readline commands. Sometimes the 264136644Sacheargument acts as a repeat count, other times it is the @i{sign} of the 265136644Sacheargument that is significant. If you pass a negative argument to a 266136644Sachecommand which normally acts in a forward direction, that command will 267136644Sacheact in a backward direction. For example, to kill text back to the 268136644Sachestart of the line, you might type @samp{M-- C-k}. 269136644Sache 270136644SacheThe general way to pass numeric arguments to a command is to type meta 271136644Sachedigits before the command. If the first `digit' typed is a minus 272136644Sachesign (@samp{-}), then the sign of the argument will be negative. Once 273136644Sacheyou have typed one meta digit to get the argument started, you can type 274136644Sachethe remainder of the digits, and then the command. For example, to give 275136644Sachethe @kbd{C-d} command an argument of 10, you could type @samp{M-1 0 C-d}, 276136644Sachewhich will delete the next ten characters on the input line. 277136644Sache 278136644Sache@node Searching 279136644Sache@subsection Searching for Commands in the History 280136644Sache 281136644SacheReadline provides commands for searching through the command history 282136644Sache@ifset BashFeatures 283136644Sache(@pxref{Bash History Facilities}) 284136644Sache@end ifset 285136644Sachefor lines containing a specified string. 286136644SacheThere are two search modes: @dfn{incremental} and @dfn{non-incremental}. 287136644Sache 288136644SacheIncremental searches begin before the user has finished typing the 289136644Sachesearch string. 290136644SacheAs each character of the search string is typed, Readline displays 291136644Sachethe next entry from the history matching the string typed so far. 292136644SacheAn incremental search requires only as many characters as needed to 293136644Sachefind the desired history entry. 294136644SacheTo search backward in the history for a particular string, type 295136644Sache@kbd{C-r}. Typing @kbd{C-s} searches forward through the history. 296136644SacheThe characters present in the value of the @code{isearch-terminators} variable 297136644Sacheare used to terminate an incremental search. 298136644SacheIf that variable has not been assigned a value, the @key{ESC} and 299136644Sache@kbd{C-J} characters will terminate an incremental search. 300136644Sache@kbd{C-g} will abort an incremental search and restore the original line. 301136644SacheWhen the search is terminated, the history entry containing the 302136644Sachesearch string becomes the current line. 303136644Sache 304136644SacheTo find other matching entries in the history list, type @kbd{C-r} or 305136644Sache@kbd{C-s} as appropriate. 306136644SacheThis will search backward or forward in the history for the next 307136644Sacheentry matching the search string typed so far. 308136644SacheAny other key sequence bound to a Readline command will terminate 309136644Sachethe search and execute that command. 310136644SacheFor instance, a @key{RET} will terminate the search and accept 311136644Sachethe line, thereby executing the command from the history list. 312136644SacheA movement command will terminate the search, make the last line found 313136644Sachethe current line, and begin editing. 314136644Sache 315136644SacheReadline remembers the last incremental search string. If two 316136644Sache@kbd{C-r}s are typed without any intervening characters defining a new 317136644Sachesearch string, any remembered search string is used. 318136644Sache 319136644SacheNon-incremental searches read the entire search string before starting 320136644Sacheto search for matching history lines. The search string may be 321136644Sachetyped by the user or be part of the contents of the current line. 322136644Sache 323136644Sache@node Readline Init File 324136644Sache@section Readline Init File 325136644Sache@cindex initialization file, readline 326136644Sache 327136644SacheAlthough the Readline library comes with a set of Emacs-like 328136644Sachekeybindings installed by default, it is possible to use a different set 329136644Sacheof keybindings. 330136644SacheAny user can customize programs that use Readline by putting 331136644Sachecommands in an @dfn{inputrc} file, conventionally in his home directory. 332136644SacheThe name of this 333136644Sache@ifset BashFeatures 334136644Sachefile is taken from the value of the shell variable @env{INPUTRC}. If 335136644Sache@end ifset 336136644Sache@ifclear BashFeatures 337136644Sachefile is taken from the value of the environment variable @env{INPUTRC}. If 338136644Sache@end ifclear 339165670Sachethat variable is unset, the default is @file{~/.inputrc}. If that 340165670Sachefile does not exist or cannot be read, the ultimate default is 341165670Sache@file{/etc/inputrc}. 342136644Sache 343136644SacheWhen a program which uses the Readline library starts up, the 344136644Sacheinit file is read, and the key bindings are set. 345136644Sache 346136644SacheIn addition, the @code{C-x C-r} command re-reads this init file, thus 347136644Sacheincorporating any changes that you might have made to it. 348136644Sache 349136644Sache@menu 350136644Sache* Readline Init File Syntax:: Syntax for the commands in the inputrc file. 351136644Sache 352136644Sache* Conditional Init Constructs:: Conditional key bindings in the inputrc file. 353136644Sache 354136644Sache* Sample Init File:: An example inputrc file. 355136644Sache@end menu 356136644Sache 357136644Sache@node Readline Init File Syntax 358136644Sache@subsection Readline Init File Syntax 359136644Sache 360136644SacheThere are only a few basic constructs allowed in the 361136644SacheReadline init file. Blank lines are ignored. 362136644SacheLines beginning with a @samp{#} are comments. 363136644SacheLines beginning with a @samp{$} indicate conditional 364136644Sacheconstructs (@pxref{Conditional Init Constructs}). Other lines 365136644Sachedenote variable settings and key bindings. 366136644Sache 367136644Sache@table @asis 368136644Sache@item Variable Settings 369136644SacheYou can modify the run-time behavior of Readline by 370136644Sachealtering the values of variables in Readline 371136644Sacheusing the @code{set} command within the init file. 372136644SacheThe syntax is simple: 373136644Sache 374136644Sache@example 375136644Sacheset @var{variable} @var{value} 376136644Sache@end example 377136644Sache 378136644Sache@noindent 379136644SacheHere, for example, is how to 380136644Sachechange from the default Emacs-like key binding to use 381136644Sache@code{vi} line editing commands: 382136644Sache 383136644Sache@example 384136644Sacheset editing-mode vi 385136644Sache@end example 386136644Sache 387136644SacheVariable names and values, where appropriate, are recognized without regard 388157184Sacheto case. Unrecognized variable names are ignored. 389136644Sache 390157184SacheBoolean variables (those that can be set to on or off) are set to on if 391157184Sachethe value is null or empty, @var{on} (case-insensitive), or 1. Any other 392157184Sachevalue results in the variable being set to off. 393157184Sache 394136644Sache@ifset BashFeatures 395136644SacheThe @w{@code{bind -V}} command lists the current Readline variable names 396136644Sacheand values. @xref{Bash Builtins}. 397136644Sache@end ifset 398136644Sache 399136644SacheA great deal of run-time behavior is changeable with the following 400136644Sachevariables. 401136644Sache 402136644Sache@cindex variables, readline 403136644Sache@table @code 404136644Sache 405136644Sache@item bell-style 406136644Sache@vindex bell-style 407136644SacheControls what happens when Readline wants to ring the terminal bell. 408136644SacheIf set to @samp{none}, Readline never rings the bell. If set to 409136644Sache@samp{visible}, Readline uses a visible bell if one is available. 410136644SacheIf set to @samp{audible} (the default), Readline attempts to ring 411136644Sachethe terminal's bell. 412136644Sache 413157184Sache@item bind-tty-special-chars 414157184Sache@vindex bind-tty-special-chars 415157184SacheIf set to @samp{on}, Readline attempts to bind the control characters 416157184Sachetreated specially by the kernel's terminal driver to their Readline 417157184Sacheequivalents. 418157184Sache 419136644Sache@item comment-begin 420136644Sache@vindex comment-begin 421136644SacheThe string to insert at the beginning of the line when the 422136644Sache@code{insert-comment} command is executed. The default value 423136644Sacheis @code{"#"}. 424136644Sache 425136644Sache@item completion-ignore-case 426136644SacheIf set to @samp{on}, Readline performs filename matching and completion 427136644Sachein a case-insensitive fashion. 428136644SacheThe default value is @samp{off}. 429136644Sache 430136644Sache@item completion-query-items 431136644Sache@vindex completion-query-items 432136644SacheThe number of possible completions that determines when the user is 433136644Sacheasked whether the list of possibilities should be displayed. 434136644SacheIf the number of possible completions is greater than this value, 435136644SacheReadline will ask the user whether or not he wishes to view 436136644Sachethem; otherwise, they are simply listed. 437136644SacheThis variable must be set to an integer value greater than or equal to 0. 438157184SacheA negative value means Readline should never ask. 439136644SacheThe default limit is @code{100}. 440136644Sache 441136644Sache@item convert-meta 442136644Sache@vindex convert-meta 443136644SacheIf set to @samp{on}, Readline will convert characters with the 444136644Sacheeighth bit set to an @sc{ascii} key sequence by stripping the eighth 445136644Sachebit and prefixing an @key{ESC} character, converting them to a 446136644Sachemeta-prefixed key sequence. The default value is @samp{on}. 447136644Sache 448136644Sache@item disable-completion 449136644Sache@vindex disable-completion 450136644SacheIf set to @samp{On}, Readline will inhibit word completion. 451136644SacheCompletion characters will be inserted into the line as if they had 452136644Sachebeen mapped to @code{self-insert}. The default is @samp{off}. 453136644Sache 454136644Sache@item editing-mode 455136644Sache@vindex editing-mode 456136644SacheThe @code{editing-mode} variable controls which default set of 457136644Sachekey bindings is used. By default, Readline starts up in Emacs editing 458136644Sachemode, where the keystrokes are most similar to Emacs. This variable can be 459136644Sacheset to either @samp{emacs} or @samp{vi}. 460136644Sache 461136644Sache@item enable-keypad 462136644Sache@vindex enable-keypad 463136644SacheWhen set to @samp{on}, Readline will try to enable the application 464136644Sachekeypad when it is called. Some systems need this to enable the 465136644Sachearrow keys. The default is @samp{off}. 466136644Sache 467136644Sache@item expand-tilde 468136644Sache@vindex expand-tilde 469136644SacheIf set to @samp{on}, tilde expansion is performed when Readline 470136644Sacheattempts word completion. The default is @samp{off}. 471136644Sache 472157184Sache@item history-preserve-point 473136644Sache@vindex history-preserve-point 474136644SacheIf set to @samp{on}, the history code attempts to place point at the 475136644Sachesame location on each history line retrieved with @code{previous-history} 476157184Sacheor @code{next-history}. The default is @samp{off}. 477136644Sache 478136644Sache@item horizontal-scroll-mode 479136644Sache@vindex horizontal-scroll-mode 480136644SacheThis variable can be set to either @samp{on} or @samp{off}. Setting it 481136644Sacheto @samp{on} means that the text of the lines being edited will scroll 482136644Sachehorizontally on a single screen line when they are longer than the width 483136644Sacheof the screen, instead of wrapping onto a new screen line. By default, 484136644Sachethis variable is set to @samp{off}. 485136644Sache 486136644Sache@item input-meta 487136644Sache@vindex input-meta 488136644Sache@vindex meta-flag 489136644SacheIf set to @samp{on}, Readline will enable eight-bit input (it 490136644Sachewill not clear the eighth bit in the characters it reads), 491136644Sacheregardless of what the terminal claims it can support. The 492136644Sachedefault value is @samp{off}. The name @code{meta-flag} is a 493136644Sachesynonym for this variable. 494136644Sache 495136644Sache@item isearch-terminators 496136644Sache@vindex isearch-terminators 497136644SacheThe string of characters that should terminate an incremental search without 498136644Sachesubsequently executing the character as a command (@pxref{Searching}). 499136644SacheIf this variable has not been given a value, the characters @key{ESC} and 500136644Sache@kbd{C-J} will terminate an incremental search. 501136644Sache 502136644Sache@item keymap 503136644Sache@vindex keymap 504136644SacheSets Readline's idea of the current keymap for key binding commands. 505136644SacheAcceptable @code{keymap} names are 506136644Sache@code{emacs}, 507136644Sache@code{emacs-standard}, 508136644Sache@code{emacs-meta}, 509136644Sache@code{emacs-ctlx}, 510136644Sache@code{vi}, 511136644Sache@code{vi-move}, 512136644Sache@code{vi-command}, and 513136644Sache@code{vi-insert}. 514136644Sache@code{vi} is equivalent to @code{vi-command}; @code{emacs} is 515136644Sacheequivalent to @code{emacs-standard}. The default value is @code{emacs}. 516136644SacheThe value of the @code{editing-mode} variable also affects the 517136644Sachedefault keymap. 518136644Sache 519136644Sache@item mark-directories 520136644SacheIf set to @samp{on}, completed directory names have a slash 521136644Sacheappended. The default is @samp{on}. 522136644Sache 523136644Sache@item mark-modified-lines 524136644Sache@vindex mark-modified-lines 525136644SacheThis variable, when set to @samp{on}, causes Readline to display an 526136644Sacheasterisk (@samp{*}) at the start of history lines which have been modified. 527136644SacheThis variable is @samp{off} by default. 528136644Sache 529136644Sache@item mark-symlinked-directories 530136644Sache@vindex mark-symlinked-directories 531136644SacheIf set to @samp{on}, completed names which are symbolic links 532136644Sacheto directories have a slash appended (subject to the value of 533136644Sache@code{mark-directories}). 534136644SacheThe default is @samp{off}. 535136644Sache 536136644Sache@item match-hidden-files 537136644Sache@vindex match-hidden-files 538136644SacheThis variable, when set to @samp{on}, causes Readline to match files whose 539136644Sachenames begin with a @samp{.} (hidden files) when performing filename 540136644Sachecompletion, unless the leading @samp{.} is 541136644Sachesupplied by the user in the filename to be completed. 542136644SacheThis variable is @samp{on} by default. 543136644Sache 544136644Sache@item output-meta 545136644Sache@vindex output-meta 546136644SacheIf set to @samp{on}, Readline will display characters with the 547136644Sacheeighth bit set directly rather than as a meta-prefixed escape 548136644Sachesequence. The default is @samp{off}. 549136644Sache 550136644Sache@item page-completions 551136644Sache@vindex page-completions 552136644SacheIf set to @samp{on}, Readline uses an internal @code{more}-like pager 553136644Sacheto display a screenful of possible completions at a time. 554136644SacheThis variable is @samp{on} by default. 555136644Sache 556136644Sache@item print-completions-horizontally 557136644SacheIf set to @samp{on}, Readline will display completions with matches 558136644Sachesorted horizontally in alphabetical order, rather than down the screen. 559136644SacheThe default is @samp{off}. 560136644Sache 561136644Sache@item show-all-if-ambiguous 562136644Sache@vindex show-all-if-ambiguous 563136644SacheThis alters the default behavior of the completion functions. If 564136644Sacheset to @samp{on}, 565136644Sachewords which have more than one possible completion cause the 566136644Sachematches to be listed immediately instead of ringing the bell. 567136644SacheThe default value is @samp{off}. 568136644Sache 569136644Sache@item show-all-if-unmodified 570136644Sache@vindex show-all-if-unmodified 571136644SacheThis alters the default behavior of the completion functions in 572136644Sachea fashion similar to @var{show-all-if-ambiguous}. 573136644SacheIf set to @samp{on}, 574136644Sachewords which have more than one possible completion without any 575136644Sachepossible partial completion (the possible completions don't share 576136644Sachea common prefix) cause the matches to be listed immediately instead 577136644Sacheof ringing the bell. 578136644SacheThe default value is @samp{off}. 579136644Sache 580136644Sache@item visible-stats 581136644Sache@vindex visible-stats 582136644SacheIf set to @samp{on}, a character denoting a file's type 583136644Sacheis appended to the filename when listing possible 584136644Sachecompletions. The default is @samp{off}. 585136644Sache 586136644Sache@end table 587136644Sache 588136644Sache@item Key Bindings 589136644SacheThe syntax for controlling key bindings in the init file is 590136644Sachesimple. First you need to find the name of the command that you 591136644Sachewant to change. The following sections contain tables of the command 592136644Sachename, the default keybinding, if any, and a short description of what 593136644Sachethe command does. 594136644Sache 595136644SacheOnce you know the name of the command, simply place on a line 596136644Sachein the init file the name of the key 597136644Sacheyou wish to bind the command to, a colon, and then the name of the 598165670Sachecommand. 599165670SacheThere can be no space between the key name and the colon -- that will be 600165670Sacheinterpreted as part of the key name. 601165670SacheThe name of the key can be expressed in different ways, depending on 602165670Sachewhat you find most comfortable. 603136644Sache 604136644SacheIn addition to command names, readline allows keys to be bound 605136644Sacheto a string that is inserted when the key is pressed (a @var{macro}). 606136644Sache 607136644Sache@ifset BashFeatures 608136644SacheThe @w{@code{bind -p}} command displays Readline function names and 609136644Sachebindings in a format that can put directly into an initialization file. 610136644Sache@xref{Bash Builtins}. 611136644Sache@end ifset 612136644Sache 613136644Sache@table @asis 614136644Sache@item @w{@var{keyname}: @var{function-name} or @var{macro}} 615136644Sache@var{keyname} is the name of a key spelled out in English. For example: 616136644Sache@example 617136644SacheControl-u: universal-argument 618136644SacheMeta-Rubout: backward-kill-word 619136644SacheControl-o: "> output" 620136644Sache@end example 621136644Sache 622136644SacheIn the above example, @kbd{C-u} is bound to the function 623136644Sache@code{universal-argument}, 624136644Sache@kbd{M-DEL} is bound to the function @code{backward-kill-word}, and 625136644Sache@kbd{C-o} is bound to run the macro 626136644Sacheexpressed on the right hand side (that is, to insert the text 627136644Sache@samp{> output} into the line). 628136644Sache 629136644SacheA number of symbolic character names are recognized while 630136644Sacheprocessing this key binding syntax: 631136644Sache@var{DEL}, 632136644Sache@var{ESC}, 633136644Sache@var{ESCAPE}, 634136644Sache@var{LFD}, 635136644Sache@var{NEWLINE}, 636136644Sache@var{RET}, 637136644Sache@var{RETURN}, 638136644Sache@var{RUBOUT}, 639136644Sache@var{SPACE}, 640136644Sache@var{SPC}, 641136644Sacheand 642136644Sache@var{TAB}. 643136644Sache 644136644Sache@item @w{"@var{keyseq}": @var{function-name} or @var{macro}} 645136644Sache@var{keyseq} differs from @var{keyname} above in that strings 646136644Sachedenoting an entire key sequence can be specified, by placing 647136644Sachethe key sequence in double quotes. Some @sc{gnu} Emacs style key 648136644Sacheescapes can be used, as in the following example, but the 649136644Sachespecial character names are not recognized. 650136644Sache 651136644Sache@example 652136644Sache"\C-u": universal-argument 653136644Sache"\C-x\C-r": re-read-init-file 654136644Sache"\e[11~": "Function Key 1" 655136644Sache@end example 656136644Sache 657136644SacheIn the above example, @kbd{C-u} is again bound to the function 658136644Sache@code{universal-argument} (just as it was in the first example), 659136644Sache@samp{@kbd{C-x} @kbd{C-r}} is bound to the function @code{re-read-init-file}, 660136644Sacheand @samp{@key{ESC} @key{[} @key{1} @key{1} @key{~}} is bound to insert 661136644Sachethe text @samp{Function Key 1}. 662136644Sache 663136644Sache@end table 664136644Sache 665136644SacheThe following @sc{gnu} Emacs style escape sequences are available when 666136644Sachespecifying key sequences: 667136644Sache 668136644Sache@table @code 669136644Sache@item @kbd{\C-} 670136644Sachecontrol prefix 671136644Sache@item @kbd{\M-} 672136644Sachemeta prefix 673136644Sache@item @kbd{\e} 674136644Sachean escape character 675136644Sache@item @kbd{\\} 676136644Sachebackslash 677136644Sache@item @kbd{\"} 678136644Sache@key{"}, a double quotation mark 679136644Sache@item @kbd{\'} 680136644Sache@key{'}, a single quote or apostrophe 681136644Sache@end table 682136644Sache 683136644SacheIn addition to the @sc{gnu} Emacs style escape sequences, a second 684136644Sacheset of backslash escapes is available: 685136644Sache 686136644Sache@table @code 687136644Sache@item \a 688136644Sachealert (bell) 689136644Sache@item \b 690136644Sachebackspace 691136644Sache@item \d 692136644Sachedelete 693136644Sache@item \f 694136644Sacheform feed 695136644Sache@item \n 696136644Sachenewline 697136644Sache@item \r 698136644Sachecarriage return 699136644Sache@item \t 700136644Sachehorizontal tab 701136644Sache@item \v 702136644Sachevertical tab 703136644Sache@item \@var{nnn} 704136644Sachethe eight-bit character whose value is the octal value @var{nnn} 705136644Sache(one to three digits) 706136644Sache@item \x@var{HH} 707136644Sachethe eight-bit character whose value is the hexadecimal value @var{HH} 708136644Sache(one or two hex digits) 709136644Sache@end table 710136644Sache 711136644SacheWhen entering the text of a macro, single or double quotes must 712136644Sachebe used to indicate a macro definition. 713136644SacheUnquoted text is assumed to be a function name. 714136644SacheIn the macro body, the backslash escapes described above are expanded. 715136644SacheBackslash will quote any other character in the macro text, 716136644Sacheincluding @samp{"} and @samp{'}. 717136644SacheFor example, the following binding will make @samp{@kbd{C-x} \} 718136644Sacheinsert a single @samp{\} into the line: 719136644Sache@example 720136644Sache"\C-x\\": "\\" 721136644Sache@end example 722136644Sache 723136644Sache@end table 724136644Sache 725136644Sache@node Conditional Init Constructs 726136644Sache@subsection Conditional Init Constructs 727136644Sache 728136644SacheReadline implements a facility similar in spirit to the conditional 729136644Sachecompilation features of the C preprocessor which allows key 730136644Sachebindings and variable settings to be performed as the result 731136644Sacheof tests. There are four parser directives used. 732136644Sache 733136644Sache@table @code 734136644Sache@item $if 735136644SacheThe @code{$if} construct allows bindings to be made based on the 736136644Sacheediting mode, the terminal being used, or the application using 737136644SacheReadline. The text of the test extends to the end of the line; 738136644Sacheno characters are required to isolate it. 739136644Sache 740136644Sache@table @code 741136644Sache@item mode 742136644SacheThe @code{mode=} form of the @code{$if} directive is used to test 743136644Sachewhether Readline is in @code{emacs} or @code{vi} mode. 744136644SacheThis may be used in conjunction 745136644Sachewith the @samp{set keymap} command, for instance, to set bindings in 746136644Sachethe @code{emacs-standard} and @code{emacs-ctlx} keymaps only if 747136644SacheReadline is starting out in @code{emacs} mode. 748136644Sache 749136644Sache@item term 750136644SacheThe @code{term=} form may be used to include terminal-specific 751136644Sachekey bindings, perhaps to bind the key sequences output by the 752136644Sacheterminal's function keys. The word on the right side of the 753136644Sache@samp{=} is tested against both the full name of the terminal and 754136644Sachethe portion of the terminal name before the first @samp{-}. This 755136644Sacheallows @code{sun} to match both @code{sun} and @code{sun-cmd}, 756136644Sachefor instance. 757136644Sache 758136644Sache@item application 759136644SacheThe @var{application} construct is used to include 760136644Sacheapplication-specific settings. Each program using the Readline 761136644Sachelibrary sets the @var{application name}, and you can test for 762136644Sachea particular value. 763136644SacheThis could be used to bind key sequences to functions useful for 764136644Sachea specific program. For instance, the following command adds a 765136644Sachekey sequence that quotes the current or previous word in Bash: 766136644Sache@example 767136644Sache$if Bash 768136644Sache# Quote the current or previous word 769136644Sache"\C-xq": "\eb\"\ef\"" 770136644Sache$endif 771136644Sache@end example 772136644Sache@end table 773136644Sache 774136644Sache@item $endif 775136644SacheThis command, as seen in the previous example, terminates an 776136644Sache@code{$if} command. 777136644Sache 778136644Sache@item $else 779136644SacheCommands in this branch of the @code{$if} directive are executed if 780136644Sachethe test fails. 781136644Sache 782136644Sache@item $include 783136644SacheThis directive takes a single filename as an argument and reads commands 784136644Sacheand bindings from that file. 785136644SacheFor example, the following directive reads from @file{/etc/inputrc}: 786136644Sache@example 787136644Sache$include /etc/inputrc 788136644Sache@end example 789136644Sache@end table 790136644Sache 791136644Sache@node Sample Init File 792136644Sache@subsection Sample Init File 793136644Sache 794136644SacheHere is an example of an @var{inputrc} file. This illustrates key 795136644Sachebinding, variable assignment, and conditional syntax. 796136644Sache 797136644Sache@example 798136644Sache@page 799136644Sache# This file controls the behaviour of line input editing for 800136644Sache# programs that use the GNU Readline library. Existing 801136644Sache# programs include FTP, Bash, and GDB. 802136644Sache# 803136644Sache# You can re-read the inputrc file with C-x C-r. 804136644Sache# Lines beginning with '#' are comments. 805136644Sache# 806136644Sache# First, include any systemwide bindings and variable 807136644Sache# assignments from /etc/Inputrc 808136644Sache$include /etc/Inputrc 809136644Sache 810136644Sache# 811136644Sache# Set various bindings for emacs mode. 812136644Sache 813136644Sacheset editing-mode emacs 814136644Sache 815136644Sache$if mode=emacs 816136644Sache 817136644SacheMeta-Control-h: backward-kill-word Text after the function name is ignored 818136644Sache 819136644Sache# 820136644Sache# Arrow keys in keypad mode 821136644Sache# 822136644Sache#"\M-OD": backward-char 823136644Sache#"\M-OC": forward-char 824136644Sache#"\M-OA": previous-history 825136644Sache#"\M-OB": next-history 826136644Sache# 827136644Sache# Arrow keys in ANSI mode 828136644Sache# 829136644Sache"\M-[D": backward-char 830136644Sache"\M-[C": forward-char 831136644Sache"\M-[A": previous-history 832136644Sache"\M-[B": next-history 833136644Sache# 834136644Sache# Arrow keys in 8 bit keypad mode 835136644Sache# 836136644Sache#"\M-\C-OD": backward-char 837136644Sache#"\M-\C-OC": forward-char 838136644Sache#"\M-\C-OA": previous-history 839136644Sache#"\M-\C-OB": next-history 840136644Sache# 841136644Sache# Arrow keys in 8 bit ANSI mode 842136644Sache# 843136644Sache#"\M-\C-[D": backward-char 844136644Sache#"\M-\C-[C": forward-char 845136644Sache#"\M-\C-[A": previous-history 846136644Sache#"\M-\C-[B": next-history 847136644Sache 848136644SacheC-q: quoted-insert 849136644Sache 850136644Sache$endif 851136644Sache 852136644Sache# An old-style binding. This happens to be the default. 853136644SacheTAB: complete 854136644Sache 855136644Sache# Macros that are convenient for shell interaction 856136644Sache$if Bash 857136644Sache# edit the path 858136644Sache"\C-xp": "PATH=$@{PATH@}\e\C-e\C-a\ef\C-f" 859136644Sache# prepare to type a quoted word -- 860136644Sache# insert open and close double quotes 861136644Sache# and move to just after the open quote 862136644Sache"\C-x\"": "\"\"\C-b" 863136644Sache# insert a backslash (testing backslash escapes 864136644Sache# in sequences and macros) 865136644Sache"\C-x\\": "\\" 866136644Sache# Quote the current or previous word 867136644Sache"\C-xq": "\eb\"\ef\"" 868136644Sache# Add a binding to refresh the line, which is unbound 869136644Sache"\C-xr": redraw-current-line 870136644Sache# Edit variable on current line. 871136644Sache"\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y=" 872136644Sache$endif 873136644Sache 874136644Sache# use a visible bell if one is available 875136644Sacheset bell-style visible 876136644Sache 877136644Sache# don't strip characters to 7 bits when reading 878136644Sacheset input-meta on 879136644Sache 880136644Sache# allow iso-latin1 characters to be inserted rather 881136644Sache# than converted to prefix-meta sequences 882136644Sacheset convert-meta off 883136644Sache 884136644Sache# display characters with the eighth bit set directly 885136644Sache# rather than as meta-prefixed characters 886136644Sacheset output-meta on 887136644Sache 888136644Sache# if there are more than 150 possible completions for 889136644Sache# a word, ask the user if he wants to see all of them 890136644Sacheset completion-query-items 150 891136644Sache 892136644Sache# For FTP 893136644Sache$if Ftp 894136644Sache"\C-xg": "get \M-?" 895136644Sache"\C-xt": "put \M-?" 896136644Sache"\M-.": yank-last-arg 897136644Sache$endif 898136644Sache@end example 899136644Sache 900136644Sache@node Bindable Readline Commands 901136644Sache@section Bindable Readline Commands 902136644Sache 903136644Sache@menu 904136644Sache* Commands For Moving:: Moving about the line. 905136644Sache* Commands For History:: Getting at previous lines. 906136644Sache* Commands For Text:: Commands for changing text. 907136644Sache* Commands For Killing:: Commands for killing and yanking. 908136644Sache* Numeric Arguments:: Specifying numeric arguments, repeat counts. 909136644Sache* Commands For Completion:: Getting Readline to do the typing for you. 910136644Sache* Keyboard Macros:: Saving and re-executing typed characters 911136644Sache* Miscellaneous Commands:: Other miscellaneous commands. 912136644Sache@end menu 913136644Sache 914136644SacheThis section describes Readline commands that may be bound to key 915136644Sachesequences. 916136644Sache@ifset BashFeatures 917136644SacheYou can list your key bindings by executing 918136644Sache@w{@code{bind -P}} or, for a more terse format, suitable for an 919136644Sache@var{inputrc} file, @w{@code{bind -p}}. (@xref{Bash Builtins}.) 920136644Sache@end ifset 921136644SacheCommand names without an accompanying key sequence are unbound by default. 922136644Sache 923136644SacheIn the following descriptions, @dfn{point} refers to the current cursor 924136644Sacheposition, and @dfn{mark} refers to a cursor position saved by the 925136644Sache@code{set-mark} command. 926136644SacheThe text between the point and mark is referred to as the @dfn{region}. 927136644Sache 928136644Sache@node Commands For Moving 929136644Sache@subsection Commands For Moving 930136644Sache@ftable @code 931136644Sache@item beginning-of-line (C-a) 932136644SacheMove to the start of the current line. 933136644Sache 934136644Sache@item end-of-line (C-e) 935136644SacheMove to the end of the line. 936136644Sache 937136644Sache@item forward-char (C-f) 938136644SacheMove forward a character. 939136644Sache 940136644Sache@item backward-char (C-b) 941136644SacheMove back a character. 942136644Sache 943136644Sache@item forward-word (M-f) 944136644SacheMove forward to the end of the next word. Words are composed of 945136644Sacheletters and digits. 946136644Sache 947136644Sache@item backward-word (M-b) 948136644SacheMove back to the start of the current or previous word. Words are 949136644Sachecomposed of letters and digits. 950136644Sache 951136644Sache@item clear-screen (C-l) 952136644SacheClear the screen and redraw the current line, 953136644Sacheleaving the current line at the top of the screen. 954136644Sache 955136644Sache@item redraw-current-line () 956136644SacheRefresh the current line. By default, this is unbound. 957136644Sache 958136644Sache@end ftable 959136644Sache 960136644Sache@node Commands For History 961136644Sache@subsection Commands For Manipulating The History 962136644Sache 963136644Sache@ftable @code 964136644Sache@item accept-line (Newline or Return) 965136644Sache@ifset BashFeatures 966136644SacheAccept the line regardless of where the cursor is. 967136644SacheIf this line is 968136644Sachenon-empty, add it to the history list according to the setting of 969136644Sachethe @env{HISTCONTROL} and @env{HISTIGNORE} variables. 970136644SacheIf this line is a modified history line, then restore the history line 971136644Sacheto its original state. 972136644Sache@end ifset 973136644Sache@ifclear BashFeatures 974136644SacheAccept the line regardless of where the cursor is. 975136644SacheIf this line is 976136644Sachenon-empty, it may be added to the history list for future recall with 977136644Sache@code{add_history()}. 978136644SacheIf this line is a modified history line, the history line is restored 979136644Sacheto its original state. 980136644Sache@end ifclear 981136644Sache 982136644Sache@item previous-history (C-p) 983136644SacheMove `back' through the history list, fetching the previous command. 984136644Sache 985136644Sache@item next-history (C-n) 986136644SacheMove `forward' through the history list, fetching the next command. 987136644Sache 988136644Sache@item beginning-of-history (M-<) 989136644SacheMove to the first line in the history. 990136644Sache 991136644Sache@item end-of-history (M->) 992136644SacheMove to the end of the input history, i.e., the line currently 993136644Sachebeing entered. 994136644Sache 995136644Sache@item reverse-search-history (C-r) 996136644SacheSearch backward starting at the current line and moving `up' through 997136644Sachethe history as necessary. This is an incremental search. 998136644Sache 999136644Sache@item forward-search-history (C-s) 1000136644SacheSearch forward starting at the current line and moving `down' through 1001136644Sachethe the history as necessary. This is an incremental search. 1002136644Sache 1003136644Sache@item non-incremental-reverse-search-history (M-p) 1004136644SacheSearch backward starting at the current line and moving `up' 1005136644Sachethrough the history as necessary using a non-incremental search 1006136644Sachefor a string supplied by the user. 1007136644Sache 1008136644Sache@item non-incremental-forward-search-history (M-n) 1009136644SacheSearch forward starting at the current line and moving `down' 1010136644Sachethrough the the history as necessary using a non-incremental search 1011136644Sachefor a string supplied by the user. 1012136644Sache 1013136644Sache@item history-search-forward () 1014136644SacheSearch forward through the history for the string of characters 1015136644Sachebetween the start of the current line and the point. 1016136644SacheThis is a non-incremental search. 1017136644SacheBy default, this command is unbound. 1018136644Sache 1019136644Sache@item history-search-backward () 1020136644SacheSearch backward through the history for the string of characters 1021136644Sachebetween the start of the current line and the point. This 1022136644Sacheis a non-incremental search. By default, this command is unbound. 1023136644Sache 1024136644Sache@item yank-nth-arg (M-C-y) 1025136644SacheInsert the first argument to the previous command (usually 1026136644Sachethe second word on the previous line) at point. 1027136644SacheWith an argument @var{n}, 1028136644Sacheinsert the @var{n}th word from the previous command (the words 1029136644Sachein the previous command begin with word 0). A negative argument 1030136644Sacheinserts the @var{n}th word from the end of the previous command. 1031157184SacheOnce the argument @var{n} is computed, the argument is extracted 1032157184Sacheas if the @samp{!@var{n}} history expansion had been specified. 1033136644Sache 1034136644Sache@item yank-last-arg (M-. or M-_) 1035136644SacheInsert last argument to the previous command (the last word of the 1036136644Sacheprevious history entry). With an 1037136644Sacheargument, behave exactly like @code{yank-nth-arg}. 1038136644SacheSuccessive calls to @code{yank-last-arg} move back through the history 1039136644Sachelist, inserting the last argument of each line in turn. 1040157184SacheThe history expansion facilities are used to extract the last argument, 1041157184Sacheas if the @samp{!$} history expansion had been specified. 1042136644Sache 1043136644Sache@end ftable 1044136644Sache 1045136644Sache@node Commands For Text 1046136644Sache@subsection Commands For Changing Text 1047136644Sache 1048136644Sache@ftable @code 1049136644Sache@item delete-char (C-d) 1050136644SacheDelete the character at point. If point is at the 1051136644Sachebeginning of the line, there are no characters in the line, and 1052136644Sachethe last character typed was not bound to @code{delete-char}, then 1053136644Sachereturn @sc{eof}. 1054136644Sache 1055136644Sache@item backward-delete-char (Rubout) 1056136644SacheDelete the character behind the cursor. A numeric argument means 1057136644Sacheto kill the characters instead of deleting them. 1058136644Sache 1059136644Sache@item forward-backward-delete-char () 1060136644SacheDelete the character under the cursor, unless the cursor is at the 1061136644Sacheend of the line, in which case the character behind the cursor is 1062136644Sachedeleted. By default, this is not bound to a key. 1063136644Sache 1064136644Sache@item quoted-insert (C-q or C-v) 1065136644SacheAdd the next character typed to the line verbatim. This is 1066136644Sachehow to insert key sequences like @kbd{C-q}, for example. 1067136644Sache 1068136644Sache@ifclear BashFeatures 1069136644Sache@item tab-insert (M-@key{TAB}) 1070136644SacheInsert a tab character. 1071136644Sache@end ifclear 1072136644Sache 1073136644Sache@item self-insert (a, b, A, 1, !, @dots{}) 1074136644SacheInsert yourself. 1075136644Sache 1076136644Sache@item transpose-chars (C-t) 1077136644SacheDrag the character before the cursor forward over 1078136644Sachethe character at the cursor, moving the 1079136644Sachecursor forward as well. If the insertion point 1080136644Sacheis at the end of the line, then this 1081136644Sachetransposes the last two characters of the line. 1082136644SacheNegative arguments have no effect. 1083136644Sache 1084136644Sache@item transpose-words (M-t) 1085136644SacheDrag the word before point past the word after point, 1086136644Sachemoving point past that word as well. 1087136644SacheIf the insertion point is at the end of the line, this transposes 1088136644Sachethe last two words on the line. 1089136644Sache 1090136644Sache@item upcase-word (M-u) 1091136644SacheUppercase the current (or following) word. With a negative argument, 1092136644Sacheuppercase the previous word, but do not move the cursor. 1093136644Sache 1094136644Sache@item downcase-word (M-l) 1095136644SacheLowercase the current (or following) word. With a negative argument, 1096136644Sachelowercase the previous word, but do not move the cursor. 1097136644Sache 1098136644Sache@item capitalize-word (M-c) 1099136644SacheCapitalize the current (or following) word. With a negative argument, 1100136644Sachecapitalize the previous word, but do not move the cursor. 1101136644Sache 1102136644Sache@item overwrite-mode () 1103136644SacheToggle overwrite mode. With an explicit positive numeric argument, 1104136644Sacheswitches to overwrite mode. With an explicit non-positive numeric 1105136644Sacheargument, switches to insert mode. This command affects only 1106136644Sache@code{emacs} mode; @code{vi} mode does overwrite differently. 1107136644SacheEach call to @code{readline()} starts in insert mode. 1108136644Sache 1109136644SacheIn overwrite mode, characters bound to @code{self-insert} replace 1110136644Sachethe text at point rather than pushing the text to the right. 1111136644SacheCharacters bound to @code{backward-delete-char} replace the character 1112136644Sachebefore point with a space. 1113136644Sache 1114136644SacheBy default, this command is unbound. 1115136644Sache 1116136644Sache@end ftable 1117136644Sache 1118136644Sache@node Commands For Killing 1119136644Sache@subsection Killing And Yanking 1120136644Sache 1121136644Sache@ftable @code 1122136644Sache 1123136644Sache@item kill-line (C-k) 1124136644SacheKill the text from point to the end of the line. 1125136644Sache 1126136644Sache@item backward-kill-line (C-x Rubout) 1127136644SacheKill backward to the beginning of the line. 1128136644Sache 1129136644Sache@item unix-line-discard (C-u) 1130136644SacheKill backward from the cursor to the beginning of the current line. 1131136644Sache 1132136644Sache@item kill-whole-line () 1133136644SacheKill all characters on the current line, no matter where point is. 1134136644SacheBy default, this is unbound. 1135136644Sache 1136136644Sache@item kill-word (M-d) 1137136644SacheKill from point to the end of the current word, or if between 1138136644Sachewords, to the end of the next word. 1139136644SacheWord boundaries are the same as @code{forward-word}. 1140136644Sache 1141136644Sache@item backward-kill-word (M-@key{DEL}) 1142136644SacheKill the word behind point. 1143136644SacheWord boundaries are the same as @code{backward-word}. 1144136644Sache 1145136644Sache@item unix-word-rubout (C-w) 1146136644SacheKill the word behind point, using white space as a word boundary. 1147136644SacheThe killed text is saved on the kill-ring. 1148136644Sache 1149136644Sache@item unix-filename-rubout () 1150136644SacheKill the word behind point, using white space and the slash character 1151136644Sacheas the word boundaries. 1152136644SacheThe killed text is saved on the kill-ring. 1153136644Sache 1154136644Sache@item delete-horizontal-space () 1155136644SacheDelete all spaces and tabs around point. By default, this is unbound. 1156136644Sache 1157136644Sache@item kill-region () 1158136644SacheKill the text in the current region. 1159136644SacheBy default, this command is unbound. 1160136644Sache 1161136644Sache@item copy-region-as-kill () 1162136644SacheCopy the text in the region to the kill buffer, so it can be yanked 1163136644Sacheright away. By default, this command is unbound. 1164136644Sache 1165136644Sache@item copy-backward-word () 1166136644SacheCopy the word before point to the kill buffer. 1167136644SacheThe word boundaries are the same as @code{backward-word}. 1168136644SacheBy default, this command is unbound. 1169136644Sache 1170136644Sache@item copy-forward-word () 1171136644SacheCopy the word following point to the kill buffer. 1172136644SacheThe word boundaries are the same as @code{forward-word}. 1173136644SacheBy default, this command is unbound. 1174136644Sache 1175136644Sache@item yank (C-y) 1176136644SacheYank the top of the kill ring into the buffer at point. 1177136644Sache 1178136644Sache@item yank-pop (M-y) 1179136644SacheRotate the kill-ring, and yank the new top. You can only do this if 1180136644Sachethe prior command is @code{yank} or @code{yank-pop}. 1181136644Sache@end ftable 1182136644Sache 1183136644Sache@node Numeric Arguments 1184136644Sache@subsection Specifying Numeric Arguments 1185136644Sache@ftable @code 1186136644Sache 1187136644Sache@item digit-argument (@kbd{M-0}, @kbd{M-1}, @dots{} @kbd{M--}) 1188136644SacheAdd this digit to the argument already accumulating, or start a new 1189136644Sacheargument. @kbd{M--} starts a negative argument. 1190136644Sache 1191136644Sache@item universal-argument () 1192136644SacheThis is another way to specify an argument. 1193136644SacheIf this command is followed by one or more digits, optionally with a 1194136644Sacheleading minus sign, those digits define the argument. 1195136644SacheIf the command is followed by digits, executing @code{universal-argument} 1196136644Sacheagain ends the numeric argument, but is otherwise ignored. 1197136644SacheAs a special case, if this command is immediately followed by a 1198136644Sachecharacter that is neither a digit or minus sign, the argument count 1199136644Sachefor the next command is multiplied by four. 1200136644SacheThe argument count is initially one, so executing this function the 1201136644Sachefirst time makes the argument count four, a second time makes the 1202136644Sacheargument count sixteen, and so on. 1203136644SacheBy default, this is not bound to a key. 1204136644Sache@end ftable 1205136644Sache 1206136644Sache@node Commands For Completion 1207136644Sache@subsection Letting Readline Type For You 1208136644Sache 1209136644Sache@ftable @code 1210136644Sache@item complete (@key{TAB}) 1211136644SacheAttempt to perform completion on the text before point. 1212136644SacheThe actual completion performed is application-specific. 1213136644Sache@ifset BashFeatures 1214136644SacheBash attempts completion treating the text as a variable (if the 1215136644Sachetext begins with @samp{$}), username (if the text begins with 1216136644Sache@samp{~}), hostname (if the text begins with @samp{@@}), or 1217136644Sachecommand (including aliases and functions) in turn. If none 1218136644Sacheof these produces a match, filename completion is attempted. 1219136644Sache@end ifset 1220136644Sache@ifclear BashFeatures 1221136644SacheThe default is filename completion. 1222136644Sache@end ifclear 1223136644Sache 1224136644Sache@item possible-completions (M-?) 1225136644SacheList the possible completions of the text before point. 1226136644Sache 1227136644Sache@item insert-completions (M-*) 1228136644SacheInsert all completions of the text before point that would have 1229136644Sachebeen generated by @code{possible-completions}. 1230136644Sache 1231136644Sache@item menu-complete () 1232136644SacheSimilar to @code{complete}, but replaces the word to be completed 1233136644Sachewith a single match from the list of possible completions. 1234136644SacheRepeated execution of @code{menu-complete} steps through the list 1235136644Sacheof possible completions, inserting each match in turn. 1236136644SacheAt the end of the list of completions, the bell is rung 1237136644Sache(subject to the setting of @code{bell-style}) 1238136644Sacheand the original text is restored. 1239136644SacheAn argument of @var{n} moves @var{n} positions forward in the list 1240136644Sacheof matches; a negative argument may be used to move backward 1241136644Sachethrough the list. 1242136644SacheThis command is intended to be bound to @key{TAB}, but is unbound 1243136644Sacheby default. 1244136644Sache 1245136644Sache@item delete-char-or-list () 1246136644SacheDeletes the character under the cursor if not at the beginning or 1247136644Sacheend of the line (like @code{delete-char}). 1248136644SacheIf at the end of the line, behaves identically to 1249136644Sache@code{possible-completions}. 1250136644SacheThis command is unbound by default. 1251136644Sache 1252136644Sache@ifset BashFeatures 1253136644Sache@item complete-filename (M-/) 1254136644SacheAttempt filename completion on the text before point. 1255136644Sache 1256136644Sache@item possible-filename-completions (C-x /) 1257136644SacheList the possible completions of the text before point, 1258136644Sachetreating it as a filename. 1259136644Sache 1260136644Sache@item complete-username (M-~) 1261136644SacheAttempt completion on the text before point, treating 1262136644Sacheit as a username. 1263136644Sache 1264136644Sache@item possible-username-completions (C-x ~) 1265136644SacheList the possible completions of the text before point, 1266136644Sachetreating it as a username. 1267136644Sache 1268136644Sache@item complete-variable (M-$) 1269136644SacheAttempt completion on the text before point, treating 1270136644Sacheit as a shell variable. 1271136644Sache 1272136644Sache@item possible-variable-completions (C-x $) 1273136644SacheList the possible completions of the text before point, 1274136644Sachetreating it as a shell variable. 1275136644Sache 1276136644Sache@item complete-hostname (M-@@) 1277136644SacheAttempt completion on the text before point, treating 1278136644Sacheit as a hostname. 1279136644Sache 1280136644Sache@item possible-hostname-completions (C-x @@) 1281136644SacheList the possible completions of the text before point, 1282136644Sachetreating it as a hostname. 1283136644Sache 1284136644Sache@item complete-command (M-!) 1285136644SacheAttempt completion on the text before point, treating 1286136644Sacheit as a command name. Command completion attempts to 1287136644Sachematch the text against aliases, reserved words, shell 1288136644Sachefunctions, shell builtins, and finally executable filenames, 1289136644Sachein that order. 1290136644Sache 1291136644Sache@item possible-command-completions (C-x !) 1292136644SacheList the possible completions of the text before point, 1293136644Sachetreating it as a command name. 1294136644Sache 1295136644Sache@item dynamic-complete-history (M-@key{TAB}) 1296136644SacheAttempt completion on the text before point, comparing 1297136644Sachethe text against lines from the history list for possible 1298136644Sachecompletion matches. 1299136644Sache 1300136644Sache@item complete-into-braces (M-@{) 1301136644SachePerform filename completion and insert the list of possible completions 1302136644Sacheenclosed within braces so the list is available to the shell 1303136644Sache(@pxref{Brace Expansion}). 1304136644Sache 1305136644Sache@end ifset 1306136644Sache@end ftable 1307136644Sache 1308136644Sache@node Keyboard Macros 1309136644Sache@subsection Keyboard Macros 1310136644Sache@ftable @code 1311136644Sache 1312136644Sache@item start-kbd-macro (C-x () 1313136644SacheBegin saving the characters typed into the current keyboard macro. 1314136644Sache 1315136644Sache@item end-kbd-macro (C-x )) 1316136644SacheStop saving the characters typed into the current keyboard macro 1317136644Sacheand save the definition. 1318136644Sache 1319136644Sache@item call-last-kbd-macro (C-x e) 1320136644SacheRe-execute the last keyboard macro defined, by making the characters 1321136644Sachein the macro appear as if typed at the keyboard. 1322136644Sache 1323136644Sache@end ftable 1324136644Sache 1325136644Sache@node Miscellaneous Commands 1326136644Sache@subsection Some Miscellaneous Commands 1327136644Sache@ftable @code 1328136644Sache 1329136644Sache@item re-read-init-file (C-x C-r) 1330136644SacheRead in the contents of the @var{inputrc} file, and incorporate 1331136644Sacheany bindings or variable assignments found there. 1332136644Sache 1333136644Sache@item abort (C-g) 1334136644SacheAbort the current editing command and 1335136644Sachering the terminal's bell (subject to the setting of 1336136644Sache@code{bell-style}). 1337136644Sache 1338136644Sache@item do-uppercase-version (M-a, M-b, M-@var{x}, @dots{}) 1339136644SacheIf the metafied character @var{x} is lowercase, run the command 1340136644Sachethat is bound to the corresponding uppercase character. 1341136644Sache 1342136644Sache@item prefix-meta (@key{ESC}) 1343136644SacheMetafy the next character typed. This is for keyboards 1344136644Sachewithout a meta key. Typing @samp{@key{ESC} f} is equivalent to typing 1345136644Sache@kbd{M-f}. 1346136644Sache 1347136644Sache@item undo (C-_ or C-x C-u) 1348136644SacheIncremental undo, separately remembered for each line. 1349136644Sache 1350136644Sache@item revert-line (M-r) 1351136644SacheUndo all changes made to this line. This is like executing the @code{undo} 1352136644Sachecommand enough times to get back to the beginning. 1353136644Sache 1354136644Sache@ifset BashFeatures 1355136644Sache@item tilde-expand (M-&) 1356136644Sache@end ifset 1357136644Sache@ifclear BashFeatures 1358136644Sache@item tilde-expand (M-~) 1359136644Sache@end ifclear 1360136644SachePerform tilde expansion on the current word. 1361136644Sache 1362136644Sache@item set-mark (C-@@) 1363136644SacheSet the mark to the point. If a 1364136644Sachenumeric argument is supplied, the mark is set to that position. 1365136644Sache 1366136644Sache@item exchange-point-and-mark (C-x C-x) 1367136644SacheSwap the point with the mark. The current cursor position is set to 1368136644Sachethe saved position, and the old cursor position is saved as the mark. 1369136644Sache 1370136644Sache@item character-search (C-]) 1371136644SacheA character is read and point is moved to the next occurrence of that 1372136644Sachecharacter. A negative count searches for previous occurrences. 1373136644Sache 1374136644Sache@item character-search-backward (M-C-]) 1375136644SacheA character is read and point is moved to the previous occurrence 1376136644Sacheof that character. A negative count searches for subsequent 1377136644Sacheoccurrences. 1378136644Sache 1379136644Sache@item insert-comment (M-#) 1380136644SacheWithout a numeric argument, the value of the @code{comment-begin} 1381136644Sachevariable is inserted at the beginning of the current line. 1382136644SacheIf a numeric argument is supplied, this command acts as a toggle: if 1383136644Sachethe characters at the beginning of the line do not match the value 1384136644Sacheof @code{comment-begin}, the value is inserted, otherwise 1385136644Sachethe characters in @code{comment-begin} are deleted from the beginning of 1386136644Sachethe line. 1387136644SacheIn either case, the line is accepted as if a newline had been typed. 1388136644Sache@ifset BashFeatures 1389136644SacheThe default value of @code{comment-begin} causes this command 1390136644Sacheto make the current line a shell comment. 1391136644SacheIf a numeric argument causes the comment character to be removed, the line 1392136644Sachewill be executed by the shell. 1393136644Sache@end ifset 1394136644Sache 1395136644Sache@item dump-functions () 1396136644SachePrint all of the functions and their key bindings to the 1397136644SacheReadline output stream. If a numeric argument is supplied, 1398136644Sachethe output is formatted in such a way that it can be made part 1399136644Sacheof an @var{inputrc} file. This command is unbound by default. 1400136644Sache 1401136644Sache@item dump-variables () 1402136644SachePrint all of the settable variables and their values to the 1403136644SacheReadline output stream. If a numeric argument is supplied, 1404136644Sachethe output is formatted in such a way that it can be made part 1405136644Sacheof an @var{inputrc} file. This command is unbound by default. 1406136644Sache 1407136644Sache@item dump-macros () 1408136644SachePrint all of the Readline key sequences bound to macros and the 1409136644Sachestrings they output. If a numeric argument is supplied, 1410136644Sachethe output is formatted in such a way that it can be made part 1411136644Sacheof an @var{inputrc} file. This command is unbound by default. 1412136644Sache 1413136644Sache@ifset BashFeatures 1414136644Sache@item glob-complete-word (M-g) 1415136644SacheThe word before point is treated as a pattern for pathname expansion, 1416136644Sachewith an asterisk implicitly appended. This pattern is used to 1417136644Sachegenerate a list of matching file names for possible completions. 1418136644Sache 1419136644Sache@item glob-expand-word (C-x *) 1420136644SacheThe word before point is treated as a pattern for pathname expansion, 1421136644Sacheand the list of matching file names is inserted, replacing the word. 1422136644SacheIf a numeric argument is supplied, a @samp{*} is appended before 1423136644Sachepathname expansion. 1424136644Sache 1425136644Sache@item glob-list-expansions (C-x g) 1426136644SacheThe list of expansions that would have been generated by 1427136644Sache@code{glob-expand-word} is displayed, and the line is redrawn. 1428136644SacheIf a numeric argument is supplied, a @samp{*} is appended before 1429136644Sachepathname expansion. 1430136644Sache 1431136644Sache@item display-shell-version (C-x C-v) 1432136644SacheDisplay version information about the current instance of Bash. 1433136644Sache 1434136644Sache@item shell-expand-line (M-C-e) 1435136644SacheExpand the line as the shell does. 1436136644SacheThis performs alias and history expansion as well as all of the shell 1437136644Sacheword expansions (@pxref{Shell Expansions}). 1438136644Sache 1439136644Sache@item history-expand-line (M-^) 1440136644SachePerform history expansion on the current line. 1441136644Sache 1442136644Sache@item magic-space () 1443136644SachePerform history expansion on the current line and insert a space 1444136644Sache(@pxref{History Interaction}). 1445136644Sache 1446136644Sache@item alias-expand-line () 1447136644SachePerform alias expansion on the current line (@pxref{Aliases}). 1448136644Sache 1449136644Sache@item history-and-alias-expand-line () 1450136644SachePerform history and alias expansion on the current line. 1451136644Sache 1452136644Sache@item insert-last-argument (M-. or M-_) 1453136644SacheA synonym for @code{yank-last-arg}. 1454136644Sache 1455136644Sache@item operate-and-get-next (C-o) 1456136644SacheAccept the current line for execution and fetch the next line 1457136644Sacherelative to the current line from the history for editing. Any 1458136644Sacheargument is ignored. 1459136644Sache 1460136644Sache@item edit-and-execute-command (C-xC-e) 1461136644SacheInvoke an editor on the current command line, and execute the result as shell 1462136644Sachecommands. 1463136644SacheBash attempts to invoke 1464136644Sache@code{$VISUAL}, @code{$EDITOR}, and @code{emacs} 1465136644Sacheas the editor, in that order. 1466136644Sache 1467136644Sache@end ifset 1468136644Sache 1469136644Sache@ifclear BashFeatures 1470136644Sache@item emacs-editing-mode (C-e) 1471136644SacheWhen in @code{vi} command mode, this causes a switch to @code{emacs} 1472136644Sacheediting mode. 1473136644Sache 1474136644Sache@item vi-editing-mode (M-C-j) 1475136644SacheWhen in @code{emacs} editing mode, this causes a switch to @code{vi} 1476136644Sacheediting mode. 1477136644Sache 1478136644Sache@end ifclear 1479136644Sache 1480136644Sache@end ftable 1481136644Sache 1482136644Sache@node Readline vi Mode 1483136644Sache@section Readline vi Mode 1484136644Sache 1485136644SacheWhile the Readline library does not have a full set of @code{vi} 1486136644Sacheediting functions, it does contain enough to allow simple editing 1487136644Sacheof the line. The Readline @code{vi} mode behaves as specified in 1488136644Sachethe @sc{posix} 1003.2 standard. 1489136644Sache 1490136644Sache@ifset BashFeatures 1491136644SacheIn order to switch interactively between @code{emacs} and @code{vi} 1492136644Sacheediting modes, use the @samp{set -o emacs} and @samp{set -o vi} 1493136644Sachecommands (@pxref{The Set Builtin}). 1494136644Sache@end ifset 1495136644Sache@ifclear BashFeatures 1496136644SacheIn order to switch interactively between @code{emacs} and @code{vi} 1497136644Sacheediting modes, use the command @kbd{M-C-j} (bound to emacs-editing-mode 1498136644Sachewhen in @code{vi} mode and to vi-editing-mode in @code{emacs} mode). 1499136644Sache@end ifclear 1500136644SacheThe Readline default is @code{emacs} mode. 1501136644Sache 1502136644SacheWhen you enter a line in @code{vi} mode, you are already placed in 1503136644Sache`insertion' mode, as if you had typed an @samp{i}. Pressing @key{ESC} 1504136644Sacheswitches you into `command' mode, where you can edit the text of the 1505136644Sacheline with the standard @code{vi} movement keys, move to previous 1506136644Sachehistory lines with @samp{k} and subsequent lines with @samp{j}, and 1507136644Sacheso forth. 1508136644Sache 1509136644Sache@ifset BashFeatures 1510136644Sache@node Programmable Completion 1511136644Sache@section Programmable Completion 1512136644Sache@cindex programmable completion 1513136644Sache 1514136644SacheWhen word completion is attempted for an argument to a command for 1515136644Sachewhich a completion specification (a @var{compspec}) has been defined 1516136644Sacheusing the @code{complete} builtin (@pxref{Programmable Completion Builtins}), 1517136644Sachethe programmable completion facilities are invoked. 1518136644Sache 1519136644SacheFirst, the command name is identified. 1520136644SacheIf a compspec has been defined for that command, the 1521136644Sachecompspec is used to generate the list of possible completions for the word. 1522136644SacheIf the command word is a full pathname, a compspec for the full 1523136644Sachepathname is searched for first. 1524136644SacheIf no compspec is found for the full pathname, an attempt is made to 1525136644Sachefind a compspec for the portion following the final slash. 1526136644Sache 1527136644SacheOnce a compspec has been found, it is used to generate the list of 1528136644Sachematching words. 1529136644SacheIf a compspec is not found, the default Bash completion 1530136644Sachedescribed above (@pxref{Commands For Completion}) is performed. 1531136644Sache 1532136644SacheFirst, the actions specified by the compspec are used. 1533136644SacheOnly matches which are prefixed by the word being completed are 1534136644Sachereturned. 1535136644SacheWhen the @option{-f} or @option{-d} option is used for filename or 1536136644Sachedirectory name completion, the shell variable @env{FIGNORE} is 1537136644Sacheused to filter the matches. 1538136644Sache@xref{Bash Variables}, for a description of @env{FIGNORE}. 1539136644Sache 1540136644SacheAny completions specified by a filename expansion pattern to the 1541136644Sache@option{-G} option are generated next. 1542136644SacheThe words generated by the pattern need not match the word being completed. 1543136644SacheThe @env{GLOBIGNORE} shell variable is not used to filter the matches, 1544136644Sachebut the @env{FIGNORE} shell variable is used. 1545136644Sache 1546136644SacheNext, the string specified as the argument to the @option{-W} option 1547136644Sacheis considered. 1548136644SacheThe string is first split using the characters in the @env{IFS} 1549136644Sachespecial variable as delimiters. 1550136644SacheShell quoting is honored. 1551136644SacheEach word is then expanded using 1552136644Sachebrace expansion, tilde expansion, parameter and variable expansion, 1553157184Sachecommand substitution, and arithmetic expansion, 1554136644Sacheas described above (@pxref{Shell Expansions}). 1555136644SacheThe results are split using the rules described above 1556136644Sache(@pxref{Word Splitting}). 1557136644SacheThe results of the expansion are prefix-matched against the word being 1558136644Sachecompleted, and the matching words become the possible completions. 1559136644Sache 1560136644SacheAfter these matches have been generated, any shell function or command 1561136644Sachespecified with the @option{-F} and @option{-C} options is invoked. 1562136644SacheWhen the command or function is invoked, the @env{COMP_LINE} and 1563136644Sache@env{COMP_POINT} variables are assigned values as described above 1564136644Sache(@pxref{Bash Variables}). 1565136644SacheIf a shell function is being invoked, the @env{COMP_WORDS} and 1566136644Sache@env{COMP_CWORD} variables are also set. 1567136644SacheWhen the function or command is invoked, the first argument is the 1568136644Sachename of the command whose arguments are being completed, the 1569136644Sachesecond argument is the word being completed, and the third argument 1570136644Sacheis the word preceding the word being completed on the current command line. 1571136644SacheNo filtering of the generated completions against the word being completed 1572136644Sacheis performed; the function or command has complete freedom in generating 1573136644Sachethe matches. 1574136644Sache 1575136644SacheAny function specified with @option{-F} is invoked first. 1576136644SacheThe function may use any of the shell facilities, including the 1577136644Sache@code{compgen} builtin described below 1578136644Sache(@pxref{Programmable Completion Builtins}), to generate the matches. 1579136644SacheIt must put the possible completions in the @env{COMPREPLY} array 1580136644Sachevariable. 1581136644Sache 1582136644SacheNext, any command specified with the @option{-C} option is invoked 1583136644Sachein an environment equivalent to command substitution. 1584136644SacheIt should print a list of completions, one per line, to 1585136644Sachethe standard output. 1586136644SacheBackslash may be used to escape a newline, if necessary. 1587136644Sache 1588136644SacheAfter all of the possible completions are generated, any filter 1589136644Sachespecified with the @option{-X} option is applied to the list. 1590136644SacheThe filter is a pattern as used for pathname expansion; a @samp{&} 1591136644Sachein the pattern is replaced with the text of the word being completed. 1592136644SacheA literal @samp{&} may be escaped with a backslash; the backslash 1593136644Sacheis removed before attempting a match. 1594136644SacheAny completion that matches the pattern will be removed from the list. 1595136644SacheA leading @samp{!} negates the pattern; in this case any completion 1596136644Sachenot matching the pattern will be removed. 1597136644Sache 1598136644SacheFinally, any prefix and suffix specified with the @option{-P} and @option{-S} 1599136644Sacheoptions are added to each member of the completion list, and the result is 1600136644Sachereturned to the Readline completion code as the list of possible 1601136644Sachecompletions. 1602136644Sache 1603136644SacheIf the previously-applied actions do not generate any matches, and the 1604136644Sache@option{-o dirnames} option was supplied to @code{complete} when the 1605136644Sachecompspec was defined, directory name completion is attempted. 1606136644Sache 1607136644SacheIf the @option{-o plusdirs} option was supplied to @code{complete} when 1608136644Sachethe compspec was defined, directory name completion is attempted and any 1609136644Sachematches are added to the results of the other actions. 1610136644Sache 1611136644SacheBy default, if a compspec is found, whatever it generates is returned to 1612136644Sachethe completion code as the full set of possible completions. 1613136644SacheThe default Bash completions are not attempted, and the Readline default 1614136644Sacheof filename completion is disabled. 1615136644SacheIf the @option{-o bashdefault} option was supplied to @code{complete} when 1616136644Sachethe compspec was defined, the default Bash completions are attempted 1617136644Sacheif the compspec generates no matches. 1618136644SacheIf the @option{-o default} option was supplied to @code{complete} when the 1619136644Sachecompspec was defined, Readline's default completion will be performed 1620136644Sacheif the compspec (and, if attempted, the default Bash completions) 1621136644Sachegenerate no matches. 1622136644Sache 1623136644SacheWhen a compspec indicates that directory name completion is desired, 1624136644Sachethe programmable completion functions force Readline to append a slash 1625136644Sacheto completed names which are symbolic links to directories, subject to 1626136644Sachethe value of the @var{mark-directories} Readline variable, regardless 1627136644Sacheof the setting of the @var{mark-symlinked-directories} Readline variable. 1628136644Sache 1629136644Sache@node Programmable Completion Builtins 1630136644Sache@section Programmable Completion Builtins 1631136644Sache@cindex completion builtins 1632136644Sache 1633136644SacheTwo builtin commands are available to manipulate the programmable completion 1634136644Sachefacilities. 1635136644Sache 1636136644Sache@table @code 1637136644Sache@item compgen 1638136644Sache@btindex compgen 1639136644Sache@example 1640136644Sache@code{compgen [@var{option}] [@var{word}]} 1641136644Sache@end example 1642136644Sache 1643136644SacheGenerate possible completion matches for @var{word} according to 1644136644Sachethe @var{option}s, which may be any option accepted by the 1645136644Sache@code{complete} 1646136644Sachebuiltin with the exception of @option{-p} and @option{-r}, and write 1647136644Sachethe matches to the standard output. 1648136644SacheWhen using the @option{-F} or @option{-C} options, the various shell variables 1649136644Sacheset by the programmable completion facilities, while available, will not 1650136644Sachehave useful values. 1651136644Sache 1652136644SacheThe matches will be generated in the same way as if the programmable 1653136644Sachecompletion code had generated them directly from a completion specification 1654136644Sachewith the same flags. 1655136644SacheIf @var{word} is specified, only those completions matching @var{word} 1656136644Sachewill be displayed. 1657136644Sache 1658136644SacheThe return value is true unless an invalid option is supplied, or no 1659136644Sachematches were generated. 1660136644Sache 1661136644Sache@item complete 1662136644Sache@btindex complete 1663136644Sache@example 1664136644Sache@code{complete [-abcdefgjksuv] [-o @var{comp-option}] [-A @var{action}] [-G @var{globpat}] [-W @var{wordlist}] 1665136644Sache[-P @var{prefix}] [-S @var{suffix}] [-X @var{filterpat}] [-F @var{function}] 1666136644Sache[-C @var{command}] @var{name} [@var{name} @dots{}]} 1667136644Sache@code{complete -pr [@var{name} @dots{}]} 1668136644Sache@end example 1669136644Sache 1670136644SacheSpecify how arguments to each @var{name} should be completed. 1671136644SacheIf the @option{-p} option is supplied, or if no options are supplied, existing 1672136644Sachecompletion specifications are printed in a way that allows them to be 1673136644Sachereused as input. 1674136644SacheThe @option{-r} option removes a completion specification for 1675136644Sacheeach @var{name}, or, if no @var{name}s are supplied, all 1676136644Sachecompletion specifications. 1677136644Sache 1678136644SacheThe process of applying these completion specifications when word completion 1679136644Sacheis attempted is described above (@pxref{Programmable Completion}). 1680136644Sache 1681136644SacheOther options, if specified, have the following meanings. 1682136644SacheThe arguments to the @option{-G}, @option{-W}, and @option{-X} options 1683136644Sache(and, if necessary, the @option{-P} and @option{-S} options) 1684136644Sacheshould be quoted to protect them from expansion before the 1685136644Sache@code{complete} builtin is invoked. 1686136644Sache 1687136644Sache 1688136644Sache@table @code 1689136644Sache@item -o @var{comp-option} 1690136644SacheThe @var{comp-option} controls several aspects of the compspec's behavior 1691136644Sachebeyond the simple generation of completions. 1692136644Sache@var{comp-option} may be one of: 1693136644Sache 1694136644Sache@table @code 1695136644Sache 1696136644Sache@item bashdefault 1697136644SachePerform the rest of the default Bash completions if the compspec 1698136644Sachegenerates no matches. 1699136644Sache 1700136644Sache@item default 1701136644SacheUse Readline's default filename completion if the compspec generates 1702136644Sacheno matches. 1703136644Sache 1704136644Sache@item dirnames 1705136644SachePerform directory name completion if the compspec generates no matches. 1706136644Sache 1707136644Sache@item filenames 1708136644SacheTell Readline that the compspec generates filenames, so it can perform any 1709136644Sachefilename-specific processing (like adding a slash to directory names or 1710136644Sachesuppressing trailing spaces). This option is intended to be used with 1711136644Sacheshell functions specified with @option{-F}. 1712136644Sache 1713136644Sache@item nospace 1714136644SacheTell Readline not to append a space (the default) to words completed at 1715136644Sachethe end of the line. 1716157184Sache 1717157184Sache@item plusdirs 1718157184SacheAfter any matches defined by the compspec are generated, 1719157184Sachedirectory name completion is attempted and any 1720157184Sachematches are added to the results of the other actions. 1721157184Sache 1722136644Sache@end table 1723136644Sache 1724136644Sache@item -A @var{action} 1725136644SacheThe @var{action} may be one of the following to generate a list of possible 1726136644Sachecompletions: 1727136644Sache 1728136644Sache@table @code 1729136644Sache@item alias 1730136644SacheAlias names. May also be specified as @option{-a}. 1731136644Sache 1732136644Sache@item arrayvar 1733136644SacheArray variable names. 1734136644Sache 1735136644Sache@item binding 1736136644SacheReadline key binding names (@pxref{Bindable Readline Commands}). 1737136644Sache 1738136644Sache@item builtin 1739136644SacheNames of shell builtin commands. May also be specified as @option{-b}. 1740136644Sache 1741136644Sache@item command 1742136644SacheCommand names. May also be specified as @option{-c}. 1743136644Sache 1744136644Sache@item directory 1745136644SacheDirectory names. May also be specified as @option{-d}. 1746136644Sache 1747136644Sache@item disabled 1748136644SacheNames of disabled shell builtins. 1749136644Sache 1750136644Sache@item enabled 1751136644SacheNames of enabled shell builtins. 1752136644Sache 1753136644Sache@item export 1754136644SacheNames of exported shell variables. May also be specified as @option{-e}. 1755136644Sache 1756136644Sache@item file 1757136644SacheFile names. May also be specified as @option{-f}. 1758136644Sache 1759136644Sache@item function 1760136644SacheNames of shell functions. 1761136644Sache 1762136644Sache@item group 1763136644SacheGroup names. May also be specified as @option{-g}. 1764136644Sache 1765136644Sache@item helptopic 1766136644SacheHelp topics as accepted by the @code{help} builtin (@pxref{Bash Builtins}). 1767136644Sache 1768136644Sache@item hostname 1769136644SacheHostnames, as taken from the file specified by the 1770136644Sache@env{HOSTFILE} shell variable (@pxref{Bash Variables}). 1771136644Sache 1772136644Sache@item job 1773136644SacheJob names, if job control is active. May also be specified as @option{-j}. 1774136644Sache 1775136644Sache@item keyword 1776136644SacheShell reserved words. May also be specified as @option{-k}. 1777136644Sache 1778136644Sache@item running 1779136644SacheNames of running jobs, if job control is active. 1780136644Sache 1781136644Sache@item service 1782136644SacheService names. May also be specified as @option{-s}. 1783136644Sache 1784136644Sache@item setopt 1785136644SacheValid arguments for the @option{-o} option to the @code{set} builtin 1786136644Sache(@pxref{The Set Builtin}). 1787136644Sache 1788136644Sache@item shopt 1789136644SacheShell option names as accepted by the @code{shopt} builtin 1790136644Sache(@pxref{Bash Builtins}). 1791136644Sache 1792136644Sache@item signal 1793136644SacheSignal names. 1794136644Sache 1795136644Sache@item stopped 1796136644SacheNames of stopped jobs, if job control is active. 1797136644Sache 1798136644Sache@item user 1799136644SacheUser names. May also be specified as @option{-u}. 1800136644Sache 1801136644Sache@item variable 1802136644SacheNames of all shell variables. May also be specified as @option{-v}. 1803136644Sache@end table 1804136644Sache 1805136644Sache@item -G @var{globpat} 1806136644SacheThe filename expansion pattern @var{globpat} is expanded to generate 1807136644Sachethe possible completions. 1808136644Sache 1809136644Sache@item -W @var{wordlist} 1810136644SacheThe @var{wordlist} is split using the characters in the 1811136644Sache@env{IFS} special variable as delimiters, and each resultant word 1812136644Sacheis expanded. 1813136644SacheThe possible completions are the members of the resultant list which 1814136644Sachematch the word being completed. 1815136644Sache 1816136644Sache@item -C @var{command} 1817136644Sache@var{command} is executed in a subshell environment, and its output is 1818136644Sacheused as the possible completions. 1819136644Sache 1820136644Sache@item -F @var{function} 1821136644SacheThe shell function @var{function} is executed in the current shell 1822136644Sacheenvironment. 1823136644SacheWhen it finishes, the possible completions are retrieved from the value 1824136644Sacheof the @env{COMPREPLY} array variable. 1825136644Sache 1826136644Sache@item -X @var{filterpat} 1827136644Sache@var{filterpat} is a pattern as used for filename expansion. 1828136644SacheIt is applied to the list of possible completions generated by the 1829136644Sachepreceding options and arguments, and each completion matching 1830136644Sache@var{filterpat} is removed from the list. 1831136644SacheA leading @samp{!} in @var{filterpat} negates the pattern; in this 1832136644Sachecase, any completion not matching @var{filterpat} is removed. 1833136644Sache 1834136644Sache@item -P @var{prefix} 1835136644Sache@var{prefix} is added at the beginning of each possible completion 1836136644Sacheafter all other options have been applied. 1837136644Sache 1838136644Sache@item -S @var{suffix} 1839136644Sache@var{suffix} is appended to each possible completion 1840136644Sacheafter all other options have been applied. 1841136644Sache@end table 1842136644Sache 1843136644SacheThe return value is true unless an invalid option is supplied, an option 1844136644Sacheother than @option{-p} or @option{-r} is supplied without a @var{name} 1845136644Sacheargument, an attempt is made to remove a completion specification for 1846136644Sachea @var{name} for which no specification exists, or 1847136644Sachean error occurs adding a completion specification. 1848136644Sache 1849136644Sache@end table 1850136644Sache@end ifset 1851