Made -i option independent of -a.
Signed-off-by: Arun Prakash Jana <engineerarun@gmail.com>
This commit is contained in:
parent
5b38f11b1a
commit
d4921362af
@ -72,12 +72,12 @@ Options
|
||||
-a URL tag 1, tag 2, ... add URL as bookmark with comma separated tags
|
||||
-d N delete entry at index N
|
||||
-D delete ALL bookmarks
|
||||
-i N add entry at index N, works with -a, use to fill deleted index
|
||||
-i N insert entry at index N, useful to fill deleted index
|
||||
-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 each keyword
|
||||
-u N update entry at index N (from output of -p)
|
||||
-w fetch title info from web, works with -a or -u
|
||||
-u N update entry at index N (from output of -P)
|
||||
-w fetch title info from web, works with -a, -i, -u
|
||||
-z show debug information
|
||||
you can either add or update or delete in one instance
|
||||
any other option shows help and exits markit
|
||||
@ -103,7 +103,7 @@ Updated</pre>
|
||||
5. Delete all bookmarks:
|
||||
<pre>$ markit -D</pre>
|
||||
6. Insert a bookmark at deleted index 15012014 (fails if index or URL exists in database):
|
||||
<pre>$ markit -i 15012014 -a -w http://tuxdiary.com/about linux news, open source
|
||||
<pre>$ markit -i 15012014 -w http://tuxdiary.com/about linux news, open source
|
||||
Title: [A journey with WordPress | TuxDiary]
|
||||
Added at index 15012014</pre>
|
||||
This option is useful in filling deleted indices from database manually.
|
||||
|
54
markit
54
markit
@ -50,12 +50,12 @@ def usage():
|
||||
print(" -a URL tag 1, tag 2, ... add URL as bookmark with comma separated tags")
|
||||
print(" -d N delete entry at index N")
|
||||
print(" -D delete ALL bookmarks")
|
||||
print(" -i N add entry at index N, works with -a, use to fill deleted index")
|
||||
print(" -i N insert entry at index N, useful to fill deleted index")
|
||||
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(" -w fetch title info from web, works with -a or -u")
|
||||
print(" -u N update entry at index N (from output of -P)")
|
||||
print(" -w fetch title info from web, works with -a, -i, -u")
|
||||
print(" -z show debug information")
|
||||
print(" you can either add or update or delete in one instance")
|
||||
print(" any other option shows help and exits markit\n")
|
||||
@ -275,21 +275,9 @@ def searchdb(cur, keywords):
|
||||
continue
|
||||
|
||||
try:
|
||||
_stderr = os.dup(2)
|
||||
os.close(2)
|
||||
_stdout = os.dup(1)
|
||||
os.close(1)
|
||||
fd = os.open(os.devnull, os.O_RDWR)
|
||||
os.dup2(fd, 2)
|
||||
os.dup2(fd, 1)
|
||||
try:
|
||||
openurl = unquote(results[int(nav) - 1])
|
||||
openurl = openurl.replace("%22", "\"")
|
||||
webbrowser.open(openurl)
|
||||
finally:
|
||||
os.close(fd)
|
||||
os.dup2(_stderr, 2)
|
||||
os.dup2(_stdout, 1)
|
||||
openurl = unquote(results[int(nav) - 1])
|
||||
openurl = openurl.replace("%22", "\"")
|
||||
browser_open(openurl)
|
||||
except IndexError:
|
||||
print("Index out of bound")
|
||||
else:
|
||||
@ -365,6 +353,26 @@ class BMHTMLParser(HTMLParser.HTMLParser):
|
||||
|
||||
|
||||
|
||||
# Open a URL in browser
|
||||
def browser_open(url):
|
||||
_stderr = os.dup(2)
|
||||
os.close(2)
|
||||
_stdout = os.dup(1)
|
||||
os.close(1)
|
||||
fd = os.open(os.devnull, os.O_RDWR)
|
||||
os.dup2(fd, 2)
|
||||
os.dup2(fd, 1)
|
||||
try:
|
||||
webbrowser.open(url)
|
||||
except Exception as e:
|
||||
print("Browser Exception: %s" % e)
|
||||
finally:
|
||||
os.close(fd)
|
||||
os.dup2(_stderr, 2)
|
||||
os.dup2(_stdout, 1)
|
||||
|
||||
|
||||
|
||||
# Main starts here
|
||||
# ----------------
|
||||
optlist = None
|
||||
@ -406,14 +414,18 @@ try:
|
||||
|
||||
delete = True
|
||||
elif opt[0] == "-i":
|
||||
if update == True or delete == True:
|
||||
print("You can either add or update or delete in one instance\n")
|
||||
usage()
|
||||
|
||||
if not opt[1].isdigit():
|
||||
usage()
|
||||
|
||||
addindex = opt[1]
|
||||
if int(addindex) <= 0:
|
||||
usage()
|
||||
elif opt[0] == "-w":
|
||||
online = True
|
||||
|
||||
addurl = True
|
||||
elif opt[0] == "-p":
|
||||
if not opt[1].isdigit():
|
||||
usage()
|
||||
@ -440,6 +452,8 @@ try:
|
||||
usage()
|
||||
|
||||
update = True
|
||||
elif opt[0] == "-w":
|
||||
online = True
|
||||
elif opt[0] == "-z":
|
||||
debug = True
|
||||
except GetoptError as e:
|
||||
|
6
markit.1
6
markit.1
@ -41,7 +41,7 @@ Delete ALL bookmarks.
|
||||
.BI \-i " N"
|
||||
Add a new record at index
|
||||
.I N
|
||||
of the database. Works only if `-a` option is used. Use this option to fill blank indexes left by deleted bookmarks.
|
||||
of the database. Use this option to fill blank indexes left by deleted bookmarks.
|
||||
.TP
|
||||
.BI \-p " N"
|
||||
Show details of bookmark record stored at
|
||||
@ -57,10 +57,10 @@ Search bookmarks for a (partial) tag or keywords and show the results. Prompts t
|
||||
.BI \-u " N"
|
||||
Update bookmark at index
|
||||
.I N
|
||||
(as shown in `-p` output).
|
||||
(as shown in `-P` output).
|
||||
.TP
|
||||
.BI \-w
|
||||
Fetch title data from the web. Works only with `-a` or `-u` options.
|
||||
Fetch title data from the web. Works with `-a`, `-i` or `-u` options.
|
||||
.TP
|
||||
.BI \-z
|
||||
Enable debugging.
|
||||
|
Loading…
Reference in New Issue
Block a user