rluser.texi revision 136644
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 13136644SacheCopyright (C) 1988-2004 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 339136644Sachethat variable is unset, the default is @file{~/.inputrc}. 340136644Sache 341136644SacheWhen a program which uses the Readline library starts up, the 342136644Sacheinit file is read, and the key bindings are set. 343136644Sache 344136644SacheIn addition, the @code{C-x C-r} command re-reads this init file, thus 345136644Sacheincorporating any changes that you might have made to it. 346136644Sache 347136644Sache@menu 348136644Sache* Readline Init File Syntax:: Syntax for the commands in the inputrc file. 349136644Sache 350136644Sache* Conditional Init Constructs:: Conditional key bindings in the inputrc file. 351136644Sache 352136644Sache* Sample Init File:: An example inputrc file. 353136644Sache@end menu 354136644Sache 355136644Sache@node Readline Init File Syntax 356136644Sache@subsection Readline Init File Syntax 357136644Sache 358136644SacheThere are only a few basic constructs allowed in the 359136644SacheReadline init file. Blank lines are ignored. 360136644SacheLines beginning with a @samp{#} are comments. 361136644SacheLines beginning with a @samp{$} indicate conditional 362136644Sacheconstructs (@pxref{Conditional Init Constructs}). Other lines 363136644Sachedenote variable settings and key bindings. 364136644Sache 365136644Sache@table @asis 366136644Sache@item Variable Settings 367136644SacheYou can modify the run-time behavior of Readline by 368136644Sachealtering the values of variables in Readline 369136644Sacheusing the @code{set} command within the init file. 370136644SacheThe syntax is simple: 371136644Sache 372136644Sache@example 373136644Sacheset @var{variable} @var{value} 374136644Sache@end example 375136644Sache 376136644Sache@noindent 377136644SacheHere, for example, is how to 378136644Sachechange from the default Emacs-like key binding to use 379136644Sache@code{vi} line editing commands: 380136644Sache 381136644Sache@example 382136644Sacheset editing-mode vi 383136644Sache@end example 384136644Sache 385136644SacheVariable names and values, where appropriate, are recognized without regard 386136644Sacheto case. 387136644Sache 388136644Sache@ifset BashFeatures 389136644SacheThe @w{@code{bind -V}} command lists the current Readline variable names 390136644Sacheand values. @xref{Bash Builtins}. 391136644Sache@end ifset 392136644Sache 393136644SacheA great deal of run-time behavior is changeable with the following 394136644Sachevariables. 395136644Sache 396136644Sache@cindex variables, readline 397136644Sache@table @code 398136644Sache 399136644Sache@item bell-style 400136644Sache@vindex bell-style 401136644SacheControls what happens when Readline wants to ring the terminal bell. 402136644SacheIf set to @samp{none}, Readline never rings the bell. If set to 403136644Sache@samp{visible}, Readline uses a visible bell if one is available. 404136644SacheIf set to @samp{audible} (the default), Readline attempts to ring 405136644Sachethe terminal's bell. 406136644Sache 407136644Sache@item comment-begin 408136644Sache@vindex comment-begin 409136644SacheThe string to insert at the beginning of the line when the 410136644Sache@code{insert-comment} command is executed. The default value 411136644Sacheis @code{"#"}. 412136644Sache 413136644Sache@item completion-ignore-case 414136644SacheIf set to @samp{on}, Readline performs filename matching and completion 415136644Sachein a case-insensitive fashion. 416136644SacheThe default value is @samp{off}. 417136644Sache 418136644Sache@item completion-query-items 419136644Sache@vindex completion-query-items 420136644SacheThe number of possible completions that determines when the user is 421136644Sacheasked whether the list of possibilities should be displayed. 422136644SacheIf the number of possible completions is greater than this value, 423136644SacheReadline will ask the user whether or not he wishes to view 424136644Sachethem; otherwise, they are simply listed. 425136644SacheThis variable must be set to an integer value greater than or equal to 0. 426136644SacheThe default limit is @code{100}. 427136644Sache 428136644Sache@item convert-meta 429136644Sache@vindex convert-meta 430136644SacheIf set to @samp{on}, Readline will convert characters with the 431136644Sacheeighth bit set to an @sc{ascii} key sequence by stripping the eighth 432136644Sachebit and prefixing an @key{ESC} character, converting them to a 433136644Sachemeta-prefixed key sequence. The default value is @samp{on}. 434136644Sache 435136644Sache@item disable-completion 436136644Sache@vindex disable-completion 437136644SacheIf set to @samp{On}, Readline will inhibit word completion. 438136644SacheCompletion characters will be inserted into the line as if they had 439136644Sachebeen mapped to @code{self-insert}. The default is @samp{off}. 440136644Sache 441136644Sache@item editing-mode 442136644Sache@vindex editing-mode 443136644SacheThe @code{editing-mode} variable controls which default set of 444136644Sachekey bindings is used. By default, Readline starts up in Emacs editing 445136644Sachemode, where the keystrokes are most similar to Emacs. This variable can be 446136644Sacheset to either @samp{emacs} or @samp{vi}. 447136644Sache 448136644Sache@item enable-keypad 449136644Sache@vindex enable-keypad 450136644SacheWhen set to @samp{on}, Readline will try to enable the application 451136644Sachekeypad when it is called. Some systems need this to enable the 452136644Sachearrow keys. The default is @samp{off}. 453136644Sache 454136644Sache@item expand-tilde 455136644Sache@vindex expand-tilde 456136644SacheIf set to @samp{on}, tilde expansion is performed when Readline 457136644Sacheattempts word completion. The default is @samp{off}. 458136644Sache 459136644Sache@vindex history-preserve-point 460136644SacheIf set to @samp{on}, the history code attempts to place point at the 461136644Sachesame location on each history line retrieved with @code{previous-history} 462136644Sacheor @code{next-history}. 463136644Sache 464136644Sache@item horizontal-scroll-mode 465136644Sache@vindex horizontal-scroll-mode 466136644SacheThis variable can be set to either @samp{on} or @samp{off}. Setting it 467136644Sacheto @samp{on} means that the text of the lines being edited will scroll 468136644Sachehorizontally on a single screen line when they are longer than the width 469136644Sacheof the screen, instead of wrapping onto a new screen line. By default, 470136644Sachethis variable is set to @samp{off}. 471136644Sache 472136644Sache@item input-meta 473136644Sache@vindex input-meta 474136644Sache@vindex meta-flag 475136644SacheIf set to @samp{on}, Readline will enable eight-bit input (it 476136644Sachewill not clear the eighth bit in the characters it reads), 477136644Sacheregardless of what the terminal claims it can support. The 478136644Sachedefault value is @samp{off}. The name @code{meta-flag} is a 479136644Sachesynonym for this variable. 480136644Sache 481136644Sache@item isearch-terminators 482136644Sache@vindex isearch-terminators 483136644SacheThe string of characters that should terminate an incremental search without 484136644Sachesubsequently executing the character as a command (@pxref{Searching}). 485136644SacheIf this variable has not been given a value, the characters @key{ESC} and 486136644Sache@kbd{C-J} will terminate an incremental search. 487136644Sache 488136644Sache@item keymap 489136644Sache@vindex keymap 490136644SacheSets Readline's idea of the current keymap for key binding commands. 491136644SacheAcceptable @code{keymap} names are 492136644Sache@code{emacs}, 493136644Sache@code{emacs-standard}, 494136644Sache@code{emacs-meta}, 495136644Sache@code{emacs-ctlx}, 496136644Sache@code{vi}, 497136644Sache@code{vi-move}, 498136644Sache@code{vi-command}, and 499136644Sache@code{vi-insert}. 500136644Sache@code{vi} is equivalent to @code{vi-command}; @code{emacs} is 501136644Sacheequivalent to @code{emacs-standard}. The default value is @code{emacs}. 502136644SacheThe value of the @code{editing-mode} variable also affects the 503136644Sachedefault keymap. 504136644Sache 505136644Sache@item mark-directories 506136644SacheIf set to @samp{on}, completed directory names have a slash 507136644Sacheappended. The default is @samp{on}. 508136644Sache 509136644Sache@item mark-modified-lines 510136644Sache@vindex mark-modified-lines 511136644SacheThis variable, when set to @samp{on}, causes Readline to display an 512136644Sacheasterisk (@samp{*}) at the start of history lines which have been modified. 513136644SacheThis variable is @samp{off} by default. 514136644Sache 515136644Sache@item mark-symlinked-directories 516136644Sache@vindex mark-symlinked-directories 517136644SacheIf set to @samp{on}, completed names which are symbolic links 518136644Sacheto directories have a slash appended (subject to the value of 519136644Sache@code{mark-directories}). 520136644SacheThe default is @samp{off}. 521136644Sache 522136644Sache@item match-hidden-files 523136644Sache@vindex match-hidden-files 524136644SacheThis variable, when set to @samp{on}, causes Readline to match files whose 525136644Sachenames begin with a @samp{.} (hidden files) when performing filename 526136644Sachecompletion, unless the leading @samp{.} is 527136644Sachesupplied by the user in the filename to be completed. 528136644SacheThis variable is @samp{on} by default. 529136644Sache 530136644Sache@item output-meta 531136644Sache@vindex output-meta 532136644SacheIf set to @samp{on}, Readline will display characters with the 533136644Sacheeighth bit set directly rather than as a meta-prefixed escape 534136644Sachesequence. The default is @samp{off}. 535136644Sache 536136644Sache@item page-completions 537136644Sache@vindex page-completions 538136644SacheIf set to @samp{on}, Readline uses an internal @code{more}-like pager 539136644Sacheto display a screenful of possible completions at a time. 540136644SacheThis variable is @samp{on} by default. 541136644Sache 542136644Sache@item print-completions-horizontally 543136644SacheIf set to @samp{on}, Readline will display completions with matches 544136644Sachesorted horizontally in alphabetical order, rather than down the screen. 545136644SacheThe default is @samp{off}. 546136644Sache 547136644Sache@item show-all-if-ambiguous 548136644Sache@vindex show-all-if-ambiguous 549136644SacheThis alters the default behavior of the completion functions. If 550136644Sacheset to @samp{on}, 551136644Sachewords which have more than one possible completion cause the 552136644Sachematches to be listed immediately instead of ringing the bell. 553136644SacheThe default value is @samp{off}. 554136644Sache 555136644Sache@item show-all-if-unmodified 556136644Sache@vindex show-all-if-unmodified 557136644SacheThis alters the default behavior of the completion functions in 558136644Sachea fashion similar to @var{show-all-if-ambiguous}. 559136644SacheIf set to @samp{on}, 560136644Sachewords which have more than one possible completion without any 561136644Sachepossible partial completion (the possible completions don't share 562136644Sachea common prefix) cause the matches to be listed immediately instead 563136644Sacheof ringing the bell. 564136644SacheThe default value is @samp{off}. 565136644Sache 566136644Sache@item visible-stats 567136644Sache@vindex visible-stats 568136644SacheIf set to @samp{on}, a character denoting a file's type 569136644Sacheis appended to the filename when listing possible 570136644Sachecompletions. The default is @samp{off}. 571136644Sache 572136644Sache@end table 573136644Sache 574136644Sache@item Key Bindings 575136644SacheThe syntax for controlling key bindings in the init file is 576136644Sachesimple. First you need to find the name of the command that you 577136644Sachewant to change. The following sections contain tables of the command 578136644Sachename, the default keybinding, if any, and a short description of what 579136644Sachethe command does. 580136644Sache 581136644SacheOnce you know the name of the command, simply place on a line 582136644Sachein the init file the name of the key 583136644Sacheyou wish to bind the command to, a colon, and then the name of the 584136644Sachecommand. The name of the key 585136644Sachecan be expressed in different ways, depending on what you find most 586136644Sachecomfortable. 587136644Sache 588136644SacheIn addition to command names, readline allows keys to be bound 589136644Sacheto a string that is inserted when the key is pressed (a @var{macro}). 590136644Sache 591136644Sache@ifset BashFeatures 592136644SacheThe @w{@code{bind -p}} command displays Readline function names and 593136644Sachebindings in a format that can put directly into an initialization file. 594136644Sache@xref{Bash Builtins}. 595136644Sache@end ifset 596136644Sache 597136644Sache@table @asis 598136644Sache@item @w{@var{keyname}: @var{function-name} or @var{macro}} 599136644Sache@var{keyname} is the name of a key spelled out in English. For example: 600136644Sache@example 601136644SacheControl-u: universal-argument 602136644SacheMeta-Rubout: backward-kill-word 603136644SacheControl-o: "> output" 604136644Sache@end example 605136644Sache 606136644SacheIn the above example, @kbd{C-u} is bound to the function 607136644Sache@code{universal-argument}, 608136644Sache@kbd{M-DEL} is bound to the function @code{backward-kill-word}, and 609136644Sache@kbd{C-o} is bound to run the macro 610136644Sacheexpressed on the right hand side (that is, to insert the text 611136644Sache@samp{> output} into the line). 612136644Sache 613136644SacheA number of symbolic character names are recognized while 614136644Sacheprocessing this key binding syntax: 615136644Sache@var{DEL}, 616136644Sache@var{ESC}, 617136644Sache@var{ESCAPE}, 618136644Sache@var{LFD}, 619136644Sache@var{NEWLINE}, 620136644Sache@var{RET}, 621136644Sache@var{RETURN}, 622136644Sache@var{RUBOUT}, 623136644Sache@var{SPACE}, 624136644Sache@var{SPC}, 625136644Sacheand 626136644Sache@var{TAB}. 627136644Sache 628136644Sache@item @w{"@var{keyseq}": @var{function-name} or @var{macro}} 629136644Sache@var{keyseq} differs from @var{keyname} above in that strings 630136644Sachedenoting an entire key sequence can be specified, by placing 631136644Sachethe key sequence in double quotes. Some @sc{gnu} Emacs style key 632136644Sacheescapes can be used, as in the following example, but the 633136644Sachespecial character names are not recognized. 634136644Sache 635136644Sache@example 636136644Sache"\C-u": universal-argument 637136644Sache"\C-x\C-r": re-read-init-file 638136644Sache"\e[11~": "Function Key 1" 639136644Sache@end example 640136644Sache 641136644SacheIn the above example, @kbd{C-u} is again bound to the function 642136644Sache@code{universal-argument} (just as it was in the first example), 643136644Sache@samp{@kbd{C-x} @kbd{C-r}} is bound to the function @code{re-read-init-file}, 644136644Sacheand @samp{@key{ESC} @key{[} @key{1} @key{1} @key{~}} is bound to insert 645136644Sachethe text @samp{Function Key 1}. 646136644Sache 647136644Sache@end table 648136644Sache 649136644SacheThe following @sc{gnu} Emacs style escape sequences are available when 650136644Sachespecifying key sequences: 651136644Sache 652136644Sache@table @code 653136644Sache@item @kbd{\C-} 654136644Sachecontrol prefix 655136644Sache@item @kbd{\M-} 656136644Sachemeta prefix 657136644Sache@item @kbd{\e} 658136644Sachean escape character 659136644Sache@item @kbd{\\} 660136644Sachebackslash 661136644Sache@item @kbd{\"} 662136644Sache@key{"}, a double quotation mark 663136644Sache@item @kbd{\'} 664136644Sache@key{'}, a single quote or apostrophe 665136644Sache@end table 666136644Sache 667136644SacheIn addition to the @sc{gnu} Emacs style escape sequences, a second 668136644Sacheset of backslash escapes is available: 669136644Sache 670136644Sache@table @code 671136644Sache@item \a 672136644Sachealert (bell) 673136644Sache@item \b 674136644Sachebackspace 675136644Sache@item \d 676136644Sachedelete 677136644Sache@item \f 678136644Sacheform feed 679136644Sache@item \n 680136644Sachenewline 681136644Sache@item \r 682136644Sachecarriage return 683136644Sache@item \t 684136644Sachehorizontal tab 685136644Sache@item \v 686136644Sachevertical tab 687136644Sache@item \@var{nnn} 688136644Sachethe eight-bit character whose value is the octal value @var{nnn} 689136644Sache(one to three digits) 690136644Sache@item \x@var{HH} 691136644Sachethe eight-bit character whose value is the hexadecimal value @var{HH} 692136644Sache(one or two hex digits) 693136644Sache@end table 694136644Sache 695136644SacheWhen entering the text of a macro, single or double quotes must 696136644Sachebe used to indicate a macro definition. 697136644SacheUnquoted text is assumed to be a function name. 698136644SacheIn the macro body, the backslash escapes described above are expanded. 699136644SacheBackslash will quote any other character in the macro text, 700136644Sacheincluding @samp{"} and @samp{'}. 701136644SacheFor example, the following binding will make @samp{@kbd{C-x} \} 702136644Sacheinsert a single @samp{\} into the line: 703136644Sache@example 704136644Sache"\C-x\\": "\\" 705136644Sache@end example 706136644Sache 707136644Sache@end table 708136644Sache 709136644Sache@node Conditional Init Constructs 710136644Sache@subsection Conditional Init Constructs 711136644Sache 712136644SacheReadline implements a facility similar in spirit to the conditional 713136644Sachecompilation features of the C preprocessor which allows key 714136644Sachebindings and variable settings to be performed as the result 715136644Sacheof tests. There are four parser directives used. 716136644Sache 717136644Sache@table @code 718136644Sache@item $if 719136644SacheThe @code{$if} construct allows bindings to be made based on the 720136644Sacheediting mode, the terminal being used, or the application using 721136644SacheReadline. The text of the test extends to the end of the line; 722136644Sacheno characters are required to isolate it. 723136644Sache 724136644Sache@table @code 725136644Sache@item mode 726136644SacheThe @code{mode=} form of the @code{$if} directive is used to test 727136644Sachewhether Readline is in @code{emacs} or @code{vi} mode. 728136644SacheThis may be used in conjunction 729136644Sachewith the @samp{set keymap} command, for instance, to set bindings in 730136644Sachethe @code{emacs-standard} and @code{emacs-ctlx} keymaps only if 731136644SacheReadline is starting out in @code{emacs} mode. 732136644Sache 733136644Sache@item term 734136644SacheThe @code{term=} form may be used to include terminal-specific 735136644Sachekey bindings, perhaps to bind the key sequences output by the 736136644Sacheterminal's function keys. The word on the right side of the 737136644Sache@samp{=} is tested against both the full name of the terminal and 738136644Sachethe portion of the terminal name before the first @samp{-}. This 739136644Sacheallows @code{sun} to match both @code{sun} and @code{sun-cmd}, 740136644Sachefor instance. 741136644Sache 742136644Sache@item application 743136644SacheThe @var{application} construct is used to include 744136644Sacheapplication-specific settings. Each program using the Readline 745136644Sachelibrary sets the @var{application name}, and you can test for 746136644Sachea particular value. 747136644SacheThis could be used to bind key sequences to functions useful for 748136644Sachea specific program. For instance, the following command adds a 749136644Sachekey sequence that quotes the current or previous word in Bash: 750136644Sache@example 751136644Sache$if Bash 752136644Sache# Quote the current or previous word 753136644Sache"\C-xq": "\eb\"\ef\"" 754136644Sache$endif 755136644Sache@end example 756136644Sache@end table 757136644Sache 758136644Sache@item $endif 759136644SacheThis command, as seen in the previous example, terminates an 760136644Sache@code{$if} command. 761136644Sache 762136644Sache@item $else 763136644SacheCommands in this branch of the @code{$if} directive are executed if 764136644Sachethe test fails. 765136644Sache 766136644Sache@item $include 767136644SacheThis directive takes a single filename as an argument and reads commands 768136644Sacheand bindings from that file. 769136644SacheFor example, the following directive reads from @file{/etc/inputrc}: 770136644Sache@example 771136644Sache$include /etc/inputrc 772136644Sache@end example 773136644Sache@end table 774136644Sache 775136644Sache@node Sample Init File 776136644Sache@subsection Sample Init File 777136644Sache 778136644SacheHere is an example of an @var{inputrc} file. This illustrates key 779136644Sachebinding, variable assignment, and conditional syntax. 780136644Sache 781136644Sache@example 782136644Sache@page 783136644Sache# This file controls the behaviour of line input editing for 784136644Sache# programs that use the GNU Readline library. Existing 785136644Sache# programs include FTP, Bash, and GDB. 786136644Sache# 787136644Sache# You can re-read the inputrc file with C-x C-r. 788136644Sache# Lines beginning with '#' are comments. 789136644Sache# 790136644Sache# First, include any systemwide bindings and variable 791136644Sache# assignments from /etc/Inputrc 792136644Sache$include /etc/Inputrc 793136644Sache 794136644Sache# 795136644Sache# Set various bindings for emacs mode. 796136644Sache 797136644Sacheset editing-mode emacs 798136644Sache 799136644Sache$if mode=emacs 800136644Sache 801136644SacheMeta-Control-h: backward-kill-word Text after the function name is ignored 802136644Sache 803136644Sache# 804136644Sache# Arrow keys in keypad mode 805136644Sache# 806136644Sache#"\M-OD": backward-char 807136644Sache#"\M-OC": forward-char 808136644Sache#"\M-OA": previous-history 809136644Sache#"\M-OB": next-history 810136644Sache# 811136644Sache# Arrow keys in ANSI mode 812136644Sache# 813136644Sache"\M-[D": backward-char 814136644Sache"\M-[C": forward-char 815136644Sache"\M-[A": previous-history 816136644Sache"\M-[B": next-history 817136644Sache# 818136644Sache# Arrow keys in 8 bit keypad mode 819136644Sache# 820136644Sache#"\M-\C-OD": backward-char 821136644Sache#"\M-\C-OC": forward-char 822136644Sache#"\M-\C-OA": previous-history 823136644Sache#"\M-\C-OB": next-history 824136644Sache# 825136644Sache# Arrow keys in 8 bit ANSI mode 826136644Sache# 827136644Sache#"\M-\C-[D": backward-char 828136644Sache#"\M-\C-[C": forward-char 829136644Sache#"\M-\C-[A": previous-history 830136644Sache#"\M-\C-[B": next-history 831136644Sache 832136644SacheC-q: quoted-insert 833136644Sache 834136644Sache$endif 835136644Sache 836136644Sache# An old-style binding. This happens to be the default. 837136644SacheTAB: complete 838136644Sache 839136644Sache# Macros that are convenient for shell interaction 840136644Sache$if Bash 841136644Sache# edit the path 842136644Sache"\C-xp": "PATH=$@{PATH@}\e\C-e\C-a\ef\C-f" 843136644Sache# prepare to type a quoted word -- 844136644Sache# insert open and close double quotes 845136644Sache# and move to just after the open quote 846136644Sache"\C-x\"": "\"\"\C-b" 847136644Sache# insert a backslash (testing backslash escapes 848136644Sache# in sequences and macros) 849136644Sache"\C-x\\": "\\" 850136644Sache# Quote the current or previous word 851136644Sache"\C-xq": "\eb\"\ef\"" 852136644Sache# Add a binding to refresh the line, which is unbound 853136644Sache"\C-xr": redraw-current-line 854136644Sache# Edit variable on current line. 855136644Sache"\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y=" 856136644Sache$endif 857136644Sache 858136644Sache# use a visible bell if one is available 859136644Sacheset bell-style visible 860136644Sache 861136644Sache# don't strip characters to 7 bits when reading 862136644Sacheset input-meta on 863136644Sache 864136644Sache# allow iso-latin1 characters to be inserted rather 865136644Sache# than converted to prefix-meta sequences 866136644Sacheset convert-meta off 867136644Sache 868136644Sache# display characters with the eighth bit set directly 869136644Sache# rather than as meta-prefixed characters 870136644Sacheset output-meta on 871136644Sache 872136644Sache# if there are more than 150 possible completions for 873136644Sache# a word, ask the user if he wants to see all of them 874136644Sacheset completion-query-items 150 875136644Sache 876136644Sache# For FTP 877136644Sache$if Ftp 878136644Sache"\C-xg": "get \M-?" 879136644Sache"\C-xt": "put \M-?" 880136644Sache"\M-.": yank-last-arg 881136644Sache$endif 882136644Sache@end example 883136644Sache 884136644Sache@node Bindable Readline Commands 885136644Sache@section Bindable Readline Commands 886136644Sache 887136644Sache@menu 888136644Sache* Commands For Moving:: Moving about the line. 889136644Sache* Commands For History:: Getting at previous lines. 890136644Sache* Commands For Text:: Commands for changing text. 891136644Sache* Commands For Killing:: Commands for killing and yanking. 892136644Sache* Numeric Arguments:: Specifying numeric arguments, repeat counts. 893136644Sache* Commands For Completion:: Getting Readline to do the typing for you. 894136644Sache* Keyboard Macros:: Saving and re-executing typed characters 895136644Sache* Miscellaneous Commands:: Other miscellaneous commands. 896136644Sache@end menu 897136644Sache 898136644SacheThis section describes Readline commands that may be bound to key 899136644Sachesequences. 900136644Sache@ifset BashFeatures 901136644SacheYou can list your key bindings by executing 902136644Sache@w{@code{bind -P}} or, for a more terse format, suitable for an 903136644Sache@var{inputrc} file, @w{@code{bind -p}}. (@xref{Bash Builtins}.) 904136644Sache@end ifset 905136644SacheCommand names without an accompanying key sequence are unbound by default. 906136644Sache 907136644SacheIn the following descriptions, @dfn{point} refers to the current cursor 908136644Sacheposition, and @dfn{mark} refers to a cursor position saved by the 909136644Sache@code{set-mark} command. 910136644SacheThe text between the point and mark is referred to as the @dfn{region}. 911136644Sache 912136644Sache@node Commands For Moving 913136644Sache@subsection Commands For Moving 914136644Sache@ftable @code 915136644Sache@item beginning-of-line (C-a) 916136644SacheMove to the start of the current line. 917136644Sache 918136644Sache@item end-of-line (C-e) 919136644SacheMove to the end of the line. 920136644Sache 921136644Sache@item forward-char (C-f) 922136644SacheMove forward a character. 923136644Sache 924136644Sache@item backward-char (C-b) 925136644SacheMove back a character. 926136644Sache 927136644Sache@item forward-word (M-f) 928136644SacheMove forward to the end of the next word. Words are composed of 929136644Sacheletters and digits. 930136644Sache 931136644Sache@item backward-word (M-b) 932136644SacheMove back to the start of the current or previous word. Words are 933136644Sachecomposed of letters and digits. 934136644Sache 935136644Sache@item clear-screen (C-l) 936136644SacheClear the screen and redraw the current line, 937136644Sacheleaving the current line at the top of the screen. 938136644Sache 939136644Sache@item redraw-current-line () 940136644SacheRefresh the current line. By default, this is unbound. 941136644Sache 942136644Sache@end ftable 943136644Sache 944136644Sache@node Commands For History 945136644Sache@subsection Commands For Manipulating The History 946136644Sache 947136644Sache@ftable @code 948136644Sache@item accept-line (Newline or Return) 949136644Sache@ifset BashFeatures 950136644SacheAccept the line regardless of where the cursor is. 951136644SacheIf this line is 952136644Sachenon-empty, add it to the history list according to the setting of 953136644Sachethe @env{HISTCONTROL} and @env{HISTIGNORE} variables. 954136644SacheIf this line is a modified history line, then restore the history line 955136644Sacheto its original state. 956136644Sache@end ifset 957136644Sache@ifclear BashFeatures 958136644SacheAccept the line regardless of where the cursor is. 959136644SacheIf this line is 960136644Sachenon-empty, it may be added to the history list for future recall with 961136644Sache@code{add_history()}. 962136644SacheIf this line is a modified history line, the history line is restored 963136644Sacheto its original state. 964136644Sache@end ifclear 965136644Sache 966136644Sache@item previous-history (C-p) 967136644SacheMove `back' through the history list, fetching the previous command. 968136644Sache 969136644Sache@item next-history (C-n) 970136644SacheMove `forward' through the history list, fetching the next command. 971136644Sache 972136644Sache@item beginning-of-history (M-<) 973136644SacheMove to the first line in the history. 974136644Sache 975136644Sache@item end-of-history (M->) 976136644SacheMove to the end of the input history, i.e., the line currently 977136644Sachebeing entered. 978136644Sache 979136644Sache@item reverse-search-history (C-r) 980136644SacheSearch backward starting at the current line and moving `up' through 981136644Sachethe history as necessary. This is an incremental search. 982136644Sache 983136644Sache@item forward-search-history (C-s) 984136644SacheSearch forward starting at the current line and moving `down' through 985136644Sachethe the history as necessary. This is an incremental search. 986136644Sache 987136644Sache@item non-incremental-reverse-search-history (M-p) 988136644SacheSearch backward starting at the current line and moving `up' 989136644Sachethrough the history as necessary using a non-incremental search 990136644Sachefor a string supplied by the user. 991136644Sache 992136644Sache@item non-incremental-forward-search-history (M-n) 993136644SacheSearch forward starting at the current line and moving `down' 994136644Sachethrough the the history as necessary using a non-incremental search 995136644Sachefor a string supplied by the user. 996136644Sache 997136644Sache@item history-search-forward () 998136644SacheSearch forward through the history for the string of characters 999136644Sachebetween the start of the current line and the point. 1000136644SacheThis is a non-incremental search. 1001136644SacheBy default, this command is unbound. 1002136644Sache 1003136644Sache@item history-search-backward () 1004136644SacheSearch backward through the history for the string of characters 1005136644Sachebetween the start of the current line and the point. This 1006136644Sacheis a non-incremental search. By default, this command is unbound. 1007136644Sache 1008136644Sache@item yank-nth-arg (M-C-y) 1009136644SacheInsert the first argument to the previous command (usually 1010136644Sachethe second word on the previous line) at point. 1011136644SacheWith an argument @var{n}, 1012136644Sacheinsert the @var{n}th word from the previous command (the words 1013136644Sachein the previous command begin with word 0). A negative argument 1014136644Sacheinserts the @var{n}th word from the end of the previous command. 1015136644Sache 1016136644Sache@item yank-last-arg (M-. or M-_) 1017136644SacheInsert last argument to the previous command (the last word of the 1018136644Sacheprevious history entry). With an 1019136644Sacheargument, behave exactly like @code{yank-nth-arg}. 1020136644SacheSuccessive calls to @code{yank-last-arg} move back through the history 1021136644Sachelist, inserting the last argument of each line in turn. 1022136644Sache 1023136644Sache@end ftable 1024136644Sache 1025136644Sache@node Commands For Text 1026136644Sache@subsection Commands For Changing Text 1027136644Sache 1028136644Sache@ftable @code 1029136644Sache@item delete-char (C-d) 1030136644SacheDelete the character at point. If point is at the 1031136644Sachebeginning of the line, there are no characters in the line, and 1032136644Sachethe last character typed was not bound to @code{delete-char}, then 1033136644Sachereturn @sc{eof}. 1034136644Sache 1035136644Sache@item backward-delete-char (Rubout) 1036136644SacheDelete the character behind the cursor. A numeric argument means 1037136644Sacheto kill the characters instead of deleting them. 1038136644Sache 1039136644Sache@item forward-backward-delete-char () 1040136644SacheDelete the character under the cursor, unless the cursor is at the 1041136644Sacheend of the line, in which case the character behind the cursor is 1042136644Sachedeleted. By default, this is not bound to a key. 1043136644Sache 1044136644Sache@item quoted-insert (C-q or C-v) 1045136644SacheAdd the next character typed to the line verbatim. This is 1046136644Sachehow to insert key sequences like @kbd{C-q}, for example. 1047136644Sache 1048136644Sache@ifclear BashFeatures 1049136644Sache@item tab-insert (M-@key{TAB}) 1050136644SacheInsert a tab character. 1051136644Sache@end ifclear 1052136644Sache 1053136644Sache@item self-insert (a, b, A, 1, !, @dots{}) 1054136644SacheInsert yourself. 1055136644Sache 1056136644Sache@item transpose-chars (C-t) 1057136644SacheDrag the character before the cursor forward over 1058136644Sachethe character at the cursor, moving the 1059136644Sachecursor forward as well. If the insertion point 1060136644Sacheis at the end of the line, then this 1061136644Sachetransposes the last two characters of the line. 1062136644SacheNegative arguments have no effect. 1063136644Sache 1064136644Sache@item transpose-words (M-t) 1065136644SacheDrag the word before point past the word after point, 1066136644Sachemoving point past that word as well. 1067136644SacheIf the insertion point is at the end of the line, this transposes 1068136644Sachethe last two words on the line. 1069136644Sache 1070136644Sache@item upcase-word (M-u) 1071136644SacheUppercase the current (or following) word. With a negative argument, 1072136644Sacheuppercase the previous word, but do not move the cursor. 1073136644Sache 1074136644Sache@item downcase-word (M-l) 1075136644SacheLowercase the current (or following) word. With a negative argument, 1076136644Sachelowercase the previous word, but do not move the cursor. 1077136644Sache 1078136644Sache@item capitalize-word (M-c) 1079136644SacheCapitalize the current (or following) word. With a negative argument, 1080136644Sachecapitalize the previous word, but do not move the cursor. 1081136644Sache 1082136644Sache@item overwrite-mode () 1083136644SacheToggle overwrite mode. With an explicit positive numeric argument, 1084136644Sacheswitches to overwrite mode. With an explicit non-positive numeric 1085136644Sacheargument, switches to insert mode. This command affects only 1086136644Sache@code{emacs} mode; @code{vi} mode does overwrite differently. 1087136644SacheEach call to @code{readline()} starts in insert mode. 1088136644Sache 1089136644SacheIn overwrite mode, characters bound to @code{self-insert} replace 1090136644Sachethe text at point rather than pushing the text to the right. 1091136644SacheCharacters bound to @code{backward-delete-char} replace the character 1092136644Sachebefore point with a space. 1093136644Sache 1094136644SacheBy default, this command is unbound. 1095136644Sache 1096136644Sache@end ftable 1097136644Sache 1098136644Sache@node Commands For Killing 1099136644Sache@subsection Killing And Yanking 1100136644Sache 1101136644Sache@ftable @code 1102136644Sache 1103136644Sache@item kill-line (C-k) 1104136644SacheKill the text from point to the end of the line. 1105136644Sache 1106136644Sache@item backward-kill-line (C-x Rubout) 1107136644SacheKill backward to the beginning of the line. 1108136644Sache 1109136644Sache@item unix-line-discard (C-u) 1110136644SacheKill backward from the cursor to the beginning of the current line. 1111136644Sache 1112136644Sache@item kill-whole-line () 1113136644SacheKill all characters on the current line, no matter where point is. 1114136644SacheBy default, this is unbound. 1115136644Sache 1116136644Sache@item kill-word (M-d) 1117136644SacheKill from point to the end of the current word, or if between 1118136644Sachewords, to the end of the next word. 1119136644SacheWord boundaries are the same as @code{forward-word}. 1120136644Sache 1121136644Sache@item backward-kill-word (M-@key{DEL}) 1122136644SacheKill the word behind point. 1123136644SacheWord boundaries are the same as @code{backward-word}. 1124136644Sache 1125136644Sache@item unix-word-rubout (C-w) 1126136644SacheKill the word behind point, using white space as a word boundary. 1127136644SacheThe killed text is saved on the kill-ring. 1128136644Sache 1129136644Sache@item unix-filename-rubout () 1130136644SacheKill the word behind point, using white space and the slash character 1131136644Sacheas the word boundaries. 1132136644SacheThe killed text is saved on the kill-ring. 1133136644Sache 1134136644Sache@item delete-horizontal-space () 1135136644SacheDelete all spaces and tabs around point. By default, this is unbound. 1136136644Sache 1137136644Sache@item kill-region () 1138136644SacheKill the text in the current region. 1139136644SacheBy default, this command is unbound. 1140136644Sache 1141136644Sache@item copy-region-as-kill () 1142136644SacheCopy the text in the region to the kill buffer, so it can be yanked 1143136644Sacheright away. By default, this command is unbound. 1144136644Sache 1145136644Sache@item copy-backward-word () 1146136644SacheCopy the word before point to the kill buffer. 1147136644SacheThe word boundaries are the same as @code{backward-word}. 1148136644SacheBy default, this command is unbound. 1149136644Sache 1150136644Sache@item copy-forward-word () 1151136644SacheCopy the word following point to the kill buffer. 1152136644SacheThe word boundaries are the same as @code{forward-word}. 1153136644SacheBy default, this command is unbound. 1154136644Sache 1155136644Sache@item yank (C-y) 1156136644SacheYank the top of the kill ring into the buffer at point. 1157136644Sache 1158136644Sache@item yank-pop (M-y) 1159136644SacheRotate the kill-ring, and yank the new top. You can only do this if 1160136644Sachethe prior command is @code{yank} or @code{yank-pop}. 1161136644Sache@end ftable 1162136644Sache 1163136644Sache@node Numeric Arguments 1164136644Sache@subsection Specifying Numeric Arguments 1165136644Sache@ftable @code 1166136644Sache 1167136644Sache@item digit-argument (@kbd{M-0}, @kbd{M-1}, @dots{} @kbd{M--}) 1168136644SacheAdd this digit to the argument already accumulating, or start a new 1169136644Sacheargument. @kbd{M--} starts a negative argument. 1170136644Sache 1171136644Sache@item universal-argument () 1172136644SacheThis is another way to specify an argument. 1173136644SacheIf this command is followed by one or more digits, optionally with a 1174136644Sacheleading minus sign, those digits define the argument. 1175136644SacheIf the command is followed by digits, executing @code{universal-argument} 1176136644Sacheagain ends the numeric argument, but is otherwise ignored. 1177136644SacheAs a special case, if this command is immediately followed by a 1178136644Sachecharacter that is neither a digit or minus sign, the argument count 1179136644Sachefor the next command is multiplied by four. 1180136644SacheThe argument count is initially one, so executing this function the 1181136644Sachefirst time makes the argument count four, a second time makes the 1182136644Sacheargument count sixteen, and so on. 1183136644SacheBy default, this is not bound to a key. 1184136644Sache@end ftable 1185136644Sache 1186136644Sache@node Commands For Completion 1187136644Sache@subsection Letting Readline Type For You 1188136644Sache 1189136644Sache@ftable @code 1190136644Sache@item complete (@key{TAB}) 1191136644SacheAttempt to perform completion on the text before point. 1192136644SacheThe actual completion performed is application-specific. 1193136644Sache@ifset BashFeatures 1194136644SacheBash attempts completion treating the text as a variable (if the 1195136644Sachetext begins with @samp{$}), username (if the text begins with 1196136644Sache@samp{~}), hostname (if the text begins with @samp{@@}), or 1197136644Sachecommand (including aliases and functions) in turn. If none 1198136644Sacheof these produces a match, filename completion is attempted. 1199136644Sache@end ifset 1200136644Sache@ifclear BashFeatures 1201136644SacheThe default is filename completion. 1202136644Sache@end ifclear 1203136644Sache 1204136644Sache@item possible-completions (M-?) 1205136644SacheList the possible completions of the text before point. 1206136644Sache 1207136644Sache@item insert-completions (M-*) 1208136644SacheInsert all completions of the text before point that would have 1209136644Sachebeen generated by @code{possible-completions}. 1210136644Sache 1211136644Sache@item menu-complete () 1212136644SacheSimilar to @code{complete}, but replaces the word to be completed 1213136644Sachewith a single match from the list of possible completions. 1214136644SacheRepeated execution of @code{menu-complete} steps through the list 1215136644Sacheof possible completions, inserting each match in turn. 1216136644SacheAt the end of the list of completions, the bell is rung 1217136644Sache(subject to the setting of @code{bell-style}) 1218136644Sacheand the original text is restored. 1219136644SacheAn argument of @var{n} moves @var{n} positions forward in the list 1220136644Sacheof matches; a negative argument may be used to move backward 1221136644Sachethrough the list. 1222136644SacheThis command is intended to be bound to @key{TAB}, but is unbound 1223136644Sacheby default. 1224136644Sache 1225136644Sache@item delete-char-or-list () 1226136644SacheDeletes the character under the cursor if not at the beginning or 1227136644Sacheend of the line (like @code{delete-char}). 1228136644SacheIf at the end of the line, behaves identically to 1229136644Sache@code{possible-completions}. 1230136644SacheThis command is unbound by default. 1231136644Sache 1232136644Sache@ifset BashFeatures 1233136644Sache@item complete-filename (M-/) 1234136644SacheAttempt filename completion on the text before point. 1235136644Sache 1236136644Sache@item possible-filename-completions (C-x /) 1237136644SacheList the possible completions of the text before point, 1238136644Sachetreating it as a filename. 1239136644Sache 1240136644Sache@item complete-username (M-~) 1241136644SacheAttempt completion on the text before point, treating 1242136644Sacheit as a username. 1243136644Sache 1244136644Sache@item possible-username-completions (C-x ~) 1245136644SacheList the possible completions of the text before point, 1246136644Sachetreating it as a username. 1247136644Sache 1248136644Sache@item complete-variable (M-$) 1249136644SacheAttempt completion on the text before point, treating 1250136644Sacheit as a shell variable. 1251136644Sache 1252136644Sache@item possible-variable-completions (C-x $) 1253136644SacheList the possible completions of the text before point, 1254136644Sachetreating it as a shell variable. 1255136644Sache 1256136644Sache@item complete-hostname (M-@@) 1257136644SacheAttempt completion on the text before point, treating 1258136644Sacheit as a hostname. 1259136644Sache 1260136644Sache@item possible-hostname-completions (C-x @@) 1261136644SacheList the possible completions of the text before point, 1262136644Sachetreating it as a hostname. 1263136644Sache 1264136644Sache@item complete-command (M-!) 1265136644SacheAttempt completion on the text before point, treating 1266136644Sacheit as a command name. Command completion attempts to 1267136644Sachematch the text against aliases, reserved words, shell 1268136644Sachefunctions, shell builtins, and finally executable filenames, 1269136644Sachein that order. 1270136644Sache 1271136644Sache@item possible-command-completions (C-x !) 1272136644SacheList the possible completions of the text before point, 1273136644Sachetreating it as a command name. 1274136644Sache 1275136644Sache@item dynamic-complete-history (M-@key{TAB}) 1276136644SacheAttempt completion on the text before point, comparing 1277136644Sachethe text against lines from the history list for possible 1278136644Sachecompletion matches. 1279136644Sache 1280136644Sache@item complete-into-braces (M-@{) 1281136644SachePerform filename completion and insert the list of possible completions 1282136644Sacheenclosed within braces so the list is available to the shell 1283136644Sache(@pxref{Brace Expansion}). 1284136644Sache 1285136644Sache@end ifset 1286136644Sache@end ftable 1287136644Sache 1288136644Sache@node Keyboard Macros 1289136644Sache@subsection Keyboard Macros 1290136644Sache@ftable @code 1291136644Sache 1292136644Sache@item start-kbd-macro (C-x () 1293136644SacheBegin saving the characters typed into the current keyboard macro. 1294136644Sache 1295136644Sache@item end-kbd-macro (C-x )) 1296136644SacheStop saving the characters typed into the current keyboard macro 1297136644Sacheand save the definition. 1298136644Sache 1299136644Sache@item call-last-kbd-macro (C-x e) 1300136644SacheRe-execute the last keyboard macro defined, by making the characters 1301136644Sachein the macro appear as if typed at the keyboard. 1302136644Sache 1303136644Sache@end ftable 1304136644Sache 1305136644Sache@node Miscellaneous Commands 1306136644Sache@subsection Some Miscellaneous Commands 1307136644Sache@ftable @code 1308136644Sache 1309136644Sache@item re-read-init-file (C-x C-r) 1310136644SacheRead in the contents of the @var{inputrc} file, and incorporate 1311136644Sacheany bindings or variable assignments found there. 1312136644Sache 1313136644Sache@item abort (C-g) 1314136644SacheAbort the current editing command and 1315136644Sachering the terminal's bell (subject to the setting of 1316136644Sache@code{bell-style}). 1317136644Sache 1318136644Sache@item do-uppercase-version (M-a, M-b, M-@var{x}, @dots{}) 1319136644SacheIf the metafied character @var{x} is lowercase, run the command 1320136644Sachethat is bound to the corresponding uppercase character. 1321136644Sache 1322136644Sache@item prefix-meta (@key{ESC}) 1323136644SacheMetafy the next character typed. This is for keyboards 1324136644Sachewithout a meta key. Typing @samp{@key{ESC} f} is equivalent to typing 1325136644Sache@kbd{M-f}. 1326136644Sache 1327136644Sache@item undo (C-_ or C-x C-u) 1328136644SacheIncremental undo, separately remembered for each line. 1329136644Sache 1330136644Sache@item revert-line (M-r) 1331136644SacheUndo all changes made to this line. This is like executing the @code{undo} 1332136644Sachecommand enough times to get back to the beginning. 1333136644Sache 1334136644Sache@ifset BashFeatures 1335136644Sache@item tilde-expand (M-&) 1336136644Sache@end ifset 1337136644Sache@ifclear BashFeatures 1338136644Sache@item tilde-expand (M-~) 1339136644Sache@end ifclear 1340136644SachePerform tilde expansion on the current word. 1341136644Sache 1342136644Sache@item set-mark (C-@@) 1343136644SacheSet the mark to the point. If a 1344136644Sachenumeric argument is supplied, the mark is set to that position. 1345136644Sache 1346136644Sache@item exchange-point-and-mark (C-x C-x) 1347136644SacheSwap the point with the mark. The current cursor position is set to 1348136644Sachethe saved position, and the old cursor position is saved as the mark. 1349136644Sache 1350136644Sache@item character-search (C-]) 1351136644SacheA character is read and point is moved to the next occurrence of that 1352136644Sachecharacter. A negative count searches for previous occurrences. 1353136644Sache 1354136644Sache@item character-search-backward (M-C-]) 1355136644SacheA character is read and point is moved to the previous occurrence 1356136644Sacheof that character. A negative count searches for subsequent 1357136644Sacheoccurrences. 1358136644Sache 1359136644Sache@item insert-comment (M-#) 1360136644SacheWithout a numeric argument, the value of the @code{comment-begin} 1361136644Sachevariable is inserted at the beginning of the current line. 1362136644SacheIf a numeric argument is supplied, this command acts as a toggle: if 1363136644Sachethe characters at the beginning of the line do not match the value 1364136644Sacheof @code{comment-begin}, the value is inserted, otherwise 1365136644Sachethe characters in @code{comment-begin} are deleted from the beginning of 1366136644Sachethe line. 1367136644SacheIn either case, the line is accepted as if a newline had been typed. 1368136644Sache@ifset BashFeatures 1369136644SacheThe default value of @code{comment-begin} causes this command 1370136644Sacheto make the current line a shell comment. 1371136644SacheIf a numeric argument causes the comment character to be removed, the line 1372136644Sachewill be executed by the shell. 1373136644Sache@end ifset 1374136644Sache 1375136644Sache@item dump-functions () 1376136644SachePrint all of the functions and their key bindings to the 1377136644SacheReadline output stream. If a numeric argument is supplied, 1378136644Sachethe output is formatted in such a way that it can be made part 1379136644Sacheof an @var{inputrc} file. This command is unbound by default. 1380136644Sache 1381136644Sache@item dump-variables () 1382136644SachePrint all of the settable variables and their values to the 1383136644SacheReadline output stream. If a numeric argument is supplied, 1384136644Sachethe output is formatted in such a way that it can be made part 1385136644Sacheof an @var{inputrc} file. This command is unbound by default. 1386136644Sache 1387136644Sache@item dump-macros () 1388136644SachePrint all of the Readline key sequences bound to macros and the 1389136644Sachestrings they output. If a numeric argument is supplied, 1390136644Sachethe output is formatted in such a way that it can be made part 1391136644Sacheof an @var{inputrc} file. This command is unbound by default. 1392136644Sache 1393136644Sache@ifset BashFeatures 1394136644Sache@item glob-complete-word (M-g) 1395136644SacheThe word before point is treated as a pattern for pathname expansion, 1396136644Sachewith an asterisk implicitly appended. This pattern is used to 1397136644Sachegenerate a list of matching file names for possible completions. 1398136644Sache 1399136644Sache@item glob-expand-word (C-x *) 1400136644SacheThe word before point is treated as a pattern for pathname expansion, 1401136644Sacheand the list of matching file names is inserted, replacing the word. 1402136644SacheIf a numeric argument is supplied, a @samp{*} is appended before 1403136644Sachepathname expansion. 1404136644Sache 1405136644Sache@item glob-list-expansions (C-x g) 1406136644SacheThe list of expansions that would have been generated by 1407136644Sache@code{glob-expand-word} is displayed, and the line is redrawn. 1408136644SacheIf a numeric argument is supplied, a @samp{*} is appended before 1409136644Sachepathname expansion. 1410136644Sache 1411136644Sache@item display-shell-version (C-x C-v) 1412136644SacheDisplay version information about the current instance of Bash. 1413136644Sache 1414136644Sache@item shell-expand-line (M-C-e) 1415136644SacheExpand the line as the shell does. 1416136644SacheThis performs alias and history expansion as well as all of the shell 1417136644Sacheword expansions (@pxref{Shell Expansions}). 1418136644Sache 1419136644Sache@item history-expand-line (M-^) 1420136644SachePerform history expansion on the current line. 1421136644Sache 1422136644Sache@item magic-space () 1423136644SachePerform history expansion on the current line and insert a space 1424136644Sache(@pxref{History Interaction}). 1425136644Sache 1426136644Sache@item alias-expand-line () 1427136644SachePerform alias expansion on the current line (@pxref{Aliases}). 1428136644Sache 1429136644Sache@item history-and-alias-expand-line () 1430136644SachePerform history and alias expansion on the current line. 1431136644Sache 1432136644Sache@item insert-last-argument (M-. or M-_) 1433136644SacheA synonym for @code{yank-last-arg}. 1434136644Sache 1435136644Sache@item operate-and-get-next (C-o) 1436136644SacheAccept the current line for execution and fetch the next line 1437136644Sacherelative to the current line from the history for editing. Any 1438136644Sacheargument is ignored. 1439136644Sache 1440136644Sache@item edit-and-execute-command (C-xC-e) 1441136644SacheInvoke an editor on the current command line, and execute the result as shell 1442136644Sachecommands. 1443136644SacheBash attempts to invoke 1444136644Sache@code{$VISUAL}, @code{$EDITOR}, and @code{emacs} 1445136644Sacheas the editor, in that order. 1446136644Sache 1447136644Sache@end ifset 1448136644Sache 1449136644Sache@ifclear BashFeatures 1450136644Sache@item emacs-editing-mode (C-e) 1451136644SacheWhen in @code{vi} command mode, this causes a switch to @code{emacs} 1452136644Sacheediting mode. 1453136644Sache 1454136644Sache@item vi-editing-mode (M-C-j) 1455136644SacheWhen in @code{emacs} editing mode, this causes a switch to @code{vi} 1456136644Sacheediting mode. 1457136644Sache 1458136644Sache@end ifclear 1459136644Sache 1460136644Sache@end ftable 1461136644Sache 1462136644Sache@node Readline vi Mode 1463136644Sache@section Readline vi Mode 1464136644Sache 1465136644SacheWhile the Readline library does not have a full set of @code{vi} 1466136644Sacheediting functions, it does contain enough to allow simple editing 1467136644Sacheof the line. The Readline @code{vi} mode behaves as specified in 1468136644Sachethe @sc{posix} 1003.2 standard. 1469136644Sache 1470136644Sache@ifset BashFeatures 1471136644SacheIn order to switch interactively between @code{emacs} and @code{vi} 1472136644Sacheediting modes, use the @samp{set -o emacs} and @samp{set -o vi} 1473136644Sachecommands (@pxref{The Set Builtin}). 1474136644Sache@end ifset 1475136644Sache@ifclear BashFeatures 1476136644SacheIn order to switch interactively between @code{emacs} and @code{vi} 1477136644Sacheediting modes, use the command @kbd{M-C-j} (bound to emacs-editing-mode 1478136644Sachewhen in @code{vi} mode and to vi-editing-mode in @code{emacs} mode). 1479136644Sache@end ifclear 1480136644SacheThe Readline default is @code{emacs} mode. 1481136644Sache 1482136644SacheWhen you enter a line in @code{vi} mode, you are already placed in 1483136644Sache`insertion' mode, as if you had typed an @samp{i}. Pressing @key{ESC} 1484136644Sacheswitches you into `command' mode, where you can edit the text of the 1485136644Sacheline with the standard @code{vi} movement keys, move to previous 1486136644Sachehistory lines with @samp{k} and subsequent lines with @samp{j}, and 1487136644Sacheso forth. 1488136644Sache 1489136644Sache@ifset BashFeatures 1490136644Sache@node Programmable Completion 1491136644Sache@section Programmable Completion 1492136644Sache@cindex programmable completion 1493136644Sache 1494136644SacheWhen word completion is attempted for an argument to a command for 1495136644Sachewhich a completion specification (a @var{compspec}) has been defined 1496136644Sacheusing the @code{complete} builtin (@pxref{Programmable Completion Builtins}), 1497136644Sachethe programmable completion facilities are invoked. 1498136644Sache 1499136644SacheFirst, the command name is identified. 1500136644SacheIf a compspec has been defined for that command, the 1501136644Sachecompspec is used to generate the list of possible completions for the word. 1502136644SacheIf the command word is a full pathname, a compspec for the full 1503136644Sachepathname is searched for first. 1504136644SacheIf no compspec is found for the full pathname, an attempt is made to 1505136644Sachefind a compspec for the portion following the final slash. 1506136644Sache 1507136644SacheOnce a compspec has been found, it is used to generate the list of 1508136644Sachematching words. 1509136644SacheIf a compspec is not found, the default Bash completion 1510136644Sachedescribed above (@pxref{Commands For Completion}) is performed. 1511136644Sache 1512136644SacheFirst, the actions specified by the compspec are used. 1513136644SacheOnly matches which are prefixed by the word being completed are 1514136644Sachereturned. 1515136644SacheWhen the @option{-f} or @option{-d} option is used for filename or 1516136644Sachedirectory name completion, the shell variable @env{FIGNORE} is 1517136644Sacheused to filter the matches. 1518136644Sache@xref{Bash Variables}, for a description of @env{FIGNORE}. 1519136644Sache 1520136644SacheAny completions specified by a filename expansion pattern to the 1521136644Sache@option{-G} option are generated next. 1522136644SacheThe words generated by the pattern need not match the word being completed. 1523136644SacheThe @env{GLOBIGNORE} shell variable is not used to filter the matches, 1524136644Sachebut the @env{FIGNORE} shell variable is used. 1525136644Sache 1526136644SacheNext, the string specified as the argument to the @option{-W} option 1527136644Sacheis considered. 1528136644SacheThe string is first split using the characters in the @env{IFS} 1529136644Sachespecial variable as delimiters. 1530136644SacheShell quoting is honored. 1531136644SacheEach word is then expanded using 1532136644Sachebrace expansion, tilde expansion, parameter and variable expansion, 1533136644Sachecommand substitution, arithmetic expansion, and pathname expansion, 1534136644Sacheas described above (@pxref{Shell Expansions}). 1535136644SacheThe results are split using the rules described above 1536136644Sache(@pxref{Word Splitting}). 1537136644SacheThe results of the expansion are prefix-matched against the word being 1538136644Sachecompleted, and the matching words become the possible completions. 1539136644Sache 1540136644SacheAfter these matches have been generated, any shell function or command 1541136644Sachespecified with the @option{-F} and @option{-C} options is invoked. 1542136644SacheWhen the command or function is invoked, the @env{COMP_LINE} and 1543136644Sache@env{COMP_POINT} variables are assigned values as described above 1544136644Sache(@pxref{Bash Variables}). 1545136644SacheIf a shell function is being invoked, the @env{COMP_WORDS} and 1546136644Sache@env{COMP_CWORD} variables are also set. 1547136644SacheWhen the function or command is invoked, the first argument is the 1548136644Sachename of the command whose arguments are being completed, the 1549136644Sachesecond argument is the word being completed, and the third argument 1550136644Sacheis the word preceding the word being completed on the current command line. 1551136644SacheNo filtering of the generated completions against the word being completed 1552136644Sacheis performed; the function or command has complete freedom in generating 1553136644Sachethe matches. 1554136644Sache 1555136644SacheAny function specified with @option{-F} is invoked first. 1556136644SacheThe function may use any of the shell facilities, including the 1557136644Sache@code{compgen} builtin described below 1558136644Sache(@pxref{Programmable Completion Builtins}), to generate the matches. 1559136644SacheIt must put the possible completions in the @env{COMPREPLY} array 1560136644Sachevariable. 1561136644Sache 1562136644SacheNext, any command specified with the @option{-C} option is invoked 1563136644Sachein an environment equivalent to command substitution. 1564136644SacheIt should print a list of completions, one per line, to 1565136644Sachethe standard output. 1566136644SacheBackslash may be used to escape a newline, if necessary. 1567136644Sache 1568136644SacheAfter all of the possible completions are generated, any filter 1569136644Sachespecified with the @option{-X} option is applied to the list. 1570136644SacheThe filter is a pattern as used for pathname expansion; a @samp{&} 1571136644Sachein the pattern is replaced with the text of the word being completed. 1572136644SacheA literal @samp{&} may be escaped with a backslash; the backslash 1573136644Sacheis removed before attempting a match. 1574136644SacheAny completion that matches the pattern will be removed from the list. 1575136644SacheA leading @samp{!} negates the pattern; in this case any completion 1576136644Sachenot matching the pattern will be removed. 1577136644Sache 1578136644SacheFinally, any prefix and suffix specified with the @option{-P} and @option{-S} 1579136644Sacheoptions are added to each member of the completion list, and the result is 1580136644Sachereturned to the Readline completion code as the list of possible 1581136644Sachecompletions. 1582136644Sache 1583136644SacheIf the previously-applied actions do not generate any matches, and the 1584136644Sache@option{-o dirnames} option was supplied to @code{complete} when the 1585136644Sachecompspec was defined, directory name completion is attempted. 1586136644Sache 1587136644SacheIf the @option{-o plusdirs} option was supplied to @code{complete} when 1588136644Sachethe compspec was defined, directory name completion is attempted and any 1589136644Sachematches are added to the results of the other actions. 1590136644Sache 1591136644SacheBy default, if a compspec is found, whatever it generates is returned to 1592136644Sachethe completion code as the full set of possible completions. 1593136644SacheThe default Bash completions are not attempted, and the Readline default 1594136644Sacheof filename completion is disabled. 1595136644SacheIf the @option{-o bashdefault} option was supplied to @code{complete} when 1596136644Sachethe compspec was defined, the default Bash completions are attempted 1597136644Sacheif the compspec generates no matches. 1598136644SacheIf the @option{-o default} option was supplied to @code{complete} when the 1599136644Sachecompspec was defined, Readline's default completion will be performed 1600136644Sacheif the compspec (and, if attempted, the default Bash completions) 1601136644Sachegenerate no matches. 1602136644Sache 1603136644SacheWhen a compspec indicates that directory name completion is desired, 1604136644Sachethe programmable completion functions force Readline to append a slash 1605136644Sacheto completed names which are symbolic links to directories, subject to 1606136644Sachethe value of the @var{mark-directories} Readline variable, regardless 1607136644Sacheof the setting of the @var{mark-symlinked-directories} Readline variable. 1608136644Sache 1609136644Sache@node Programmable Completion Builtins 1610136644Sache@section Programmable Completion Builtins 1611136644Sache@cindex completion builtins 1612136644Sache 1613136644SacheTwo builtin commands are available to manipulate the programmable completion 1614136644Sachefacilities. 1615136644Sache 1616136644Sache@table @code 1617136644Sache@item compgen 1618136644Sache@btindex compgen 1619136644Sache@example 1620136644Sache@code{compgen [@var{option}] [@var{word}]} 1621136644Sache@end example 1622136644Sache 1623136644SacheGenerate possible completion matches for @var{word} according to 1624136644Sachethe @var{option}s, which may be any option accepted by the 1625136644Sache@code{complete} 1626136644Sachebuiltin with the exception of @option{-p} and @option{-r}, and write 1627136644Sachethe matches to the standard output. 1628136644SacheWhen using the @option{-F} or @option{-C} options, the various shell variables 1629136644Sacheset by the programmable completion facilities, while available, will not 1630136644Sachehave useful values. 1631136644Sache 1632136644SacheThe matches will be generated in the same way as if the programmable 1633136644Sachecompletion code had generated them directly from a completion specification 1634136644Sachewith the same flags. 1635136644SacheIf @var{word} is specified, only those completions matching @var{word} 1636136644Sachewill be displayed. 1637136644Sache 1638136644SacheThe return value is true unless an invalid option is supplied, or no 1639136644Sachematches were generated. 1640136644Sache 1641136644Sache@item complete 1642136644Sache@btindex complete 1643136644Sache@example 1644136644Sache@code{complete [-abcdefgjksuv] [-o @var{comp-option}] [-A @var{action}] [-G @var{globpat}] [-W @var{wordlist}] 1645136644Sache[-P @var{prefix}] [-S @var{suffix}] [-X @var{filterpat}] [-F @var{function}] 1646136644Sache[-C @var{command}] @var{name} [@var{name} @dots{}]} 1647136644Sache@code{complete -pr [@var{name} @dots{}]} 1648136644Sache@end example 1649136644Sache 1650136644SacheSpecify how arguments to each @var{name} should be completed. 1651136644SacheIf the @option{-p} option is supplied, or if no options are supplied, existing 1652136644Sachecompletion specifications are printed in a way that allows them to be 1653136644Sachereused as input. 1654136644SacheThe @option{-r} option removes a completion specification for 1655136644Sacheeach @var{name}, or, if no @var{name}s are supplied, all 1656136644Sachecompletion specifications. 1657136644Sache 1658136644SacheThe process of applying these completion specifications when word completion 1659136644Sacheis attempted is described above (@pxref{Programmable Completion}). 1660136644Sache 1661136644SacheOther options, if specified, have the following meanings. 1662136644SacheThe arguments to the @option{-G}, @option{-W}, and @option{-X} options 1663136644Sache(and, if necessary, the @option{-P} and @option{-S} options) 1664136644Sacheshould be quoted to protect them from expansion before the 1665136644Sache@code{complete} builtin is invoked. 1666136644Sache 1667136644Sache 1668136644Sache@table @code 1669136644Sache@item -o @var{comp-option} 1670136644SacheThe @var{comp-option} controls several aspects of the compspec's behavior 1671136644Sachebeyond the simple generation of completions. 1672136644Sache@var{comp-option} may be one of: 1673136644Sache 1674136644Sache@table @code 1675136644Sache 1676136644Sache@item bashdefault 1677136644SachePerform the rest of the default Bash completions if the compspec 1678136644Sachegenerates no matches. 1679136644Sache 1680136644Sache@item default 1681136644SacheUse Readline's default filename completion if the compspec generates 1682136644Sacheno matches. 1683136644Sache 1684136644Sache@item dirnames 1685136644SachePerform directory name completion if the compspec generates no matches. 1686136644Sache 1687136644Sache@item filenames 1688136644SacheTell Readline that the compspec generates filenames, so it can perform any 1689136644Sachefilename-specific processing (like adding a slash to directory names or 1690136644Sachesuppressing trailing spaces). This option is intended to be used with 1691136644Sacheshell functions specified with @option{-F}. 1692136644Sache 1693136644Sache@item nospace 1694136644SacheTell Readline not to append a space (the default) to words completed at 1695136644Sachethe end of the line. 1696136644Sache@end table 1697136644Sache 1698136644Sache@item -A @var{action} 1699136644SacheThe @var{action} may be one of the following to generate a list of possible 1700136644Sachecompletions: 1701136644Sache 1702136644Sache@table @code 1703136644Sache@item alias 1704136644SacheAlias names. May also be specified as @option{-a}. 1705136644Sache 1706136644Sache@item arrayvar 1707136644SacheArray variable names. 1708136644Sache 1709136644Sache@item binding 1710136644SacheReadline key binding names (@pxref{Bindable Readline Commands}). 1711136644Sache 1712136644Sache@item builtin 1713136644SacheNames of shell builtin commands. May also be specified as @option{-b}. 1714136644Sache 1715136644Sache@item command 1716136644SacheCommand names. May also be specified as @option{-c}. 1717136644Sache 1718136644Sache@item directory 1719136644SacheDirectory names. May also be specified as @option{-d}. 1720136644Sache 1721136644Sache@item disabled 1722136644SacheNames of disabled shell builtins. 1723136644Sache 1724136644Sache@item enabled 1725136644SacheNames of enabled shell builtins. 1726136644Sache 1727136644Sache@item export 1728136644SacheNames of exported shell variables. May also be specified as @option{-e}. 1729136644Sache 1730136644Sache@item file 1731136644SacheFile names. May also be specified as @option{-f}. 1732136644Sache 1733136644Sache@item function 1734136644SacheNames of shell functions. 1735136644Sache 1736136644Sache@item group 1737136644SacheGroup names. May also be specified as @option{-g}. 1738136644Sache 1739136644Sache@item helptopic 1740136644SacheHelp topics as accepted by the @code{help} builtin (@pxref{Bash Builtins}). 1741136644Sache 1742136644Sache@item hostname 1743136644SacheHostnames, as taken from the file specified by the 1744136644Sache@env{HOSTFILE} shell variable (@pxref{Bash Variables}). 1745136644Sache 1746136644Sache@item job 1747136644SacheJob names, if job control is active. May also be specified as @option{-j}. 1748136644Sache 1749136644Sache@item keyword 1750136644SacheShell reserved words. May also be specified as @option{-k}. 1751136644Sache 1752136644Sache@item running 1753136644SacheNames of running jobs, if job control is active. 1754136644Sache 1755136644Sache@item service 1756136644SacheService names. May also be specified as @option{-s}. 1757136644Sache 1758136644Sache@item setopt 1759136644SacheValid arguments for the @option{-o} option to the @code{set} builtin 1760136644Sache(@pxref{The Set Builtin}). 1761136644Sache 1762136644Sache@item shopt 1763136644SacheShell option names as accepted by the @code{shopt} builtin 1764136644Sache(@pxref{Bash Builtins}). 1765136644Sache 1766136644Sache@item signal 1767136644SacheSignal names. 1768136644Sache 1769136644Sache@item stopped 1770136644SacheNames of stopped jobs, if job control is active. 1771136644Sache 1772136644Sache@item user 1773136644SacheUser names. May also be specified as @option{-u}. 1774136644Sache 1775136644Sache@item variable 1776136644SacheNames of all shell variables. May also be specified as @option{-v}. 1777136644Sache@end table 1778136644Sache 1779136644Sache@item -G @var{globpat} 1780136644SacheThe filename expansion pattern @var{globpat} is expanded to generate 1781136644Sachethe possible completions. 1782136644Sache 1783136644Sache@item -W @var{wordlist} 1784136644SacheThe @var{wordlist} is split using the characters in the 1785136644Sache@env{IFS} special variable as delimiters, and each resultant word 1786136644Sacheis expanded. 1787136644SacheThe possible completions are the members of the resultant list which 1788136644Sachematch the word being completed. 1789136644Sache 1790136644Sache@item -C @var{command} 1791136644Sache@var{command} is executed in a subshell environment, and its output is 1792136644Sacheused as the possible completions. 1793136644Sache 1794136644Sache@item -F @var{function} 1795136644SacheThe shell function @var{function} is executed in the current shell 1796136644Sacheenvironment. 1797136644SacheWhen it finishes, the possible completions are retrieved from the value 1798136644Sacheof the @env{COMPREPLY} array variable. 1799136644Sache 1800136644Sache@item -X @var{filterpat} 1801136644Sache@var{filterpat} is a pattern as used for filename expansion. 1802136644SacheIt is applied to the list of possible completions generated by the 1803136644Sachepreceding options and arguments, and each completion matching 1804136644Sache@var{filterpat} is removed from the list. 1805136644SacheA leading @samp{!} in @var{filterpat} negates the pattern; in this 1806136644Sachecase, any completion not matching @var{filterpat} is removed. 1807136644Sache 1808136644Sache@item -P @var{prefix} 1809136644Sache@var{prefix} is added at the beginning of each possible completion 1810136644Sacheafter all other options have been applied. 1811136644Sache 1812136644Sache@item -S @var{suffix} 1813136644Sache@var{suffix} is appended to each possible completion 1814136644Sacheafter all other options have been applied. 1815136644Sache@end table 1816136644Sache 1817136644SacheThe return value is true unless an invalid option is supplied, an option 1818136644Sacheother than @option{-p} or @option{-r} is supplied without a @var{name} 1819136644Sacheargument, an attempt is made to remove a completion specification for 1820136644Sachea @var{name} for which no specification exists, or 1821136644Sachean error occurs adding a completion specification. 1822136644Sache 1823136644Sache@end table 1824136644Sache@end ifset 1825