History Support

Readline history support.

History Interface

class rl.History

Interface to the readline history. Used to read and write history files and to manipulate history entries.

This class is not intended for instantiation beyond the one history object in this module. Typically, applications will import the history object and use its properties and methods to work with readline history:

from rl import history

history.max_entries = 300
history.read_file(histfile)

History entries can be accessed like elements in a Python list. The item at index 0 is the oldest, the item at -1 the most recent history entry.

History.auto

Controls whether readline automatically adds lines to the history. Defaults to True. Set to False if you want to call append() yourself.

History.max_entries

The maximum number of history entries kept. Beyond this point the history list is truncated by removing the oldest entry. A negative value means no limit. Defaults to -1.

History.max_file

The maximum size of a readline history file, in entries. Beyond this point the history file is truncated by removing the oldest entries. A negative value means no limit. Defaults to -1.

History.append(line)

Append a line to the history.

History.__getitem__(index)

Return the history item at index.

History.__setitem__(index, line)

Replace the history item at index.

History.__delitem__(index)

Remove the history item at index.

History.__len__()

The current history length.

History.__iter__()

Iterate over history items (old to new).

History.__reversed__()

Reverse-iterate over history items (new to old).

History.clear()

Clear the history.

History.read_file(filename=None, raise_exc=False)

Load a readline history file. The default filename is ~/.history. If raise_exc is True, IOErrors will be allowed to propagate.

History.write_file(filename=None, raise_exc=False)

Save a readline history file. The default filename is ~/.history. If raise_exc is True, IOErrors will be allowed to propagate.

History.append_file(numitems, filename=None, raise_exc=False)

Append the last numitems history entries to a readline history file. The default filename is ~/.history. If raise_exc is True, IOErrors will be allowed to propagate.