Print your history of visited directories. %dhist -> print full history\\ %dhist n -> print last n entries only\\ %dhist n1 n2 -> print entries between n1 and n2 (n2 not included)\\ This history is automatically maintained by the %cd command, and a
(self, parameter_s='')
| 525 | |
| 526 | @line_magic |
| 527 | def dhist(self, parameter_s=''): |
| 528 | """Print your history of visited directories. |
| 529 | |
| 530 | %dhist -> print full history\\ |
| 531 | %dhist n -> print last n entries only\\ |
| 532 | %dhist n1 n2 -> print entries between n1 and n2 (n2 not included)\\ |
| 533 | |
| 534 | This history is automatically maintained by the %cd command, and |
| 535 | always available as the global list variable _dh. You can use %cd -<n> |
| 536 | to go to directory number <n>. |
| 537 | |
| 538 | Note that most of time, you should view directory history by entering |
| 539 | cd -<TAB>. |
| 540 | |
| 541 | """ |
| 542 | |
| 543 | dh = self.shell.user_ns['_dh'] |
| 544 | if parameter_s: |
| 545 | try: |
| 546 | args = map(int,parameter_s.split()) |
| 547 | except: |
| 548 | self.arg_err(self.dhist) |
| 549 | return |
| 550 | if len(args) == 1: |
| 551 | ini,fin = max(len(dh)-(args[0]),0),len(dh) |
| 552 | elif len(args) == 2: |
| 553 | ini,fin = args |
| 554 | fin = min(fin, len(dh)) |
| 555 | else: |
| 556 | self.arg_err(self.dhist) |
| 557 | return |
| 558 | else: |
| 559 | ini,fin = 0,len(dh) |
| 560 | print('Directory history (kept in _dh)') |
| 561 | for i in range(ini, fin): |
| 562 | print("%d: %s" % (i, dh[i])) |
| 563 | |
| 564 | @skip_doctest |
| 565 | @line_magic |