MCPcopy Create free account
hub / github.com/ipython/ipython / dhist

Method dhist

IPython/core/magics/osm.py:528–563  ·  view source on GitHub ↗

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='')

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

arg_errMethod · 0.80

Tested by

no test coverage detected