Manage IPython's bookmark system. %bookmark - set bookmark to current dir %bookmark - set bookmark to %bookmark -l - list all bookmarks %bookmark -d - remove bookmark %bookmark -r - remove all book
(self, parameter_s='')
| 737 | |
| 738 | @line_magic |
| 739 | def bookmark(self, parameter_s=''): |
| 740 | """Manage IPython's bookmark system. |
| 741 | |
| 742 | %bookmark <name> - set bookmark to current dir |
| 743 | %bookmark <name> <dir> - set bookmark to <dir> |
| 744 | %bookmark -l - list all bookmarks |
| 745 | %bookmark -d <name> - remove bookmark |
| 746 | %bookmark -r - remove all bookmarks |
| 747 | |
| 748 | You can later on access a bookmarked folder with:: |
| 749 | |
| 750 | %cd -b <name> |
| 751 | |
| 752 | or simply '%cd <name>' if there is no directory called <name> AND |
| 753 | there is such a bookmark defined. |
| 754 | |
| 755 | Your bookmarks persist through IPython sessions, but they are |
| 756 | associated with each profile.""" |
| 757 | |
| 758 | opts,args = self.parse_options(parameter_s,'drl',mode='list') |
| 759 | if len(args) > 2: |
| 760 | raise UsageError("%bookmark: too many arguments") |
| 761 | |
| 762 | bkms = self.shell.db.get('bookmarks',{}) |
| 763 | |
| 764 | if 'd' in opts: |
| 765 | try: |
| 766 | todel = args[0] |
| 767 | except IndexError: |
| 768 | raise UsageError( |
| 769 | "%bookmark -d: must provide a bookmark to delete") |
| 770 | else: |
| 771 | try: |
| 772 | del bkms[todel] |
| 773 | except KeyError: |
| 774 | raise UsageError( |
| 775 | "%%bookmark -d: Can't delete bookmark '%s'" % todel) |
| 776 | |
| 777 | elif 'r' in opts: |
| 778 | bkms = {} |
| 779 | elif 'l' in opts: |
| 780 | bks = sorted(bkms) |
| 781 | if bks: |
| 782 | size = max(map(len, bks)) |
| 783 | else: |
| 784 | size = 0 |
| 785 | fmt = '%-'+str(size)+'s -> %s' |
| 786 | print('Current bookmarks:') |
| 787 | for bk in bks: |
| 788 | print(fmt % (bk, bkms[bk])) |
| 789 | else: |
| 790 | if not args: |
| 791 | raise UsageError("%bookmark: You must specify the bookmark name") |
| 792 | elif len(args)==1: |
| 793 | bkms[args[0]] = os.getcwd() |
| 794 | elif len(args)==2: |
| 795 | bkms[args[0]] = args[1] |
| 796 | self.shell.db['bookmarks'] = bkms |
nothing calls this directly
no test coverage detected