1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
<h1 class="subsection">Conditional Init Constructs</h1> <p>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. </p> <dl compact> <dt><span><code>$if</code></span></dt> <dd>
<p>The <code>$if</code> 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. </p> <dl compact> <dt><span><code>mode</code></span></dt> <dd>
<p>The <code>mode=</code> form of the <code>$if</code> directive is used to test whether Readline is in <code>emacs</code> or <code>vi</code> mode. This may be used in conjunction with the ‘<samp>set keymap</samp>’ command, for instance, to set bindings in the <code>emacs-standard</code> and <code>emacs-ctlx</code> keymaps only if Readline is starting out in <code>emacs</code> mode. </p> </dd> <dt><span><code>term</code></span></dt> <dd>
<p>The <code>term=</code> 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 ‘<samp>=</samp>’ is tested against both the full name of the terminal and the portion of the terminal name before the first ‘<samp>-</samp>’. This allows <code>sun</code> to match both <code>sun</code> and <code>sun-cmd</code>, for instance. </p> </dd> <dt><span><code>version</code></span></dt> <dd>
<p>The <code>version</code> test may be used to perform comparisons against specific Readline versions. The <code>version</code> expands to the current Readline version. The set of comparison operators includes ‘<samp>=</samp>’ (and ‘<samp>==</samp>’), ‘<samp>!=</samp>’, ‘<samp><=</samp>’, ‘<samp>>=</samp>’, ‘<samp><</samp>’, and ‘<samp>></samp>’. 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., ‘<samp>7.1</samp>’). If the minor version is omitted, it is assumed to be ‘<samp>0</samp>’. The operator may be separated from the string <code>version</code> 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: </p>
<div class="example"> <pre class="example">$if version >= 7.0
set show-mode-in-prompt on
$endif
</pre>
</div> </dd> <dt><span><code>application</code></span></dt> <dd>
<p>The <var>application</var> construct is used to include application-specific settings. Each program using the Readline library sets the <var>application name</var>, and you can test for a particular value. This could be used to bind key sequences to functions useful for a specific program. For instance, the following command adds a key sequence that quotes the current or previous word in Bash: </p>
<div class="example"> <pre class="example">$if Bash
# Quote the current or previous word
"\C-xq": "\eb\"\ef\""
$endif
</pre>
</div> </dd> <dt><span><code>variable</code></span></dt> <dd>
<p>The <var>variable</var> construct provides simple equality tests for Readline variables and values. The permitted comparison operators are ‘<samp>=</samp>’, ‘<samp>==</samp>’, and ‘<samp>!=</samp>’. The variable name must be separated from the comparison operator by whitespace; the operator may be separated from the value on the right hand side by whitespace. Both string and boolean variables may be tested. Boolean variables must be tested against the values <var>on</var> and <var>off</var>. The following example is equivalent to the <code>mode=emacs</code> test described above: </p>
<div class="example"> <pre class="example">$if editing-mode == emacs
set show-mode-in-prompt on
$endif
</pre>
</div> </dd> </dl> </dd> <dt><span><code>$endif</code></span></dt> <dd>
<p>This command, as seen in the previous example, terminates an <code>$if</code> command. </p> </dd> <dt><span><code>$else</code></span></dt> <dd>
<p>Commands in this branch of the <code>$if</code> directive are executed if the test fails. </p> </dd> <dt><span><code>$include</code></span></dt> <dd>
<p>This directive takes a single filename as an argument and reads commands and bindings from that file. For example, the following directive reads from <samp>/etc/inputrc</samp>: </p>
<div class="example"> <pre class="example">$include /etc/inputrc
</pre>
</div> </dd> </dl><div class="_attribution">
<p class="_attribution-p">
Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.<br>Licensed under the GNU Free Documentation License.<br>
<a href="https://www.gnu.org/software/bash/manual/html_node/Conditional-Init-Constructs.html" class="_attribution-link">https://www.gnu.org/software/bash/manual/html_node/Conditional-Init-Constructs.html</a>
</p>
</div>
|