rluser.texi 84 KB

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