From b9fbed2cab6c121218b8f09663b8c820b431f0e8 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Fri, 7 Apr 2017 01:48:16 +0530 Subject: [PATCH] Support print records at prompt --- buku.1 | 3 +++ buku.py | 25 +++++++++++++++++++++++-- tests/test_ExtendedArgumentParser.py | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/buku.1 b/buku.1 index 4c90b2a..88e34a6 100644 --- a/buku.1 +++ b/buku.1 @@ -269,6 +269,9 @@ Search bookmarks by a tag. List all tags alphabetically, if no arguments. The in .BI "g" " [...][>>|>|<<][...]" Append, remove tags to/from indices and/or ranges. .TP +.BI "p" " [...]" +Print bookmarks by indices and/or ranges. +.TP .BI "w" " [editor|index]" Edit and add or update a bookmark. .TP diff --git a/buku.py b/buku.py index 3b15353..3ce17b5 100755 --- a/buku.py +++ b/buku.py @@ -1793,6 +1793,7 @@ keys: r expression run a regex search t [...] search bookmarks by a tag or show tag list g [...][>>|>|<<][...] append, remove tags to/from indices and/or ranges + p [...] print bookmarks by indices and/or ranges w [editor|index] edit and add or update a bookmark (tag list index fetches bookmarks by tag) ? show this help @@ -2104,7 +2105,7 @@ def taglist_subprompt(obj, msg, noninteractive=False): elif (nav == 'q' or nav == 'd' or nav == '?' or nav.startswith('s ') or nav.startswith('S ') or nav.startswith('r ') or nav.startswith('t ') or - nav.startswith('g ')): + nav.startswith('g ') or nav.startswith('p ')): return nav elif nav == 'w' or nav.startswith('w '): edit_at_prompt(obj, nav) @@ -2220,7 +2221,7 @@ def prompt(obj, results, noninteractive=False, deep=False, subprompt=False): edit_at_prompt(obj, nav) continue - # append or overwrite tags + # Append or overwrite tags if nav.startswith('g '): unique_tags, dic = obj.get_tag_all() _count = obj.set_tag(nav[2:], unique_tags) @@ -2230,6 +2231,26 @@ def prompt(obj, results, noninteractive=False, deep=False, subprompt=False): print('%d updated' % _count) continue + # Print bookmarks by DB index + if nav.startswith('p '): + id_list = nav[2:].split() + try: + for id in id_list: + if is_int(id) and int(id) > 0: + obj.print_rec(int(id)) + elif '-' in id: + vals = [int(x) for x in id.split('-')] + if vals[0] > vals[-1]: + vals[0], vals[-1] = vals[-1], vals[0] + + for _id in range(vals[0], vals[-1] + 1): + obj.print_rec(_id) + else: + print('Invalid input') + except ValueError: + print('Invalid input') + continue + # Nothing to browse if there are no results if not results: print('Not in a search context') diff --git a/tests/test_ExtendedArgumentParser.py b/tests/test_ExtendedArgumentParser.py index aac4045..82edb5b 100644 --- a/tests/test_ExtendedArgumentParser.py +++ b/tests/test_ExtendedArgumentParser.py @@ -47,6 +47,7 @@ keys: r expression run a regex search t [...] search bookmarks by a tag or show tag list g [...][>>|>|<<][...] append, remove tags to/from indices and/or ranges + p [...] print bookmarks by indices and/or ranges w [editor|index] edit and add or update a bookmark (tag list index fetches bookmarks by tag) ? show this help