From 7f0dbd972c7254f5a24d88874fd80be4be6afbda Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Wed, 18 May 2016 22:53:08 +0530 Subject: [PATCH] Show tags moved from -S to --st. --- README.md | 13 ++++++------- buku | 45 ++++++++++++++++++++++++++++----------------- buku.1 | 14 ++++++-------- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 5e98010..647a9b8 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Shell completion scripts for Bash, Fish and Zsh can be found in respective subdi usage: buku [-a URL [tags ...]] [-u [N [URL tags ...]]] [-t [...]] [-c [...]] [-d [N]] [-h] - [-s keyword [...]] [-S keyword [...]] [--st keyword [...]] + [-s keyword [...]] [-S keyword [...]] [--st [...]] [-k [N]] [-l [N]] [-p [N]] [-f N] [-r oldtag [newtag ...]] [-j] [-o N] [-z] @@ -134,11 +134,10 @@ Shell completion scripts for Bash, Fish and Zsh can be found in respective subdi search bookmarks for ANY matching keyword -S, --sall keyword [...] search bookmarks with ALL keywords - special keywords - - "tags" : list all tags alphabetically + special keyword - "blank": list entries with empty title/tag - --st, --stag keyword [...] - search bookmarks by tag + --st, --stag [...] search bookmarks by tag + list all tags alphabetically, if no arguments encryption options: -l, --lock [N] encrypt DB file with N (> 0, default 8) @@ -178,7 +177,7 @@ Shell completion scripts for Bash, Fish and Zsh can be found in respective subdi - Substrings match (`match` matches `rematched`) for URL, title and tags. - `-s` : match any of the keywords in URL, title or tags. - `-S` : match all the keywords in URL, title or tags. - - `--st` : search bookmarks by tag. + - `--st` : search bookmarks by tag, or show all tags alphabetically. - You can search bookmarks by tag (see [examples](#examples)). - Search results are indexed serially. This index is different from actual database index of a bookmark record which is shown within `[]` after the URL. - Auto DB compaction: when a record is deleted, the last record is moved to the index. @@ -229,7 +228,7 @@ The last index is moved to the deleted index to keep the DB compact. Note the commas (,) before and after the tag. Comma is the tag delimiter in DB. 11. List **all unique tags** alphabetically: - $ buku -S tags + $ buku --st 12. **Encrypt or decrypt** DB with **custom number of iterations** (15) to generate key: $ buku -l 15 diff --git a/buku b/buku index c8990f5..c9e7989 100755 --- a/buku +++ b/buku @@ -48,6 +48,7 @@ except ImportError: # Globals update = False # Update a bookmark in DB +tagsearch = False # Search bookmarks by tag titleData = None # Title fetched from a page titleManual = None # Manually add a title offline description = None # Description of the bookmark @@ -1019,7 +1020,7 @@ def printmsg(msg, level=None): class customUpdateAction(argparse.Action): - """Class to capture if an optional param + """Class to capture if optional param 'update' is actually used, even if sans arguments """ @@ -1031,8 +1032,20 @@ class customUpdateAction(argparse.Action): setattr(args, self.dest, values) +class customTagSearchAction(argparse.Action): + """Class to capture if optional param 'stag' + is actually used, even if sans arguments + """ + + def __call__(self, parser, args, values, option_string=None): + global tagsearch + + tagsearch = True + setattr(args, self.dest, values) + + class customTitleAction(argparse.Action): - """Class to capture if an optional param + """Class to capture if optional param 'title' is actually used, even if sans arguments """ @@ -1040,12 +1053,11 @@ class customTitleAction(argparse.Action): global titleManual titleManual = '' - # NOTE: the following converts a None argument to an empty array [] setattr(args, self.dest, values) class customDescAction(argparse.Action): - """Class to capture if an optional param + """Class to capture if optional param 'comment' is actually used, even if sans arguments """ @@ -1053,7 +1065,6 @@ class customDescAction(argparse.Action): global description description = '' - # NOTE: the following converts a None argument to an empty array [] setattr(args, self.dest, values) @@ -1105,7 +1116,7 @@ argparser = ExtendedArgumentParser( formatter_class=argparse.RawTextHelpFormatter, usage='''buku [-a URL [tags ...]] [-u [N [URL tags ...]]] [-t [...]] [-c [...]] [-d [N]] [-h] - [-s keyword [...]] [-S keyword [...]] [--st keyword [...]] + [-s keyword [...]] [-S keyword [...]] [--st [...]] [-k [N]] [-l [N]] [-p [N]] [-f N] [-r oldtag [newtag ...]] [-j] [-o N] [-z]''', add_help=False @@ -1140,14 +1151,13 @@ search_group=argparser.add_argument_group(title="search options", search bookmarks for ANY matching keyword -S, --sall keyword [...] search bookmarks with ALL keywords - special keywords - - "tags" : list all tags alphabetically + special keyword - "blank": list entries with empty title/tag ---st, --stag keyword [...] - search bookmarks by tag''') +--st, --stag [...] search bookmarks by tag + list all tags alphabetically, if no arguments''') search_group.add_argument('-s', '--sany', nargs='+', metavar='keyword', help=argparse.SUPPRESS) search_group.add_argument('-S', '--sall', nargs='+', metavar='keyword', help=argparse.SUPPRESS) -search_group.add_argument('--st', '--stag', nargs='+', dest='stag', metavar='keyword', help=argparse.SUPPRESS) +search_group.add_argument('--st', '--stag', nargs='*', dest='stag', action=customTagSearchAction, metavar='keyword', help=argparse.SUPPRESS) # Encryption options crypto_group=argparser.add_argument_group(title="encryption options", @@ -1255,17 +1265,18 @@ if args.sany is not None: # Search URLs, titles, tags with all keywords if args.sall is not None: - if args.sall[0] == 'tags' and len(args.sall) == 1: - showUniqueTags(cur) - elif args.sall[0] == 'blank' and len(args.sall) == 1: + if args.sall[0] == 'blank' and len(args.sall) == 1: printdb(cur, 0, True) else: searchdb(cur, args.sall, True) # Search bookmarks by tag -if args.stag is not None: - tag = ',' + " ".join(args.stag) + ',' - searchTag(cur, tag) +if tagsearch == True: + if len(args.stag) > 0: + tag = ',' + " ".join(args.stag) + ',' + searchTag(cur, tag) + else: + showUniqueTags(cur) # Update record if update == True: diff --git a/buku.1 b/buku.1 index bebdbd5..f50e6f2 100644 --- a/buku.1 +++ b/buku.1 @@ -7,7 +7,7 @@ buku \- A private command-line bookmark manager. Your mini web! .br [-t [...]] [-c [...]] [-d [N]] [-h] .br - [-s keyword [...]] [-S keyword [...]] [--st keyword [...]] + [-s keyword [...]] [-S keyword [...]] [--st [...]] .br [-k [N]] [-l [N]] [-p [N]] [-f N] .br @@ -37,7 +37,7 @@ Search works in mysterious ways: - Substrings match ('match' matches 'rematched') for URL, title and tags. - -s : match any of the keywords in URL, title or tags. - -S : match all the keywords in URL, title or tags. - - --st : search bookmarks by tag. + - --st : search bookmarks by tag, or show all tags alphabetically. - You can search bookmarks by tag (see examples below). - Search results are indexed serially. This index is different from actual database index of a bookmark record which is shown within '[]' after the URL. .PP @@ -83,14 +83,12 @@ Search bookmarks for ANY of the keyword(s) in URL, title or tags and show the re .BI \-S " " \--sall " keyword [...]" Search bookmarks with ALL keywords in URL, title or tags and show the results. Behaviour same as -s. .br -Special keywords: -.br -"tags" : list all tags alphabetically +Special keyword: .br "blank": list entries with empty title/tag .TP -.BI \--st " " \--stag " keyword [...]" -Search bookmarks by tag. +.BI \--st " " \--stag " [...]" +Search bookmarks by tag. List all tags alphabetically, if no arguments. .SH ENCRYPTION OPTIONS .TP .BI \-l " " \--lock " [N]" @@ -252,7 +250,7 @@ List \fBall unique tags\fR alphabetically: .PP .EX .IP -.B buku -S tags +.B buku --st .PP .IP 12. 4 \fBEncrypt or decrypt\fR DB with \fBcustom number of iterations\fR (15) to generate key: