LinuxCommandLibrary

rlwrap

Adds readline support to commands

TLDR

Run a REPL command with line editing, persistent history and prompt completion

$ rlwrap [command]
copy

Use all words seen on input and output for prompt completion
$ rlwrap [[-r|--remember]] [command]
copy

Better prompt completion if prompts contain ANSI colour codes
$ rlwrap [[-A|--ansi-colour-aware]] [command]
copy

Enable filename completion (case sensitive)
$ rlwrap [[-c|--complete-filenames]] [command]
copy

Add coloured prompts, use colour name, or an ASCI-conformant colour specification. Use an uppercase colour name for bold styling
$ rlwrap [[-p|--prompt-colour=]][black|red|green|yellow|blue|cyan|purple|white|colour_spec] [command]
copy

SYNOPSIS

rlwrap [rlwrap options] command [command arguments ...]

PARAMETERS

-H file
    Specifies an alternative history file to use. By default, rlwrap uses .rlwrap_history in the user's home directory.

-f file
    Reads completion words from the specified file. Each line in the file is treated as a potential completion candidate.

-C name
    Uses the default completion file associated with the given name (e.g., sqlplus, ocaml) from standard system locations.

-c
    Disables word completion. Only line editing and history features will be active.

-i
    Makes word completion case-insensitive. When enabled, typing 'SELECT' will match 'select' during completion.

-l N
    Sets the maximum number of lines to store in the history file to N. Older entries are discarded if the limit is exceeded.

-S string
    Sets the prompt string that rlwrap displays. Useful for differentiating rlwrap's prompt from the wrapped command's own.

-z filter
    Loads a custom filter script or program. Filters can pre-process user input or post-process command output, allowing for advanced customizations like syntax highlighting or auto-indentation.

DESCRIPTION

rlwrap is a versatile utility that enhances command-line tools by providing readline-like functionality. Many interactive programs, such as database clients (e.g., sqlplus), language interpreters (e.g., ocaml), or debuggers (e.g., gdb), lack advanced features like line editing, command history, and tab completion. rlwrap addresses this by acting as a wrapper:

It runs the target command as a child process, intercepts its standard input and output, and processes user input using the powerful readline library before passing it to the wrapped command. This allows users to leverage familiar keyboard shortcuts for editing, recall past commands, and benefit from context-sensitive tab completion, significantly improving productivity and user experience even with applications not originally designed for such features. It supports custom history files, completion files, and advanced filtering for more complex interactions.

CAVEATS

rlwrap is a powerful tool, but it's not universally compatible. It may not work well with programs that use raw terminal modes, full-screen interactive applications (like vi or emacs, or other curses-based programs like htop), or applications that frequently redraw the screen without explicit line-by-line input. It can also sometimes interfere with a wrapped command's own minimal input handling. While generally negligible, there's a small performance overhead as rlwrap acts as an intermediary.

<B>FILTERS</B>

rlwrap supports "filters," which are external scripts or programs that can be loaded to preprocess user input before it's sent to the wrapped command, or post-process the command's output before it's displayed. This powerful feature allows for complex customizations, such as syntax highlighting, auto-indentation, or context-aware transformations, extending rlwrap's capabilities far beyond basic line editing.

<B>ENVIRONMENT VARIABLES</B>

rlwrap can be configured using several environment variables, such as RLWRAP_HOME to specify the directory for history and completion files, or RLWRAP_HISTORY_FILE to directly set the path to the history file. These variables provide an alternative or supplementary way to configure rlwrap's behavior without always needing to pass command-line options.

HISTORY

rlwrap was created by Hans Lub, with its first public release around 2004. Its development was motivated by the observation that many useful command-line tools did not integrate with the powerful readline library, leading to a less efficient and less user-friendly interactive experience. Since its inception, rlwrap has steadily evolved, adding features such as support for custom completion files, advanced history management, and the ability to load external filters, making it an indispensable tool for many command-line users.

SEE ALSO

readline(3), bash(1), zsh(1), editline(3)

Copied to clipboard