xonsh.history.base#

Base class of Xonsh History backends.

class xonsh.history.base.History(sessionid=None, **kwargs)[source]#

Xonsh history backend base class.

History objects should be created via a subclass of History.

History acts like a sequence that can be indexed to return HistoryEntry objects.

Note that the most recent command is the last item in history.

Attributes:
rtnssequence of ints

The return of the command (ie, 0 on success)

inpssequence of strings

The command as typed by the user, including newlines

tsssequence of two-tuples of floats

The timestamps of when the command started and finished, including fractions

outssequence of strings

The output of the command, if xonsh is configured to save it

gcA garbage collector or None

The garbage collector

In all of these sequences, index 0 is the oldest and -1 (the last item)
is the newest.

Represents a xonsh session’s history.

Parameters:
sessionidint, uuid, str, optional

Current session identifier, will generate a new sessionid if not set.

all_items(newest_first=False)[source]#

Get all history items.

append(cmd)[source]#

Append a command item into history.

Parameters:
cmd: dict

This dict contains information about the command that is to be added to the history list. It should contain the keys inp, rtn and ts. These key names mirror the same names defined as instance variables in the HistoryEntry class.

clear()[source]#

Clears the history of the current session from both the disk and memory.

delete(pattern)[source]#

Deletes the history of the current session for commands that match a user-provided pattern.

Parameters:
pattern: str

The regex pattern to match commands against.

Returns:
int

The number of commands deleted from history.

flush(**kwargs)[source]#

Flush the history items to disk from a buffer.

info()[source]#

A collection of information about the shell history.

Returns:
dict or collections.OrderedDict

Contains history information as str key pairs.

is_ignored(cmd)[source]#

Determines if a history item should be added to the event history. Call this in your append method.

Parameters:
cmd: dict

The prospective item to append (structure is the same as the append method).

Returns:
bool

True if the item should be appended, False if not.

items(newest_first=False)[source]#

Get history items of current session.

pull(**kwargs)[source]#

Pull history from other parallel sessions.

run_gc(size=None, blocking=True)[source]#

Run the garbage collector.

Parameters:
size: None or tuple of a int and a string

Determines the size and units of what would be allowed to remain.

blocking: bool

If set blocking, then wait until gc action finished.

property ignore_regex#
class xonsh.history.base.HistoryEntry[source]#

Represent a command in history.

Attributes:
cmd: str

The command as typed by the user, including newlines

out: str

The output of the command, if xonsh is configured to save it

rtn: int

The return of the command (ie, 0 on success)

ts: two-tuple of floats

The timestamps of when the command started and finished, including fractions.

cwd: str

The current working directory before execution the command.