Sortix cross-volatile manual
This manual documents Sortix cross-volatile. You can instead view this document in the latest official manual.
HISTORY(3) | Library Functions Manual | HISTORY(3) |
NAME
history - GNU History LibraryCOPYRIGHT
The GNU History Library is Copyright (C) 1989-2020 by the Free Software Foundation, Inc.DESCRIPTION
Many programs read input from the user a line at a time. The GNU History library is able to keep track of those lines, associate arbitrary data with each line, and utilize information from previous lines in composing new ones.HISTORY EXPANSION
The history library supports a history expansion feature that is identical to the history expansion in bash. This section describes what syntax features are available.Event Designators
An event designator is a reference to a command line entry in the history list. Unless the reference is absolute, events are relative to the current position in the history list.- !
- Start a history substitution, except when followed by a blank, newline, = or (.
- !n
- Refer to command line n.
- !-n
- Refer to the current command minus n.
- !!
- Refer to the previous command. This is a synonym for `!-1'.
- !string
- Refer to the most recent command preceding the current position in the history list starting with string.
- !?string[?]
- Refer to the most recent command preceding the current position in the history list containing string. The trailing ? may be omitted if string is followed immediately by a newline. If string is missing, the string from the most recent search is used; it is an error if there is no previous search string.
- ^string1^string2^
- Quick substitution. Repeat the last command, replacing string1 with string2. Equivalent to ``!!:s^ string1^string2^'' (see Modifiers below).
- !#
- The entire command line typed so far.
Word Designators
Word designators are used to select desired words from the event. A : separates the event specification from the word designator. It may be omitted if the word designator begins with a ^, $, *, -, or %. Words are numbered from the beginning of the line, with the first word being denoted by 0 (zero). Words are inserted into the current line separated by single spaces.- 0 (zero)
- The zeroth word. For the shell, this is the command word.
- n
- The nth word.
- ^
- The first argument. That is, word 1.
- $
- The last word. This is usually the last argument, but will expand to the zeroth word if there is only one word in the line.
- %
- The first word matched by the most recent `?string?' search, if the search string begins with a character that is part of a word.
- x-y
- A range of words; `-y' abbreviates `0-y'.
- *
- All of the words but the zeroth. This is a synonym for ` 1-$'. It is not an error to use * if there is just one word in the event; the empty string is returned in that case.
- x*
- Abbreviates x-$.
- x-
- Abbreviates x-$ like x*, but omits the last word. If x is missing, it defaults to 0.
Modifiers
After the optional word designator, there may appear a sequence of one or more of the following modifiers, each preceded by a `:'. These modify, or edit, the word or words selected from the history event.- h
- Remove a trailing file name component, leaving only the head.
- t
- Remove all leading file name components, leaving the tail.
- r
- Remove a trailing suffix of the form .xxx, leaving the basename.
- e
- Remove all but the trailing suffix.
- p
- Print the new command but do not execute it.
- q
- Quote the substituted words, escaping further substitutions.
- x
- Quote the substituted words as with q, but break into words at blanks and newlines. The q and x modifiers are mutually exclusive; the last one supplied is used.
- s/old/new/
- Substitute new for the first occurrence of old in the event line. Any character may be used as the delimiter in place of /. The final delimiter is optional if it is the last character of the event line. The delimiter may be quoted in old and new with a single backslash. If & appears in new, it is replaced by old. A single backslash will quote the &. If old is null, it is set to the last old substituted, or, if no previous history substitutions took place, the last string in a !?string[?] search. If new is null, each matching old is deleted.
- &
- Repeat the previous substitution.
- g
- Cause changes to be applied over the entire event line. This is used in conjunction with ` :s' (e.g., `:gs/old/new/') or ` :&'. If used with ` :s', any delimiter can be used in place of /, and the final delimiter is optional if it is the last character of the event line. An a may be used as a synonym for g.
- G
- Apply the following `s' or `&' modifier once to each word in the event line.
PROGRAMMING WITH HISTORY FUNCTIONS
This section describes how to use the History library in other programs.Introduction to History
A programmer using the History library has available functions for remembering lines on a history list, associating arbitrary data with a line, removing lines from the list, searching through the list for a line containing an arbitrary text string, and referencing any line in the list directly. In addition, a history expansion function is available which provides for a consistent user interface across different programs.History Storage
The history list is an array of history entries. A history entry is declared as follows:typedef struct _hist_entry {
char *line;
char *timestamp;
histdata_t data;
} HIST_ENTRY;
/*
* A structure used to pass around the current state of the history.
*/
typedef struct _hist_state {
HIST_ENTRY **entries; /* Pointer to the entries themselves. */
int offset; /* The location pointer within this array. */
int length; /* Number of elements within this array. */
int size; /* Number of slots allocated to this array. */
int flags;
} HISTORY_STATE;
History Functions
This section describes the calling sequence for the various functions exported by the GNU History library.Initializing History and State Management
This section describes functions used to initialize and manage the state of the History library when you want to use the history functions in your program.History List Management
These functions manage individual entries on the history list, or set parameters managing the list itself.Information About the History List
These functions return information about the entire history list or individual list entries.Moving Around the History List
These functions allow the current index into the history list to be set or changed.Searching the History List
These functions allow searching of the history list for entries containing a specific string. Searching may be performed both forward and backward from the current history position. The search may be anchored, meaning that the string must match at the beginning of the history entry.Managing the History File
The History library can read the history from and write it to a file. This section documents the functions for managing a history file.History Expansion
These functions implement history expansion.- 0
- If no expansions took place (or, if the only change in the text was the removal of escape characters preceding the history expansion character);
- 1
- if expansions did take place;
- -1
- if there was an error in expansion;
- 2
- if the returned line should be displayed, but not executed, as with the :p modifier.
History Variables
This section describes the externally-visible variables exported by the GNU History Library.FILES
- ~/.history
- Default filename for reading and writing saved history
SEE ALSO
- The Gnu Readline Library, Brian Fox and Chet Ramey
- The Gnu History Library, Brian Fox and Chet Ramey
- bash(1)
- readline(3)
AUTHORS
Brian Fox, Free Software FoundationBUG REPORTS
If you find a bug in the history library, you should report it. But first, you should make sure that it really is a bug, and that it appears in the latest version of the history library that you have.2020 July 17 | GNU History 8.1 |