GNU Readline
Template:Short description Script error: No such module "Infobox".Template:Template otherScript error: No such module "Check for unknown parameters".Template:Main other GNU Readline is a software library that provides in-line editing and history capabilities for interactive programs with a command-line interface, such as Bash. It is currently maintained by Chet Ramey as part of the GNU Project.
It allows users to move the text cursor, search the command history, control a kill ring (a more flexible version of a copy/paste clipboard) and use tab completion on a text terminal. As a cross-platform library, readline allows applications on various systems to exhibit identical line-editing behavior.
Editing modes
Readline supports both Emacs and vi editing modes, which determine how keyboard input is interpreted as editor commands. See Template:Section link.
Emacs keyboard shortcuts
Emacs editing mode key bindings are taken from the text editor Emacs.
On some systems, Template:Key press must be used instead of Template:Key press, because the Template:Key press shortcut conflicts with another shortcut. For example, pressing Template:Key press in Xfce's terminal emulator window does not move the cursor forward one word, but activates "File" in the menu of the terminal window, unless that is disabled in the emulator's settings.
- Template:Key press : Autocompletes from the cursor position.
- Template:Key press : Moves the cursor to the line start (equivalent to the key Template:Key press).
- Template:Key press : Moves the cursor back one character (equivalent to the key Template:Key press).
- Template:Key press : Sends the signal SIGINT via pseudoterminal to the current task, which aborts and closes it.Template:Efn
- Template:Key press
- Sends an EOF marker, which (unless disabled by an option) closes the current shell (equivalent to the command
exit). (Only if there is no text on the current line) - If there is text on the current line, deletes the current character (then equivalent to the key Template:Key press).
- Sends an EOF marker, which (unless disabled by an option) closes the current shell (equivalent to the command
- Template:Key press : (end) moves the cursor to the line end (equivalent to the key Template:Key press).
- Template:Key press : Moves the cursor forward one character (equivalent to the key Template:Key press).
- Template:Key press : Abort the reverse search and restore the original line.
- Template:Key press : Deletes the previous character (same as backspace).
- Template:Key press : Equivalent to the tab key.
- Template:Key press : Equivalent to the enter key.
- Template:Key press : Clears the line content after the cursor and copies it into the clipboard.
- Template:Key press : Clears the screen content (equivalent to the command
clear). - Template:Key press : (next) recalls the next command (equivalent to the key Template:Key press).
- Template:Key press : Executes the found command from history, and fetch the next line relative to the current line from the history for editing.
- Template:Key press : (previous) recalls the prior command (equivalent to the key Template:Key press).
- Template:Key press : (reverse search) recalls the last command including the specified characters. A second Template:Key press recalls the next anterior command that corresponds to the search.
- Template:Key press : Go back to the next more recent command of the reverse search (beware to not execute it from a terminal because this command also launches its XOFF). If you changed that XOFF setting, use Template:Key press to return.
- Template:Key press : Transpose the previous two characters.
- Template:Key press : Clears the line content before the cursor and copies it into the clipboard.
- Template:Key press : If the next input is also a control sequence, type it literally (e. g. * Template:Key press Template:Key press types "^H", a literal backspace).
- Template:Key press : Clears the word before the cursor and copies it into the clipboard.
- Template:Key press Template:Key press : Edits the current line in the $EDITOR program, or vi if undefined.
- Template:Key press Template:Key press : Read in the contents of the inputrc file, and incorporate any bindings or variable assignments found there.
- Template:Key press Template:Key press : Incremental undo, separately remembered for each line.
- Template:Key press Template:Key press : Display version information about the current instance of Bash.
- Template:Key press Template:Key press : Alternates the cursor with its old position. (C-x, because x has a crossing shape).
- Template:Key press : (yank) adds the clipboard content from the cursor position.
- Template:Key press : Sends the signal SIGTSTP to the current task, which suspends it. To execute it in background one can enter
bg. To bring it back from background or suspensionfg ['process name or job id'](foreground) can be issued. - Template:Key press : Incremental undo, separately remembered for each line.
- Template:Key press : (backward) moves the cursor backward one word.
- Template:Key press : Capitalizes the character under the cursor and moves to the end of the word.
- Template:Key press : Cuts the word after the cursor.
- Template:Key press : (forward) moves the cursor forward one word.
- Template:Key press : Lowers the case of every character from the cursor's position to the end of the current word.
- Template:Key press : Cancels the changes and puts back the line as it was in the history.
- Template:Key press : Capitalizes every character from the cursor's position to the end of the current word.
- Template:Key press : Insert the last argument to the previous command (the last word of the previous history entry).
Choice of the GPL as GNU Readline's license
GNU Readline is notable for being a free software library which is licensed under the GNU General Public License (GPL). Free software libraries are far more often licensed under the GNU Lesser General Public License (LGPL), for example, the GNU C Library, GNU gettext and FLTK. A developer of an application who chooses to link to an LGPLv3 licensed library can use any license that does not: "restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications".[1] But linking to a GPLv3 licensed library such as Readline requires the entire combined resulting application to be licensed under the GPLv3 when distributed, to comply with section 5 of the GPL.[2][3]
This licensing was chosen by the FSF on the hopes that it would encourage software to switch to the GPL.[4] An important example of an application changing its licensing to comply with the copyleft conditions of GNU Readline is CLISP, an implementation of Common Lisp. Originally released in 1987, it changed to the GPL license in 1992,[5] after an email exchange between one of CLISP's original authors, Bruno Haible, and Richard Stallman, in which Stallman argued[6] that the linking of readline in CLISP meant that Haible was required to re-license CLISP under the GPL if he wished to distribute the implementation of CLISP which used readline.[7]
Another response has been to not use this in some projects, making text input use the primitive Unix terminal driver for editing.
Alternative libraries
Alternative libraries have been created with other licenses so they can be used by software projects which want to implement command line editing functionality, but be released with a non-GPL license.
- Many BSD systems have a BSD-licensed libedit.[8][9] MariaDB and PHP allow for the user to select at build time whether to link with GNU Readline or with libedit.[10][11]
- linenoise is a tiny C library that provides line editing functions.[12] Template:As of it is prominently used by MongoDB and Redis.[13][14] It was integrated into Android in 2010, but has since been deprecated.[15][16]
- Haskeline is a BSD-3-Clause licensed readline-like library for Haskell. It is mainly written for the Glasgow Haskell Compiler,[17] but is available to other Haskell projects which need line-editing services as well.[18]
- PSReadLine is a BSD-2-Clause licensed readline implementation written in C# for PowerShell inspired by bash and GNU Readline[19]
Sample code
The following code is in C and must be linked against the readline library by passing a Template:Mono flag to the compiler:
#include <stdlib.h>
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
int main()
{
// Configure readline to auto-complete paths when the tab key is hit.
rl_bind_key('\t', rl_complete);
// Enable history
using_history();
while (1) {
// Display prompt and read input
char* input = readline("prompt> ");
// Check for EOF.
if (!input)
break;
// Add input to readline history.
add_history(input);
// Do stuff...
// Free buffer that was allocated by readline
free(input);
}
return 0;
}
Bindings
Non-C programming languages that provide language bindings for readline include
- Python's built-in
readlinemodule; - Ruby's built-in
readlinemodule;[20] - Perl's third-party (CPAN)
Term::ReadLinemodule, specificallyTerm::ReadLine::Gnufor GNU ReadLine. - PHP's extension.[21]
Support for readline alternatives differ among these bindings.
Notes
References
External links
Script error: No such module "Portal".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Editline Library (libedit)
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".