bash: Conditional Init Constructs
1
1 8.3.2 Conditional Init Constructs
1 ---------------------------------
1
1 Readline implements a facility similar in spirit to the conditional
1 compilation features of the C preprocessor which allows key bindings and
1 variable settings to be performed as the result of tests. There are
1 four parser directives used.
1
1 '$if'
1 The '$if' construct allows bindings to be made based on the editing
1 mode, the terminal being used, or the application using Readline.
1 The text of the test extends to the end of the line; no characters
1 are required to isolate it.
1
1 'mode'
1 The 'mode=' form of the '$if' directive is used to test
1 whether Readline is in 'emacs' or 'vi' mode. This may be used
1 in conjunction with the 'set keymap' command, for instance, to
1 set bindings in the 'emacs-standard' and 'emacs-ctlx' keymaps
1 only if Readline is starting out in 'emacs' mode.
1
1 'term'
1 The 'term=' form may be used to include terminal-specific key
1 bindings, perhaps to bind the key sequences output by the
1 terminal's function keys. The word on the right side of the
1 '=' is tested against both the full name of the terminal and
1 the portion of the terminal name before the first '-'. This
1 allows 'sun' to match both 'sun' and 'sun-cmd', for instance.
1
1 'application'
1 The APPLICATION construct is used to include
1 application-specific settings. Each program using the
1 Readline library sets the APPLICATION NAME, and you can test
1 for a particular value. This could be used to bind key
1 sequences to functions useful for a specific program. For
1 instance, the following command adds a key sequence that
1 quotes the current or previous word in Bash:
1 $if Bash
1 # Quote the current or previous word
1 "\C-xq": "\eb\"\ef\""
1 $endif
1
1 '$endif'
1 This command, as seen in the previous example, terminates an '$if'
1 command.
1
1 '$else'
1 Commands in this branch of the '$if' directive are executed if the
1 test fails.
1
1 '$include'
1 This directive takes a single filename as an argument and reads
1 commands and bindings from that file. For example, the following
1 directive reads from '/etc/inputrc':
1 $include /etc/inputrc
1