1 |
24 |
jeremybenn |
.\"
|
2 |
|
|
.\" MAN PAGE COMMENTS to
|
3 |
|
|
.\"
|
4 |
|
|
.\" Chet Ramey
|
5 |
|
|
.\" Information Network Services
|
6 |
|
|
.\" Case Western Reserve University
|
7 |
|
|
.\" chet@ins.CWRU.Edu
|
8 |
|
|
.\"
|
9 |
|
|
.\" Last Change: Thu Jul 31 08:46:08 EDT 2003
|
10 |
|
|
.\"
|
11 |
|
|
.TH HISTORY 3 "2003 July 31" "GNU History 5.0"
|
12 |
|
|
.\"
|
13 |
|
|
.\" File Name macro. This used to be `.PN', for Path Name,
|
14 |
|
|
.\" but Sun doesn't seem to like that very much.
|
15 |
|
|
.\"
|
16 |
|
|
.de FN
|
17 |
|
|
\fI\|\\$1\|\fP
|
18 |
|
|
..
|
19 |
|
|
.ds lp \fR\|(\fP
|
20 |
|
|
.ds rp \fR\|)\fP
|
21 |
|
|
.\" FnN return-value fun-name N arguments
|
22 |
|
|
.de Fn1
|
23 |
|
|
\fI\\$1\fP \fB\\$2\fP \\*(lp\fI\\$3\fP\\*(rp
|
24 |
|
|
.br
|
25 |
|
|
..
|
26 |
|
|
.de Fn2
|
27 |
|
|
.if t \fI\\$1\fP \fB\\$2\fP \\*(lp\fI\\$3,\|\\$4\fP\\*(rp
|
28 |
|
|
.if n \fI\\$1\fP \fB\\$2\fP \\*(lp\fI\\$3, \\$4\fP\\*(rp
|
29 |
|
|
.br
|
30 |
|
|
..
|
31 |
|
|
.de Fn3
|
32 |
|
|
.if t \fI\\$1\fP \fB\\$2\fP \\*(lp\fI\\$3,\|\\$4,\|\\$5\fP\|\\*(rp
|
33 |
|
|
.if n \fI\\$1\fP \fB\\$2\fP \\*(lp\fI\\$3, \\$4, \\$5\fP\\*(rp
|
34 |
|
|
.br
|
35 |
|
|
..
|
36 |
|
|
.de Vb
|
37 |
|
|
\fI\\$1\fP \fB\\$2\fP
|
38 |
|
|
.br
|
39 |
|
|
..
|
40 |
|
|
.SH NAME
|
41 |
|
|
history \- GNU History Library
|
42 |
|
|
.SH COPYRIGHT
|
43 |
|
|
.if t The GNU History Library is Copyright \(co 1989-2002 by the Free Software Foundation, Inc.
|
44 |
|
|
.if n The GNU History Library is Copyright (C) 1989-2002 by the Free Software Foundation, Inc.
|
45 |
|
|
.SH DESCRIPTION
|
46 |
|
|
Many programs read input from the user a line at a time. The GNU
|
47 |
|
|
History library is able to keep track of those lines, associate arbitrary
|
48 |
|
|
data with each line, and utilize information from previous lines in
|
49 |
|
|
composing new ones.
|
50 |
|
|
.PP
|
51 |
|
|
.SH "HISTORY EXPANSION"
|
52 |
|
|
.PP
|
53 |
|
|
The history library supports a history expansion feature that
|
54 |
|
|
is identical to the history expansion in
|
55 |
|
|
.BR bash.
|
56 |
|
|
This section describes what syntax features are available.
|
57 |
|
|
.PP
|
58 |
|
|
History expansions introduce words from the history list into
|
59 |
|
|
the input stream, making it easy to repeat commands, insert the
|
60 |
|
|
arguments to a previous command into the current input line, or
|
61 |
|
|
fix errors in previous commands quickly.
|
62 |
|
|
.PP
|
63 |
|
|
History expansion is usually performed immediately after a complete line
|
64 |
|
|
is read.
|
65 |
|
|
It takes place in two parts.
|
66 |
|
|
The first is to determine which line from the history list
|
67 |
|
|
to use during substitution.
|
68 |
|
|
The second is to select portions of that line for inclusion into
|
69 |
|
|
the current one.
|
70 |
|
|
The line selected from the history is the \fIevent\fP,
|
71 |
|
|
and the portions of that line that are acted upon are \fIwords\fP.
|
72 |
|
|
Various \fImodifiers\fP are available to manipulate the selected words.
|
73 |
|
|
The line is broken into words in the same fashion as \fBbash\fP
|
74 |
|
|
does when reading input,
|
75 |
|
|
so that several words that would otherwise be separated
|
76 |
|
|
are considered one word when surrounded by quotes (see the
|
77 |
|
|
description of \fBhistory_tokenize()\fP below).
|
78 |
|
|
History expansions are introduced by the appearance of the
|
79 |
|
|
history expansion character, which is \^\fB!\fP\^ by default.
|
80 |
|
|
Only backslash (\^\fB\e\fP\^) and single quotes can quote
|
81 |
|
|
the history expansion character.
|
82 |
|
|
.SS Event Designators
|
83 |
|
|
.PP
|
84 |
|
|
An event designator is a reference to a command line entry in the
|
85 |
|
|
history list.
|
86 |
|
|
.PP
|
87 |
|
|
.PD 0
|
88 |
|
|
.TP
|
89 |
|
|
.B !
|
90 |
|
|
Start a history substitution, except when followed by a
|
91 |
|
|
.BR blank ,
|
92 |
|
|
newline, = or (.
|
93 |
|
|
.TP
|
94 |
|
|
.B !\fIn\fR
|
95 |
|
|
Refer to command line
|
96 |
|
|
.IR n .
|
97 |
|
|
.TP
|
98 |
|
|
.B !\-\fIn\fR
|
99 |
|
|
Refer to the current command line minus
|
100 |
|
|
.IR n .
|
101 |
|
|
.TP
|
102 |
|
|
.B !!
|
103 |
|
|
Refer to the previous command. This is a synonym for `!\-1'.
|
104 |
|
|
.TP
|
105 |
|
|
.B !\fIstring\fR
|
106 |
|
|
Refer to the most recent command starting with
|
107 |
|
|
.IR string .
|
108 |
|
|
.TP
|
109 |
|
|
.B !?\fIstring\fR\fB[?]\fR
|
110 |
|
|
Refer to the most recent command containing
|
111 |
|
|
.IR string .
|
112 |
|
|
The trailing \fB?\fP may be omitted if
|
113 |
|
|
.I string
|
114 |
|
|
is followed immediately by a newline.
|
115 |
|
|
.TP
|
116 |
|
|
.B \d\s+2^\s-2\u\fIstring1\fP\d\s+2^\s-2\u\fIstring2\fP\d\s+2^\s-2\u
|
117 |
|
|
Quick substitution. Repeat the last command, replacing
|
118 |
|
|
.I string1
|
119 |
|
|
with
|
120 |
|
|
.IR string2 .
|
121 |
|
|
Equivalent to
|
122 |
|
|
``!!:s/\fIstring1\fP/\fIstring2\fP/''
|
123 |
|
|
(see \fBModifiers\fP below).
|
124 |
|
|
.TP
|
125 |
|
|
.B !#
|
126 |
|
|
The entire command line typed so far.
|
127 |
|
|
.PD
|
128 |
|
|
.SS Word Designators
|
129 |
|
|
.PP
|
130 |
|
|
Word designators are used to select desired words from the event.
|
131 |
|
|
A
|
132 |
|
|
.B :
|
133 |
|
|
separates the event specification from the word designator.
|
134 |
|
|
It may be omitted if the word designator begins with a
|
135 |
|
|
.BR ^ ,
|
136 |
|
|
.BR $ ,
|
137 |
|
|
.BR * ,
|
138 |
|
|
.BR \- ,
|
139 |
|
|
or
|
140 |
|
|
.BR % .
|
141 |
|
|
Words are numbered from the beginning of the line,
|
142 |
|
|
with the first word being denoted by 0 (zero).
|
143 |
|
|
Words are inserted into the current line separated by single spaces.
|
144 |
|
|
.PP
|
145 |
|
|
.PD 0
|
146 |
|
|
.TP
|
147 |
|
|
.B 0 (zero)
|
148 |
|
|
The zeroth word. For the shell, this is the command
|
149 |
|
|
word.
|
150 |
|
|
.TP
|
151 |
|
|
.I n
|
152 |
|
|
The \fIn\fRth word.
|
153 |
|
|
.TP
|
154 |
|
|
.B ^
|
155 |
|
|
The first argument. That is, word 1.
|
156 |
|
|
.TP
|
157 |
|
|
.B $
|
158 |
|
|
The last argument.
|
159 |
|
|
.TP
|
160 |
|
|
.B %
|
161 |
|
|
The word matched by the most recent `?\fIstring\fR?' search.
|
162 |
|
|
.TP
|
163 |
|
|
.I x\fB\-\fPy
|
164 |
|
|
A range of words; `\-\fIy\fR' abbreviates `0\-\fIy\fR'.
|
165 |
|
|
.TP
|
166 |
|
|
.B *
|
167 |
|
|
All of the words but the zeroth. This is a synonym
|
168 |
|
|
for `\fI1\-$\fP'. It is not an error to use
|
169 |
|
|
.B *
|
170 |
|
|
if there is just one
|
171 |
|
|
word in the event; the empty string is returned in that case.
|
172 |
|
|
.TP
|
173 |
|
|
.B x*
|
174 |
|
|
Abbreviates \fIx\-$\fP.
|
175 |
|
|
.TP
|
176 |
|
|
.B x\-
|
177 |
|
|
Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word.
|
178 |
|
|
.PD
|
179 |
|
|
.PP
|
180 |
|
|
If a word designator is supplied without an event specification, the
|
181 |
|
|
previous command is used as the event.
|
182 |
|
|
.SS Modifiers
|
183 |
|
|
.PP
|
184 |
|
|
After the optional word designator, there may appear a sequence of
|
185 |
|
|
one or more of the following modifiers, each preceded by a `:'.
|
186 |
|
|
.PP
|
187 |
|
|
.PD 0
|
188 |
|
|
.PP
|
189 |
|
|
.TP
|
190 |
|
|
.B h
|
191 |
|
|
Remove a trailing file name component, leaving only the head.
|
192 |
|
|
.TP
|
193 |
|
|
.B t
|
194 |
|
|
Remove all leading file name components, leaving the tail.
|
195 |
|
|
.TP
|
196 |
|
|
.B r
|
197 |
|
|
Remove a trailing suffix of the form \fI.xxx\fP, leaving the
|
198 |
|
|
basename.
|
199 |
|
|
.TP
|
200 |
|
|
.B e
|
201 |
|
|
Remove all but the trailing suffix.
|
202 |
|
|
.TP
|
203 |
|
|
.B p
|
204 |
|
|
Print the new command but do not execute it.
|
205 |
|
|
.TP
|
206 |
|
|
.B q
|
207 |
|
|
Quote the substituted words, escaping further substitutions.
|
208 |
|
|
.TP
|
209 |
|
|
.B x
|
210 |
|
|
Quote the substituted words as with
|
211 |
|
|
.BR q ,
|
212 |
|
|
but break into words at
|
213 |
|
|
.B blanks
|
214 |
|
|
and newlines.
|
215 |
|
|
.TP
|
216 |
|
|
.B s/\fIold\fP/\fInew\fP/
|
217 |
|
|
Substitute
|
218 |
|
|
.I new
|
219 |
|
|
for the first occurrence of
|
220 |
|
|
.I old
|
221 |
|
|
in the event line. Any delimiter can be used in place of /. The
|
222 |
|
|
final delimiter is optional if it is the last character of the
|
223 |
|
|
event line. The delimiter may be quoted in
|
224 |
|
|
.I old
|
225 |
|
|
and
|
226 |
|
|
.I new
|
227 |
|
|
with a single backslash. If & appears in
|
228 |
|
|
.IR new ,
|
229 |
|
|
it is replaced by
|
230 |
|
|
.IR old .
|
231 |
|
|
A single backslash will quote the &. If
|
232 |
|
|
.I old
|
233 |
|
|
is null, it is set to the last
|
234 |
|
|
.I old
|
235 |
|
|
substituted, or, if no previous history substitutions took place,
|
236 |
|
|
the last
|
237 |
|
|
.I string
|
238 |
|
|
in a
|
239 |
|
|
.B !?\fIstring\fR\fB[?]\fR
|
240 |
|
|
search.
|
241 |
|
|
.TP
|
242 |
|
|
.B &
|
243 |
|
|
Repeat the previous substitution.
|
244 |
|
|
.TP
|
245 |
|
|
.B g
|
246 |
|
|
Cause changes to be applied over the entire event line. This is
|
247 |
|
|
used in conjunction with `\fB:s\fP' (e.g., `\fB:gs/\fIold\fP/\fInew\fP/\fR')
|
248 |
|
|
or `\fB:&\fP'. If used with
|
249 |
|
|
`\fB:s\fP', any delimiter can be used
|
250 |
|
|
in place of /, and the final delimiter is optional
|
251 |
|
|
if it is the last character of the event line.
|
252 |
|
|
An \fBa\fP may be used as a synonym for \fBg\fP.
|
253 |
|
|
.TP
|
254 |
|
|
.B G
|
255 |
|
|
Apply the following `\fBs\fP' modifier once to each word in the event line.
|
256 |
|
|
.PD
|
257 |
|
|
.SH "PROGRAMMING WITH HISTORY FUNCTIONS"
|
258 |
|
|
This section describes how to use the History library in other programs.
|
259 |
|
|
.SS Introduction to History
|
260 |
|
|
.PP
|
261 |
|
|
The programmer using the History library has available functions
|
262 |
|
|
for remembering lines on a history list, associating arbitrary data
|
263 |
|
|
with a line, removing lines from the list, searching through the list
|
264 |
|
|
for a line containing an arbitrary text string, and referencing any line
|
265 |
|
|
in the list directly. In addition, a history \fIexpansion\fP function
|
266 |
|
|
is available which provides for a consistent user interface across
|
267 |
|
|
different programs.
|
268 |
|
|
.PP
|
269 |
|
|
The user using programs written with the History library has the
|
270 |
|
|
benefit of a consistent user interface with a set of well-known
|
271 |
|
|
commands for manipulating the text of previous lines and using that text
|
272 |
|
|
in new commands. The basic history manipulation commands are
|
273 |
|
|
identical to
|
274 |
|
|
the history substitution provided by \fBbash\fP.
|
275 |
|
|
.PP
|
276 |
|
|
If the programmer desires, he can use the Readline library, which
|
277 |
|
|
includes some history manipulation by default, and has the added
|
278 |
|
|
advantage of command line editing.
|
279 |
|
|
.PP
|
280 |
|
|
Before declaring any functions using any functionality the History
|
281 |
|
|
library provides in other code, an application writer should include
|
282 |
|
|
the file
|
283 |
|
|
.FN
|
284 |
|
|
in any file that uses the
|
285 |
|
|
History library's features. It supplies extern declarations for all
|
286 |
|
|
of the library's public functions and variables, and declares all of
|
287 |
|
|
the public data structures.
|
288 |
|
|
|
289 |
|
|
.SS History Storage
|
290 |
|
|
.PP
|
291 |
|
|
The history list is an array of history entries. A history entry is
|
292 |
|
|
declared as follows:
|
293 |
|
|
.PP
|
294 |
|
|
.Vb "typedef void *" histdata_t;
|
295 |
|
|
.PP
|
296 |
|
|
.nf
|
297 |
|
|
typedef struct _hist_entry {
|
298 |
|
|
char *line;
|
299 |
|
|
char *timestamp;
|
300 |
|
|
histdata_t data;
|
301 |
|
|
} HIST_ENTRY;
|
302 |
|
|
.fi
|
303 |
|
|
.PP
|
304 |
|
|
The history list itself might therefore be declared as
|
305 |
|
|
.PP
|
306 |
|
|
.Vb "HIST_ENTRY **" the_history_list;
|
307 |
|
|
.PP
|
308 |
|
|
The state of the History library is encapsulated into a single structure:
|
309 |
|
|
.PP
|
310 |
|
|
.nf
|
311 |
|
|
/*
|
312 |
|
|
* A structure used to pass around the current state of the history.
|
313 |
|
|
*/
|
314 |
|
|
typedef struct _hist_state {
|
315 |
|
|
HIST_ENTRY **entries; /* Pointer to the entries themselves. */
|
316 |
|
|
int offset; /* The location pointer within this array. */
|
317 |
|
|
int length; /* Number of elements within this array. */
|
318 |
|
|
int size; /* Number of slots allocated to this array. */
|
319 |
|
|
int flags;
|
320 |
|
|
} HISTORY_STATE;
|
321 |
|
|
.fi
|
322 |
|
|
.PP
|
323 |
|
|
If the flags member includes \fBHS_STIFLED\fP, the history has been
|
324 |
|
|
stifled.
|
325 |
|
|
.SH "History Functions"
|
326 |
|
|
.PP
|
327 |
|
|
This section describes the calling sequence for the various functions
|
328 |
|
|
exported by the GNU History library.
|
329 |
|
|
.SS Initializing History and State Management
|
330 |
|
|
This section describes functions used to initialize and manage
|
331 |
|
|
the state of the History library when you want to use the history
|
332 |
|
|
functions in your program.
|
333 |
|
|
|
334 |
|
|
.Fn1 void using_history void
|
335 |
|
|
Begin a session in which the history functions might be used. This
|
336 |
|
|
initializes the interactive variables.
|
337 |
|
|
|
338 |
|
|
.Fn1 "HISTORY_STATE *" history_get_history_state void
|
339 |
|
|
Return a structure describing the current state of the input history.
|
340 |
|
|
|
341 |
|
|
.Fn1 void history_set_history_state "HISTORY_STATE *state"
|
342 |
|
|
Set the state of the history list according to \fIstate\fP.
|
343 |
|
|
|
344 |
|
|
.SS History List Management
|
345 |
|
|
|
346 |
|
|
These functions manage individual entries on the history list, or set
|
347 |
|
|
parameters managing the list itself.
|
348 |
|
|
|
349 |
|
|
.Fn1 void add_history "const char *string"
|
350 |
|
|
Place \fIstring\fP at the end of the history list. The associated data
|
351 |
|
|
field (if any) is set to \fBNULL\fP.
|
352 |
|
|
|
353 |
|
|
.Fn1 void add_history_time "const char *string"
|
354 |
|
|
Change the time stamp associated with the most recent history entry to
|
355 |
|
|
\fIstring\fP.
|
356 |
|
|
|
357 |
|
|
.Fn1 "HIST_ENTRY *" remove_history "int which"
|
358 |
|
|
Remove history entry at offset \fIwhich\fP from the history. The
|
359 |
|
|
removed element is returned so you can free the line, data,
|
360 |
|
|
and containing structure.
|
361 |
|
|
|
362 |
|
|
.Fn1 "histdata_t" free_history_entry "HIST_ENTRY *histent"
|
363 |
|
|
Free the history entry \fIhistent\fP and any history library private
|
364 |
|
|
data associated with it. Returns the application-specific data
|
365 |
|
|
so the caller can dispose of it.
|
366 |
|
|
|
367 |
|
|
.Fn3 "HIST_ENTRY *" replace_history_entry "int which" "const char *line" "histdata_t data"
|
368 |
|
|
Make the history entry at offset \fIwhich\fP have \fIline\fP and \fIdata\fP.
|
369 |
|
|
This returns the old entry so the caller can dispose of any
|
370 |
|
|
application-specific data. In the case
|
371 |
|
|
of an invalid \fIwhich\fP, a \fBNULL\fP pointer is returned.
|
372 |
|
|
|
373 |
|
|
.Fn1 void clear_history "void"
|
374 |
|
|
Clear the history list by deleting all the entries.
|
375 |
|
|
|
376 |
|
|
.Fn1 void stifle_history "int max"
|
377 |
|
|
Stifle the history list, remembering only the last \fImax\fP entries.
|
378 |
|
|
|
379 |
|
|
.Fn1 int unstifle_history "void"
|
380 |
|
|
Stop stifling the history. This returns the previously-set
|
381 |
|
|
maximum number of history entries (as set by \fBstifle_history()\fP).
|
382 |
|
|
history was stifled. The value is positive if the history was
|
383 |
|
|
stifled, negative if it wasn't.
|
384 |
|
|
|
385 |
|
|
.Fn1 int history_is_stifled "void"
|
386 |
|
|
Returns non-zero if the history is stifled, zero if it is not.
|
387 |
|
|
|
388 |
|
|
.SS Information About the History List
|
389 |
|
|
|
390 |
|
|
These functions return information about the entire history list or
|
391 |
|
|
individual list entries.
|
392 |
|
|
|
393 |
|
|
.Fn1 "HIST_ENTRY **" history_list "void"
|
394 |
|
|
Return a \fBNULL\fP terminated array of \fIHIST_ENTRY *\fP which is the
|
395 |
|
|
current input history. Element 0 of this list is the beginning of time.
|
396 |
|
|
If there is no history, return \fBNULL\fP.
|
397 |
|
|
|
398 |
|
|
.Fn1 int where_history "void"
|
399 |
|
|
Returns the offset of the current history element.
|
400 |
|
|
|
401 |
|
|
.Fn1 "HIST_ENTRY *" current_history "void"
|
402 |
|
|
Return the history entry at the current position, as determined by
|
403 |
|
|
\fBwhere_history()\fP. If there is no entry there, return a \fBNULL\fP
|
404 |
|
|
pointer.
|
405 |
|
|
|
406 |
|
|
.Fn1 "HIST_ENTRY *" history_get "int offset"
|
407 |
|
|
Return the history entry at position \fIoffset\fP, starting from
|
408 |
|
|
\fBhistory_base\fP.
|
409 |
|
|
If there is no entry there, or if \fIoffset\fP
|
410 |
|
|
is greater than the history length, return a \fBNULL\fP pointer.
|
411 |
|
|
|
412 |
|
|
.Fn1 "time_t" history_get_time "HIST_ENTRY *"
|
413 |
|
|
Return the time stamp associated with the history entry passed as the argument.
|
414 |
|
|
|
415 |
|
|
.Fn1 int history_total_bytes "void"
|
416 |
|
|
Return the number of bytes that the primary history entries are using.
|
417 |
|
|
This function returns the sum of the lengths of all the lines in the
|
418 |
|
|
history.
|
419 |
|
|
|
420 |
|
|
.SS Moving Around the History List
|
421 |
|
|
|
422 |
|
|
These functions allow the current index into the history list to be
|
423 |
|
|
set or changed.
|
424 |
|
|
|
425 |
|
|
.Fn1 int history_set_pos "int pos"
|
426 |
|
|
Set the current history offset to \fIpos\fP, an absolute index
|
427 |
|
|
into the list.
|
428 |
|
|
Returns 1 on success, 0 if \fIpos\fP is less than zero or greater
|
429 |
|
|
than the number of history entries.
|
430 |
|
|
|
431 |
|
|
.Fn1 "HIST_ENTRY *" previous_history "void"
|
432 |
|
|
Back up the current history offset to the previous history entry, and
|
433 |
|
|
return a pointer to that entry. If there is no previous entry, return
|
434 |
|
|
a \fBNULL\fP pointer.
|
435 |
|
|
|
436 |
|
|
.Fn1 "HIST_ENTRY *" next_history "void"
|
437 |
|
|
Move the current history offset forward to the next history entry, and
|
438 |
|
|
return the a pointer to that entry. If there is no next entry, return
|
439 |
|
|
a \fBNULL\fP pointer.
|
440 |
|
|
|
441 |
|
|
.SS Searching the History List
|
442 |
|
|
|
443 |
|
|
These functions allow searching of the history list for entries containing
|
444 |
|
|
a specific string. Searching may be performed both forward and backward
|
445 |
|
|
from the current history position. The search may be \fIanchored\fP,
|
446 |
|
|
meaning that the string must match at the beginning of the history entry.
|
447 |
|
|
|
448 |
|
|
.Fn2 int history_search "const char *string" "int direction"
|
449 |
|
|
Search the history for \fIstring\fP, starting at the current history offset.
|
450 |
|
|
If \fIdirection\fP is less than 0, then the search is through
|
451 |
|
|
previous entries, otherwise through subsequent entries.
|
452 |
|
|
If \fIstring\fP is found, then
|
453 |
|
|
the current history index is set to that history entry, and the value
|
454 |
|
|
returned is the offset in the line of the entry where
|
455 |
|
|
\fIstring\fP was found. Otherwise, nothing is changed, and a -1 is
|
456 |
|
|
returned.
|
457 |
|
|
|
458 |
|
|
.Fn2 int history_search_prefix "const char *string" "int direction"
|
459 |
|
|
Search the history for \fIstring\fP, starting at the current history
|
460 |
|
|
offset. The search is anchored: matching lines must begin with
|
461 |
|
|
\fIstring\fP. If \fIdirection\fP is less than 0, then the search is
|
462 |
|
|
through previous entries, otherwise through subsequent entries.
|
463 |
|
|
If \fIstring\fP is found, then the
|
464 |
|
|
current history index is set to that entry, and the return value is 0.
|
465 |
|
|
Otherwise, nothing is changed, and a -1 is returned.
|
466 |
|
|
|
467 |
|
|
.Fn3 int history_search_pos "const char *string" "int direction" "int pos"
|
468 |
|
|
Search for \fIstring\fP in the history list, starting at \fIpos\fP, an
|
469 |
|
|
absolute index into the list. If \fIdirection\fP is negative, the search
|
470 |
|
|
proceeds backward from \fIpos\fP, otherwise forward. Returns the absolute
|
471 |
|
|
index of the history element where \fIstring\fP was found, or -1 otherwise.
|
472 |
|
|
|
473 |
|
|
.SS Managing the History File
|
474 |
|
|
The History library can read the history from and write it to a file.
|
475 |
|
|
This section documents the functions for managing a history file.
|
476 |
|
|
|
477 |
|
|
.Fn1 int read_history "const char *filename"
|
478 |
|
|
Add the contents of \fIfilename\fP to the history list, a line at a time.
|
479 |
|
|
If \fIfilename\fP is \fBNULL\fP, then read from \fI~/.history\fP.
|
480 |
|
|
Returns 0 if successful, or \fBerrno\fP if not.
|
481 |
|
|
|
482 |
|
|
.Fn3 int read_history_range "const char *filename" "int from" "int to"
|
483 |
|
|
Read a range of lines from \fIfilename\fP, adding them to the history list.
|
484 |
|
|
Start reading at line \fIfrom\fP and end at \fIto\fP.
|
485 |
|
|
If \fIfrom\fP is zero, start at the beginning. If \fIto\fP is less than
|
486 |
|
|
\fIfrom\fP, then read until the end of the file. If \fIfilename\fP is
|
487 |
|
|
\fBNULL\fP, then read from \fI~/.history\fP. Returns 0 if successful,
|
488 |
|
|
or \fBerrno\fP if not.
|
489 |
|
|
|
490 |
|
|
.Fn1 int write_history "const char *filename"
|
491 |
|
|
Write the current history to \fIfilename\fP, overwriting \fIfilename\fP
|
492 |
|
|
if necessary.
|
493 |
|
|
If \fIfilename\fP is \fBNULL\fP, then write the history list to \fI~/.history\fP.
|
494 |
|
|
Returns 0 on success, or \fBerrno\fP on a read or write error.
|
495 |
|
|
|
496 |
|
|
|
497 |
|
|
.Fn2 int append_history "int nelements" "const char *filename"
|
498 |
|
|
Append the last \fInelements\fP of the history list to \fIfilename\fP.
|
499 |
|
|
If \fIfilename\fP is \fBNULL\fP, then append to \fI~/.history\fP.
|
500 |
|
|
Returns 0 on success, or \fBerrno\fP on a read or write error.
|
501 |
|
|
|
502 |
|
|
.Fn2 int history_truncate_file "const char *filename" "int nlines"
|
503 |
|
|
Truncate the history file \fIfilename\fP, leaving only the last
|
504 |
|
|
\fInlines\fP lines.
|
505 |
|
|
If \fIfilename\fP is \fBNULL\fP, then \fI~/.history\fP is truncated.
|
506 |
|
|
Returns 0 on success, or \fBerrno\fP on failure.
|
507 |
|
|
|
508 |
|
|
.SS History Expansion
|
509 |
|
|
|
510 |
|
|
These functions implement history expansion.
|
511 |
|
|
|
512 |
|
|
.Fn2 int history_expand "char *string" "char **output"
|
513 |
|
|
Expand \fIstring\fP, placing the result into \fIoutput\fP, a pointer
|
514 |
|
|
to a string. Returns:
|
515 |
|
|
.RS
|
516 |
|
|
.PD 0
|
517 |
|
|
.TP
|
518 |
|
|
|
519 |
|
|
If no expansions took place (or, if the only change in
|
520 |
|
|
the text was the removal of escape characters preceding the history expansion
|
521 |
|
|
character);
|
522 |
|
|
.TP
|
523 |
|
|
1
|
524 |
|
|
if expansions did take place;
|
525 |
|
|
.TP
|
526 |
|
|
-1
|
527 |
|
|
if there was an error in expansion;
|
528 |
|
|
.TP
|
529 |
|
|
2
|
530 |
|
|
if the returned line should be displayed, but not executed,
|
531 |
|
|
as with the \fB:p\fP modifier.
|
532 |
|
|
.PD
|
533 |
|
|
.RE
|
534 |
|
|
If an error ocurred in expansion, then \fIoutput\fP contains a descriptive
|
535 |
|
|
error message.
|
536 |
|
|
|
537 |
|
|
.Fn3 "char *" get_history_event "const char *string" "int *cindex" "int qchar"
|
538 |
|
|
Returns the text of the history event beginning at \fIstring\fP +
|
539 |
|
|
\fI*cindex\fP. \fI*cindex\fP is modified to point to after the event
|
540 |
|
|
specifier. At function entry, \fIcindex\fP points to the index into
|
541 |
|
|
\fIstring\fP where the history event specification begins. \fIqchar\fP
|
542 |
|
|
is a character that is allowed to end the event specification in addition
|
543 |
|
|
to the ``normal'' terminating characters.
|
544 |
|
|
|
545 |
|
|
.Fn1 "char **" history_tokenize "const char *string"
|
546 |
|
|
Return an array of tokens parsed out of \fIstring\fP, much as the
|
547 |
|
|
shell might.
|
548 |
|
|
The tokens are split on the characters in the
|
549 |
|
|
\fBhistory_word_delimiters\fP variable,
|
550 |
|
|
and shell quoting conventions are obeyed.
|
551 |
|
|
|
552 |
|
|
.Fn3 "char *" history_arg_extract "int first" "int last" "const char *string"
|
553 |
|
|
Extract a string segment consisting of the \fIfirst\fP through \fIlast\fP
|
554 |
|
|
arguments present in \fIstring\fP. Arguments are split using
|
555 |
|
|
\fBhistory_tokenize()\fP.
|
556 |
|
|
|
557 |
|
|
.SS History Variables
|
558 |
|
|
|
559 |
|
|
This section describes the externally-visible variables exported by
|
560 |
|
|
the GNU History Library.
|
561 |
|
|
|
562 |
|
|
.Vb int history_base
|
563 |
|
|
The logical offset of the first entry in the history list.
|
564 |
|
|
|
565 |
|
|
.Vb int history_length
|
566 |
|
|
The number of entries currently stored in the history list.
|
567 |
|
|
|
568 |
|
|
.Vb int history_max_entries
|
569 |
|
|
The maximum number of history entries. This must be changed using
|
570 |
|
|
\fBstifle_history()\fP.
|
571 |
|
|
|
572 |
|
|
.Vb int history_write_timestamps
|
573 |
|
|
If non-zero, timestamps are written to the history file, so they can be
|
574 |
|
|
preserved between sessions. The default value is 0, meaning that
|
575 |
|
|
timestamps are not saved.
|
576 |
|
|
|
577 |
|
|
.Vb char history_expansion_char
|
578 |
|
|
The character that introduces a history event. The default is \fB!\fP.
|
579 |
|
|
Setting this to 0 inhibits history expansion.
|
580 |
|
|
|
581 |
|
|
.Vb char history_subst_char
|
582 |
|
|
The character that invokes word substitution if found at the start of
|
583 |
|
|
a line. The default is \fB^\fP.
|
584 |
|
|
|
585 |
|
|
.Vb char history_comment_char
|
586 |
|
|
During tokenization, if this character is seen as the first character
|
587 |
|
|
of a word, then it and all subsequent characters up to a newline are
|
588 |
|
|
ignored, suppressing history expansion for the remainder of the line.
|
589 |
|
|
This is disabled by default.
|
590 |
|
|
|
591 |
|
|
.Vb "char *" history_word_delimiters
|
592 |
|
|
The characters that separate tokens for \fBhistory_tokenize()\fP.
|
593 |
|
|
The default value is \fB"\ \et\en()<>;&|"\fP.
|
594 |
|
|
|
595 |
|
|
.Vb "char *" history_no_expand_chars
|
596 |
|
|
The list of characters which inhibit history expansion if found immediately
|
597 |
|
|
following \fBhistory_expansion_char\fP. The default is space, tab, newline,
|
598 |
|
|
\fB\er\fP, and \fB=\fP.
|
599 |
|
|
|
600 |
|
|
.Vb "char *" history_search_delimiter_chars
|
601 |
|
|
The list of additional characters which can delimit a history search
|
602 |
|
|
string, in addition to space, tab, \fI:\fP and \fI?\fP in the case of
|
603 |
|
|
a substring search. The default is empty.
|
604 |
|
|
|
605 |
|
|
.Vb int history_quotes_inhibit_expansion
|
606 |
|
|
If non-zero, single-quoted words are not scanned for the history expansion
|
607 |
|
|
character. The default value is 0.
|
608 |
|
|
|
609 |
|
|
.Vb "rl_linebuf_func_t *" history_inhibit_expansion_function
|
610 |
|
|
This should be set to the address of a function that takes two arguments:
|
611 |
|
|
a \fBchar *\fP (\fIstring\fP)
|
612 |
|
|
and an \fBint\fP index into that string (\fIi\fP).
|
613 |
|
|
It should return a non-zero value if the history expansion starting at
|
614 |
|
|
\fIstring[i]\fP should not be performed; zero if the expansion should
|
615 |
|
|
be done.
|
616 |
|
|
It is intended for use by applications like \fBbash\fP that use the history
|
617 |
|
|
expansion character for additional purposes.
|
618 |
|
|
By default, this variable is set to \fBNULL\fP.
|
619 |
|
|
.SH FILES
|
620 |
|
|
.PD 0
|
621 |
|
|
.TP
|
622 |
|
|
.FN ~/.history
|
623 |
|
|
Default filename for reading and writing saved history
|
624 |
|
|
.PD
|
625 |
|
|
.SH "SEE ALSO"
|
626 |
|
|
.PD 0
|
627 |
|
|
.TP
|
628 |
|
|
\fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey
|
629 |
|
|
.TP
|
630 |
|
|
\fIThe Gnu History Library\fP, Brian Fox and Chet Ramey
|
631 |
|
|
.TP
|
632 |
|
|
\fIbash\fP(1)
|
633 |
|
|
.TP
|
634 |
|
|
\fIreadline\fP(3)
|
635 |
|
|
.PD
|
636 |
|
|
.SH AUTHORS
|
637 |
|
|
Brian Fox, Free Software Foundation
|
638 |
|
|
.br
|
639 |
|
|
bfox@gnu.org
|
640 |
|
|
.PP
|
641 |
|
|
Chet Ramey, Case Western Reserve University
|
642 |
|
|
.br
|
643 |
|
|
chet@ins.CWRU.Edu
|
644 |
|
|
.SH BUG REPORTS
|
645 |
|
|
If you find a bug in the
|
646 |
|
|
.B history
|
647 |
|
|
library, you should report it. But first, you should
|
648 |
|
|
make sure that it really is a bug, and that it appears in the latest
|
649 |
|
|
version of the
|
650 |
|
|
.B history
|
651 |
|
|
library that you have.
|
652 |
|
|
.PP
|
653 |
|
|
Once you have determined that a bug actually exists, mail a
|
654 |
|
|
bug report to \fIbug\-readline\fP@\fIgnu.org\fP.
|
655 |
|
|
If you have a fix, you are welcome to mail that
|
656 |
|
|
as well! Suggestions and `philosophical' bug reports may be mailed
|
657 |
|
|
to \fPbug-readline\fP@\fIgnu.org\fP or posted to the Usenet
|
658 |
|
|
newsgroup
|
659 |
|
|
.BR gnu.bash.bug .
|
660 |
|
|
.PP
|
661 |
|
|
Comments and bug reports concerning
|
662 |
|
|
this manual page should be directed to
|
663 |
|
|
.IR chet@ins.CWRU.Edu .
|