Skip to content
Back to top
View this page
Edit this page

# xonsh.history.main

Main entry points of the xonsh history.

class xonsh.history.main.HistoryAlias(threadable=True, **kwargs)

  Try ‘history <command> –help’ for more info

  exception Error(message: str, errno=1)

    Special case, when raised, the traceback will not be shown. Instead the process with exit with error code and message

    add_note(note, /)

      Add a note to the exception

    with_traceback(tb, /)

      Set self.__traceback__ to tb and return self.

    args
  static clear()

    One-time wipe of session history

  static delete(pattern)

    Delete all commands matching a pattern

    Parameters:
      pattern:

        regex pattern to match against command history

  static diff(a, b, reopen=False, verbose=False, _stdout=None)

    Diff two xonsh history files

    Parameters:
      left:

        The first file to diff

      right:

        The second file to diff

      reopen: -r, –reopen

        make lazy file loading reopen files each time

      verbose: -v, –verbose

        whether to print even more information

  static erasedups()

    Remove duplicate commands, keeping only the latest occurrence of each

  static file(_stdout)

    Display the current history filename

  static flush(_stdout)

    Flush the current history to disk

  static gc(size: Annotated[tuple[int, str], (), 'nargs', 2, 'completer', None] = None, force=False, blocking=True)

    Launches a new history garbage collector

    Parameters:
      size-s, –size

        Next two arguments represent the history size and units; e.g. “–size 8128 commands”

      force-f, –force

        perform garbage collection even if history much bigger than configured limit

      blocking-n, –non-blocking

        makes the gc non-blocking, and thus return sooner. By default it runs on main thread blocking input.

  static id_cmd(_stdout)

    Display the current session id

  static info(to_json=False, _stdout=None)

    Display information about the current history

    Parameters:
      to_json: -j, –json

        print in JSON format

  static off()

    History will not be saved for this session

  static on()

    History will be saved for the rest of the session (default)

  static pull(show_commands=False, session_id=None, _stdout=None)

    Pull history from other parallel sessions.

    Parameters:
      show_commands: -c, –show-commands

        show pulled commands

      session_id: -s, –session-id

        pull from specified session only

  build()

    Sub-classes should return constructed ArgumentParser

  create_parser(func=None, has_args=False, allowed_params=None, **kwargs) → ArgParser

    create root parser

  err(*args, **kwargs)

    Write text to error stream

  out(*args, **kwargs)

    Write text to output stream

  show(session: ~typing.Annotated[str, ((), (('nargs', '?'), ('action', <class 'xonsh.history.main.SessionAction'>), ('completer', None)))] = 'session', slices: ~typing.Annotated[list[int], ((), (('nargs', '*'), ('completer', None)))] = None, datetime_format: str | None = None, start_time: str | None = None, end_time: str | None = None, location: str | None = None, reverse=False, numerate=False, timestamp=False, null_byte=False, _stdout=None, _stderr=None, _unparsed=None)

    Display history of a session, default command

    Parameters:
      session:

        The history session to get. (all is an alias for xonsh)

      slices:

        integer or slice notation to get only portions of history.

      datetime_format-f

        the datetime format to be used for filtering and printing

      start_time: –start-time, +T

        show only commands after timestamp. Accepts $XONSH_DATETIME_FORMAT or ISO-8601 (e.g. 2023-07-17)

      end_time: -T, –end-time

        show only commands before timestamp. Accepts $XONSH_DATETIME_FORMAT or ISO-8601 (e.g. 2023-07-17)

      location: -l, –location

        The history file location (bash or zsh)

      reverse: -r, –reverse

        Reverses the direction

      numerate: -n, –numerate

        Numerate each command

      timestamp: -t, –ts, –time-stamp

        show command timestamps

      null_byte: -0, –nb, –null-byte

        separate commands by the null character for piping history to external filters

      _unparsed

        remaining args from `parser.parse_known_args`

  transfer(source: ~typing.Annotated[str, ((), (('action', <class 'xonsh.history.main.SessionAction'>), ('completer', None)))], source_file: str | None = None, target: ~typing.Annotated[str | None, ((), (('action', <class 'xonsh.history.main.SessionAction'>), ('completer', None)))] = None, target_file: str | None = None)

    Transfer entries between history backends.

    Parameters:
      source

        Name of the source history backend

      source_file–source-file, –sf

        Override the default location of the history file of the backend.

      target–target, -t

        Name of the target history backend. (default: $XONSH_HISTORY_BACKEND)

      target_file–target-file, –tf

        Path to the location of the history file.

    Notes

    It will not remove duplicate entries, use $HISTCONTROL for managing such entries.

  write_to(stream: str, *args, **kwargs)
  xonsh_complete(command, **kwargs)
  property parser

class xonsh.history.main.SessionAction(*args, **kwargs)

  Set the choices lazily

  format_usage()

xonsh.history.main.construct_history(backend=None, **kwargs) → History

  Construct the history backend object.