From 9b467bc5768c98fc70670601b2bbe4c012c3db28 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Tue, 10 Nov 2015 00:02:10 +0530 Subject: [PATCH] Print bookmark record of a single index. Signed-off-by: Arun Prakash Jana --- README.md | 3 ++- markit | 38 +++++++++++++++++++++++++++++--------- markit.1 | 7 ++++++- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index bc7d5ca..a3f260f 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,8 @@ Options -D delete ALL bookmarks -i N add entry at index N, works with -a, use to fill deleted index -o fetch title info from web, works with -a or -u - -p show all bookmarks along with real index from database + -p N show details of bookmark record at index N" + -P show all bookmarks along with real index from database -s keyword(s) search all bookmarks for a (partial) tag or keywords -u N update entry at index N (from output of -p) -z show debug information diff --git a/markit b/markit index 2b4d69f..1603976 100755 --- a/markit +++ b/markit @@ -34,6 +34,7 @@ addindex = None online = False delete = False show = False +showindex = None search = False entry = None update = False @@ -51,7 +52,8 @@ def usage(): print(" -D delete ALL bookmarks") print(" -i N add entry at index N, works with -a, use to fill deleted index") print(" -o fetch title info from web, works with -a or -u") - print(" -p show all bookmarks along with real index from database") + print(" -p N show details of bookmark record at index N") + print(" -P show all bookmarks along with real index from database") print(" -s keyword(s) search all bookmarks for a (partial) tag or each keyword") print(" -u N update entry at index N (from output of -p)") print(" -z show debug information") @@ -264,7 +266,7 @@ def searchdb(cur, keywords): if is_int(nav): index = int(nav) - 1 if index < 0: - print("Index out of bound.") + print("Index out of bound") continue try: @@ -284,7 +286,7 @@ def searchdb(cur, keywords): os.dup2(_stderr, 2) os.dup2(_stdout, 1) except IndexError: - print("Index out of bound.") + print("Index out of bound") else: break @@ -304,14 +306,23 @@ def cleardb(conn, cur, entry): else: print("No matching index") except IndexError: - print("Index out of bound.") + print("Index out of bound") # Print all records in the table -def printdb(cur): - for row in cur.execute('SELECT * FROM bookmarks'): - print("\x1B[1m\x1B[93m%s. \x1B[0m\x1B[92m%s\x1B[0m\n\t%s\n\t[TAGS] %s" % (row[0], row[1], row[2], row[3][1:-1])) +def printdb(cur, showindex): + if showindex == None: # Show all entries + for row in cur.execute('SELECT * FROM bookmarks'): + print("\x1B[1m\x1B[93m%s. \x1B[0m\x1B[92m%s\x1B[0m\n\t%s\n\t[TAGS] %s" % (row[0], row[1], row[2], row[3][1:-1])) + else: # Show record at index showindex + try: + for row in cur.execute("SELECT * FROM bookmarks WHERE id = ?", (int(showindex),)): + print("\x1B[1m\x1B[93m%s. \x1B[0m\x1B[92m%s\x1B[0m\n\t%s\n\t[TAGS] %s" % (row[0], row[1], row[2], row[3][1:-1])) + return + print("No matching index") + except IndexError: + print("Index out of bound") @@ -359,7 +370,7 @@ if len(sys.argv) < 2: # Check cmdline options try: - optlist, keywords = getopt(sys.argv[1:], "d:i:u:aDopsz") + optlist, keywords = getopt(sys.argv[1:], "d:i:p:u:aDoPsz") if len(optlist) < 1: usage() @@ -399,6 +410,15 @@ try: elif opt[0] == "-o": online = True elif opt[0] == "-p": + if not opt[1].isdigit(): + usage() + + showindex = opt[1] + if int(showindex) <= 0: + usage() + + show = True + elif opt[0] == "-P": show = True elif opt[0] == "-s": search = True @@ -447,7 +467,7 @@ if search == True: # Print all records if show == True: - printdb(cur) + printdb(cur, showindex) # Remove a single record of all records if delete == True: diff --git a/markit.1 b/markit.1 index 1ea29ed..722e351 100644 --- a/markit.1 +++ b/markit.1 @@ -39,7 +39,12 @@ of the database. Works only if `-a` option is used. Use this option to fill blan .BI \-o Fetch title data from the web. Works only with `-a` or `-u` options. .TP -.B \-p +.BI \-p " N" +Show details of bookmark record stored at +.I Nth +index in database. +.TP +.B \-P Show all bookmark records from the database along with actual index. Shows URL, title data and tags. .TP .BI \-s " keywords"