libedit/readline
command line recall and editing
DESCRIPTION
The BSD libedit library or the GNU readline library may be optionally linked with spec during the spec installation. When spec is linked with either of these libraries, the following command completion, history substitution and command line editing features become available.
A prebuilt version of the libedit library is included in the spec distribution and linking with that library is spec's default configuration.
COMMAND COMPLETION
The <tab> key can be used to complete the current word being typed. The completion is context sensitive. If completion is asked for on the first word of a command, possible completions are all of spec's built-in keywords and currently defined macros.
Possible completion on words following the commands lsdef, prdef and undef are the currently defined macros. Possible completion on words following the commands syms and unglobal include all the current symbol names. Completion on words following lscmd are the built-in keywords. Possible completions to spec_par( are the available spec_par() options. In all other cases, possible completions on words following the first word of a command are all the file and directory names in the current directory.
If only one completion is possible, typing the <tab> key will generate the completion. If a small number of completions are available, typing the <tab> key twice will list them, followed by a redisplay of the current input line. If a large number of completions are possible, typing the <tab> will generate a prompt asking if all should be displayed.
TILDE EXPANSION
The sequences ~/ and ~any_user/ will be replaced by the full path names for the current user's and any user's home directory when those characters are used in the arguments to the open(), close(), on(), off(), dofile(), qdofile(), file_info(), getline(), array_read(), data_read(), array_dump(), data_dump(), h5_file(), fmt_read(), file_write(), fmt_close(), chdir() and unix() functions. The tilde sequences are also recognized by a spec server when included in the output property argument. Tilde expansion also applies when the tilde-containing arguments are passed to the functions through macros, such as through the standard newfile, do, cd, u, etc. macros.
Note, as of spec release 5.04.04, tilde expansion is available whether or not spec is linked with the command-line editing libraries.
HISTORY SUBSTITUTION - EVENT SPECIFIERS
All or part of a previous command can be recalled for the current command using a string starting with the ! event specifier character. The following event specifiers may appear anywhere in the input line.
- !!
- The previous command.
- !N
- Command number N.
- !-N
- The Nth previous command.
- !string
- The most recent command starting with string.
- !?string[?]
- The most recent command containing string. The trailing ? is optional at the end of a line.
HISTORY SUBSTITUTION - WORD DESIGNATORS
Individual words from previous commands can be recalled by adding a word designator to the event specifier. A colon (:) separates the two components and can be omitted if the word designator begins with the characters ^, $, * or %. Words are numbered from the beginning of the line, starting with a 0 (zero).
- 0
- The 0th word.
- N
- The Nth word.
- ^
- Word 1. !^ refers to word 1 of the previous command.
- $
- The last word. !$ refers to the last word of the previous command.
- %
- The word most recently matched by a ?string?.
- N-M
- A range of words; -N Abbreviates 0-N.
- *
- All of the words, except the 0th. This is the same as 1-$. If there is just one word (the 0th) in the event, an empty string is substituted.
- N*
- Same as N-$.
- N-
- Same as N-$, but doesn't include the last word.
HISTORY SUBSTITUTION - MODIFIERS
One or more modifiers may follow the optional word designator, each preceded by a :, as follows:
- #
- The entire command line typed so far.
- h
- Remove a trailing path name component of the form /pathname.
- r
- Remove a trailing suffix of the form .suffix.
- e
- Remove all but the suffix.
- t
- Remove all leading path name components.
- s/left/right[/]
- Substitute the first occurrence of the string left with the string right. The pattern delimiter can be any character. An & character in right is replaced by left, unless the & is preceded by a single backslash. The trailing delimiter is optional if right is at the end of the line.
- g
- When used with s, apply the substitution to each occurrence of the string left.
- p
- Print the new command but do not execute it.
The usage ^left^right^ is shorthand for !!:s/left/right/.
COMMAND LINE EDITING
The following special keys can be used to recall previous command lines and to modify the current command line. In addition to the control keys described below, the up and down arrow keys move through the history, while the left and right arrow keys move the cursor within the currently displayed line.
The command names listed for libedit and readline are the names you would use in an optional key-bindings file. See the documentation for libedit or readline for information on setting up their respective key bindings files. spec will arrange for a key-bindings file named .spec_keys in the spec user's home directory to be loaded, if it exists.
- ^A
Move to the beginning of the current line.
libedit: ed-move-to-begreadline: beginning-of-line- ^E
Move to the end of the current line.
libedit: ed-move-to-endreadline: end-of-line- ESC f
Move forward to the end of the next word.
libedit: em-next-wordreadline: forward-word- ESC b
Move to the start of the current or previous word.
libedit: ed-prev-wordreadline: backward-word- ^L
Clear the screen and reprint the current line at the top.
libedit: ed-clear-screenreadline: clear-screen- ^K
Kill from the cursor to the end of the line.
libedit: ed-kill-linereadline: kill-line- ESC d
Kill from the cursor to the end of the current word. If between words, kill to the end of the next word.
libedit: em-delete-next-wordreadline: kill-word- ESC DEL
Kill from the cursor the start of the previous word. If between words, kill to the start of the previous word.
libedit: ed-delete-prev-wordreadline: backward-kill-word- ^W
Kill from the cursor to the previous white space.
libedit: em_kill_regionreadline: unix-word-rubout- ^Y
Insert the most recently killed text at the cursor.
libedit: em-yankreadline: yank- ESC y
Rotate the kill-ring, and yank the new top. You can only do this if the previous command was ^Y or ESC y.
libedit: not availablereadline: yank-pop- ^F
Move forward a character.
libedit: ed-next-charreadline: forward-char- ^B
Move back a character.
libedit: ed-prev-charreadline: backward-char- <return>
Accept the line regardless of where the cursor is. If non-empty, add the line to the history list.
libedit: ed-newlinereadline: accept-line- ^P
Move up through the history list.
libedit: ed-prev-historyreadline: previous-history- ^N
Move down through the history list.
libedit: ed-next-historyreadline: next-history- ESC <
Move to the first line of the history.
libedit: not availablereadline: beginning-of-history- ESC >
Move to last line of the history.
libedit: not availablereadline: end-of-history- ^R
Search backward, incrementally, starting at the current line and moving up through the history as necessary.
libedit: em-inc-search-prevreadline: reverse-search-history- ^S
Search forward starting at the current line and moving down through the the history as necessary.
libedit: em-inc-search-nextreadline: forward-search-history- ^D
Delete the character under the cursor.
libedit: em-delete-or-listreadline: delete-char- ^H, DEL
Delete the character behind the cursor. A numeric argument means kill the characters instead of deleting them.
libedit: ed-delete-prev-charreadline: backward-delete-char- ^V, ^Q
Add the literal next character to the line.
libedit: ed-quoted-insertreadline: quoted-insert- a, b, etc.
Characters to be inserted as themselves.
libedit: ed-insertreadline: self-insert- ^T
Transpose the previous and current characters and move forward one character.
libedit: ed-transpose-charsreadline: transpose-chars- ESC t
Transpose the previous and current words and move forward one word.
libedit: not availablereadline: transpose-words- ESC ^_
Insert a copy of the previous word
libedit: em_copy_prev-wordreadline: not available- ESC u
Capitalize the current word.
libedit: em-upper-casereadline: upcase-word- ESC l
Make the current word lower case.
libedit: em-lower-casereadline: downcase-word- ESC c
Capitalize the current word.
libedit: em-capitol-casereadline: capitalize-word- unbound
Kill backward to the beginning of the line.
libedit: not availablereadline: backward-kill-line- ^U
Kill the current line.
libedit: em-kill-linereadline: unix-line-discard- ESC 0, ESC 1, ...
Enter number arguments for commands that can operate on more than one object.
libedit: ed-argument-digitreadline: digit-argument- ^G, ESC ^G, ^X ^G
Stop.
libedit: no binding, but ^G aborts incremental searchesreadline: abort- ESC
Use this character as a meta prefix for keyboards that lack a meta key.
libedit: em-meta-nextreadline: prefix-meta- ^_, ^X ^U
Undo last change.
libedit: vi-undo, only one level of undoreadline: undo, is incremental and remembered for each line- ESC r, ESC ^R
Undo all changes made to this line.
libedit: vi-undo-linereadline: revert-line- ^X (
Save the key strokes that follow.
libedit: not availablereadline: start-kbd-macro- ^X )
Cease saving key strokes.
libedit: not availablereadline: end-kbd-macro- ^X e
Recall the previously saved key strokes.
libedit: not availablereadline: call-last-kbd-macro- unbound
Redraw the current line.
libedit: ed-redisplayreadline: redraw-current-line- ESC ^Y
Insert nth previously killed text at the cursor.
libedit: not availablereadline: yank-nth-arg- unbound
List the current key bindings.
libedit: not availablereadline: dump-functions- ^X ^R
Reread the $HOME/.spec_keys key-bindings file, if it exists.
libedit: not availablereadline: re-read-init-file
NOTES
With the optional history libraries, the ! character must be preceded by a \ when it is typed from the keyboard and is not intended to be part of a history substitution.
DISTRIBUTION
A prebuilt version of the NetBSD libedit library is included with the spec distribution in the libedit subdirectory. The official source repository for the NetBSD version is at http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libedit. Portable versions configurable for other platforms are available from http://www.thrysoee.dk/editline. The spec version of the library is taken from there, with patches as specified in a file named spec_libedit.patch. The file is included in the spec distribution and in the tarball containing the patched libedit sources available at certif.com/downloads/extras.
The readline library is included with most modern Linux distributions. In addition, sources can be retrieved from ftp://ftp.gnu.org/gnu/readline and installed on any platform supported by spec. spec should link with all current and previous releases of readline. spec is known to link with readline versions 2.0, 2.1, 2.2, 2.2.1, 4.0, 4.1, 4.2, 4.2a, 4.3, 5.2 and 6.2. Later version will likely also work.