Next: Sample Init File, Previous: Readline Init File Syntax, Up: Readline Init File
Readline implements a facility similar in spirit to the conditional compilation features of the C preprocessor which allows key bindings and variable settings to be performed as the result of tests. There are four parser directives used.
$if
$if
construct allows bindings to be made based on the
editing mode, the terminal being used, or the application using
Readline. The text of the test, after any comparison operator,
extends to the end of the line;
unless otherwise noted, no characters are required to isolate it.
mode
mode=
form of the $if
directive is used to test
whether Readline is in emacs
or vi
mode.
This may be used in conjunction
with the `set keymap' command, for instance, to set bindings in
the emacs-standard
and emacs-ctlx
keymaps only if
Readline is starting out in emacs
mode.
term
term=
form may be used to include terminal-specific
key bindings, perhaps to bind the key sequences output by the
terminal's function keys. The word on the right side of the
`=' is tested against both the full name of the terminal and
the portion of the terminal name before the first `-'. This
allows sun
to match both sun
and sun-cmd
,
for instance.
version
version
test may be used to perform comparisons against
specific Readline versions.
The version
expands to the current Readline version.
The set of comparison operators includes
`=' (and `=='), `!=', `<=', `>=', `<',
and `>'.
The version number supplied on the right side of the operator consists
of a major version number, an optional decimal point, and an optional
minor version (e.g., `7.1'). If the minor version is omitted, it
is assumed to be `0'.
The operator may be separated from the string version
and
from the version number argument by whitespace.
The following example sets a variable if the Readline version being used
is 7.0 or newer:
$if version >= 7.0 set show-mode-in-prompt on $endif
application
$if Bash # Quote the current or previous word "\C-xq": "\eb\"\ef\"" $endif
variable
mode=emacs
test described
above:
$if editing-mode == emacs set show-mode-in-prompt on $endif
$endif
$if
command.
$else
$if
directive are executed if
the test fails.
$include
$include /etc/inputrc