If an argument was supplied, then retrieve partial contents of the history; otherwise retrieve entire history. This function returns a dictionary with history items keyed by their 1-based index in ascending order.
(self, args: argparse.Namespace)
| 5279 | return None |
| 5280 | |
| 5281 | def _get_history(self, args: argparse.Namespace) -> dict[int, HistoryItem]: |
| 5282 | """If an argument was supplied, then retrieve partial contents of the history; otherwise retrieve entire history. |
| 5283 | |
| 5284 | This function returns a dictionary with history items keyed by their 1-based index in ascending order. |
| 5285 | """ |
| 5286 | if args.arg: |
| 5287 | try: |
| 5288 | int_arg = int(args.arg) |
| 5289 | return {int_arg: self.history.get(int_arg)} |
| 5290 | except ValueError: |
| 5291 | pass |
| 5292 | |
| 5293 | if ".." in args.arg or ":" in args.arg: |
| 5294 | # Get a slice of history |
| 5295 | history = self.history.span(args.arg, args.all) |
| 5296 | elif args.arg.startswith(r"/") and args.arg.endswith(r"/"): |
| 5297 | history = self.history.regex_search(args.arg, args.all) |
| 5298 | else: |
| 5299 | history = self.history.str_search(args.arg, args.all) |
| 5300 | else: |
| 5301 | # Get a copy of the history so it doesn't get mutated while we are using it |
| 5302 | history = self.history.span(":", args.all) |
| 5303 | return history |
| 5304 | |
| 5305 | def _initialize_history(self, hist_file: str) -> None: |
| 5306 | """Initialize history using history related attributes. |
no test coverage detected