예제 #1
0
def _xh_show_history(hist, ns, stdout=None, stderr=None):
    """Show the requested portion of shell history.
    Accepts same parameters with `_xh_get_history`.
    """
    try:
        commands = _xh_get_history(ns.session,
                                   slices=ns.slices,
                                   start_time=ns.start_time,
                                   end_time=ns.end_time,
                                   datetime_format=ns.datetime_format)
    except ValueError as err:
        print("history: error: {}".format(err), file=stderr)
        return
    if ns.reverse:
        commands = reversed(list(commands))
    if ns.numerate and ns.timestamp:
        for c in commands:
            dt = datetime.datetime.fromtimestamp(c['ts'])
            print('{}:({}) {}'.format(c['ind'], xt.format_datetime(dt),
                                      c['inp']),
                  file=stdout)
    elif ns.numerate:
        for c in commands:
            print('{}: {}'.format(c['ind'], c['inp']), file=stdout)
    elif ns.timestamp:
        for c in commands:
            dt = datetime.datetime.fromtimestamp(c['ts'])
            print('({}) {}'.format(xt.format_datetime(dt), c['inp']),
                  file=stdout)
    else:
        for c in commands:
            print(c['inp'], file=stdout)
예제 #2
0
파일: main.py 프로젝트: VHarisop/xonsh
def _xh_show_history(hist, ns, stdout=None, stderr=None):
    """Show the requested portion of shell history.
    Accepts same parameters with `_xh_get_history`.
    """
    try:
        commands = _xh_get_history(ns.session,
                                   slices=ns.slices,
                                   start_time=ns.start_time,
                                   end_time=ns.end_time,
                                   datetime_format=ns.datetime_format)
    except ValueError as err:
        print("history: error: {}".format(err), file=stderr)
        return
    if ns.reverse:
        commands = reversed(list(commands))
    if ns.numerate and ns.timestamp:
        for c in commands:
            dt = datetime.datetime.fromtimestamp(c['ts'])
            print('{}:({}) {}'.format(c['ind'], xt.format_datetime(dt), c['inp']),
                  file=stdout)
    elif ns.numerate:
        for c in commands:
            print('{}: {}'.format(c['ind'], c['inp']), file=stdout)
    elif ns.timestamp:
        for c in commands:
            dt = datetime.datetime.fromtimestamp(c['ts'])
            print('({}) {}'.format(xt.format_datetime(dt), c['inp']),
                  file=stdout)
    else:
        for c in commands:
            print(c['inp'], file=stdout)
예제 #3
0
파일: main.py 프로젝트: swedneck/xonsh
def _xh_show_history(hist, ns, stdout=None, stderr=None):
    """Show the requested portion of shell history.
    Accepts same parameters with `_xh_get_history`.
    """
    try:
        commands = _xh_get_history(
            ns.session,
            slices=ns.slices,
            start_time=ns.start_time,
            end_time=ns.end_time,
            datetime_format=ns.datetime_format,
        )
    except Exception as err:
        print("history: error: {}".format(err), file=stderr)
        return
    if ns.reverse:
        commands = reversed(list(commands))
    end = "\0" if ns.null_byte else "\n"
    if ns.numerate and ns.timestamp:
        for c in commands:
            dt = datetime.datetime.fromtimestamp(c["ts"])
            print(
                "{}:({}) {}".format(c["ind"], xt.format_datetime(dt),
                                    c["inp"]),
                file=stdout,
                end=end,
            )
    elif ns.numerate:
        for c in commands:
            print("{}: {}".format(c["ind"], c["inp"]), file=stdout, end=end)
    elif ns.timestamp:
        for c in commands:
            dt = datetime.datetime.fromtimestamp(c["ts"])
            print("({}) {}".format(xt.format_datetime(dt), c["inp"]),
                  file=stdout,
                  end=end)
    else:
        for c in commands:
            print(c["inp"], file=stdout, end=end)
예제 #4
0
파일: main.py 프로젝트: donnemartin/gitsome
def _xh_show_history(hist, ns, stdout=None, stderr=None):
    """Show the requested portion of shell history.
    Accepts same parameters with `_xh_get_history`.
    """
    try:
        commands = _xh_get_history(
            ns.session,
            slices=ns.slices,
            start_time=ns.start_time,
            end_time=ns.end_time,
            datetime_format=ns.datetime_format,
        )
    except Exception as err:
        print("history: error: {}".format(err), file=stderr)
        return
    if ns.reverse:
        commands = reversed(list(commands))
    end = "\0" if ns.null_byte else "\n"
    if ns.numerate and ns.timestamp:
        for c in commands:
            dt = datetime.datetime.fromtimestamp(c["ts"])
            print(
                "{}:({}) {}".format(c["ind"], xt.format_datetime(dt), c["inp"]),
                file=stdout,
                end=end,
            )
    elif ns.numerate:
        for c in commands:
            print("{}: {}".format(c["ind"], c["inp"]), file=stdout, end=end)
    elif ns.timestamp:
        for c in commands:
            dt = datetime.datetime.fromtimestamp(c["ts"])
            print(
                "({}) {}".format(xt.format_datetime(dt), c["inp"]), file=stdout, end=end
            )
    else:
        for c in commands:
            print(c["inp"], file=stdout, end=end)
예제 #5
0
    def show(
        self,
        session: xcli.Annotated[
            str, xcli.Arg(nargs="?", choices=tuple(_XH_HISTORY_SESSIONS)
                          )] = "session",
        slices: xcli.Annotated[tp.List[int], xcli.Arg(nargs="*")] = None,
        datetime_format: tp.Optional[str] = None,
        start_time: tp.Optional[str] = None,
        end_time: tp.Optional[str] = None,
        location: tp.Optional[str] = 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
        end_time: -T, --end-time
            show only commands before timestamp
        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``
        """
        slices = list(slices or ())
        if _unparsed:
            slices.extend(_unparsed)
        try:
            commands = _xh_get_history(
                session,
                slices=slices,
                start_time=start_time,
                end_time=end_time,
                datetime_format=datetime_format,
                location=location,
            )
        except Exception as err:
            self.parser.error(err)
            return

        if reverse:
            commands = reversed(list(commands))
        end = "\0" if null_byte else "\n"
        if numerate and timestamp:
            for c in commands:
                dt = datetime.datetime.fromtimestamp(c["ts"])
                print(
                    "{}:({}) {}".format(c["ind"], xt.format_datetime(dt),
                                        c["inp"]),
                    file=_stdout,
                    end=end,
                )
        elif numerate:
            for c in commands:
                print("{}: {}".format(c["ind"], c["inp"]),
                      file=_stdout,
                      end=end)
        elif timestamp:
            for c in commands:
                dt = datetime.datetime.fromtimestamp(c["ts"])
                print(
                    "({}) {}".format(xt.format_datetime(dt), c["inp"]),
                    file=_stdout,
                    end=end,
                )
        else:
            for c in commands:
                print(c["inp"], file=_stdout, end=end)