History Backend JSON – xonsh.history.json
¶
Implements JSON version of xonsh history backend.
-
class
xonsh.history.json.
JsonCommandField
(field, hist, default=None)[source]¶ A field in the ‘cmds’ portion of history.
Represents a field in the ‘cmds’ portion of history.
Will query the buffer for the relevant data, if possible. Otherwise it will lazily acquire data from the file.
Parameters: field : str
The name of the field to query.
hist : History object
The history object to query.
default : optional
The default value to return if key is not present.
-
class
xonsh.history.json.
JsonHistory
(filename=None, sessionid=None, buffersize=100, gc=True, **meta)[source]¶ Xonsh history backend implemented with JSON files.
JsonHistory implements two extra actions:
diff
, andreplay
.Represents a xonsh session’s history as an in-memory buffer that is periodically flushed to disk.
Parameters: filename : str, optional
Location of history file, defaults to
$XONSH_DATA_DIR/xonsh-{sessionid}.json
.sessionid : int, uuid, str, optional
Current session identifier, will generate a new sessionid if not set.
buffersize : int, optional
Maximum buffersize in memory.
meta : optional
Top-level metadata to store along with the history. The kwargs ‘cmds’ and ‘sessionid’ are not allowed and will be overwritten.
gc : bool, optional
Run garbage collector flag.
-
all_items
(**kwargs)[source]¶ Returns all history as found in XONSH_DATA_DIR.
yeild format: {‘inp’: cmd, ‘rtn’: 0, ...}
-
append
(cmd)[source]¶ Appends command to history. Will periodically flush the history to file.
Parameters: cmd : dict
Command dictionary that should be added to the ordered history.
Returns: hf : JsonHistoryFlusher or None
The thread that was spawned to flush history
-
flush
(at_exit=False)[source]¶ Flushes the current command buffer to disk.
Parameters: at_exit : bool, optional
Whether the JsonHistoryFlusher should act as a thread in the background, or execute immeadiately and block.
Returns: hf : JsonHistoryFlusher or None
The thread that was spawned to flush history
-
-
class
xonsh.history.json.
JsonHistoryFlusher
(filename, buffer, queue, cond, at_exit=False, *args, **kwargs)[source]¶ Flush shell history to disk periodically.
Thread for flushing history.