Open a random index with option -o.
This commit is contained in:
parent
4eeca53f27
commit
18f4e70071
@ -178,7 +178,8 @@ Shell completion scripts for Bash, Fish and Zsh can be found in respective subdi
|
|||||||
delete oldtag, if no newtag
|
delete oldtag, if no newtag
|
||||||
-j, --json Json formatted output for -p, -s, -S, --st
|
-j, --json Json formatted output for -p, -s, -S, --st
|
||||||
--noprompt do not show the prompt, run and exit
|
--noprompt do not show the prompt, run and exit
|
||||||
-o, --open N open bookmark at DB index N in web browser
|
-o, --open [N] open bookmark at DB index N in web browser
|
||||||
|
open a random index if N is omitted
|
||||||
-z, --debug show debug information and additional logs
|
-z, --debug show debug information and additional logs
|
||||||
|
|
||||||
prompt keys:
|
prompt keys:
|
||||||
|
27
buku
27
buku
@ -746,7 +746,7 @@ class BukuDb:
|
|||||||
|
|
||||||
self.cur.execute('SELECT MAX(id) from bookmarks')
|
self.cur.execute('SELECT MAX(id) from bookmarks')
|
||||||
results = self.cur.fetchall()
|
results = self.cur.fetchall()
|
||||||
# Return if the last index was just deleted
|
# Return if the last index left in DB was just deleted
|
||||||
if len(results) == 1 and results[0][0] is None:
|
if len(results) == 1 and results[0][0] is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -940,6 +940,20 @@ class BukuDb:
|
|||||||
Params: index
|
Params: index
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
if index == 0:
|
||||||
|
self.cur.execute('SELECT MAX(id) from bookmarks')
|
||||||
|
results = self.cur.fetchall()
|
||||||
|
|
||||||
|
# Return if no entries in DB
|
||||||
|
if len(results) == 1 and results[0][0] is None:
|
||||||
|
print("No bookmarks added yet ...")
|
||||||
|
return
|
||||||
|
|
||||||
|
import random
|
||||||
|
index = random.randint(1, results[0][0])
|
||||||
|
logger.debug('Opening random index ' + str(index))
|
||||||
|
|
||||||
|
|
||||||
query = 'SELECT URL FROM bookmarks WHERE id = ?'
|
query = 'SELECT URL FROM bookmarks WHERE id = ?'
|
||||||
try:
|
try:
|
||||||
for row in self.cur.execute(query, (index,)):
|
for row in self.cur.execute(query, (index,)):
|
||||||
@ -1739,7 +1753,8 @@ if __name__ == '__main__':
|
|||||||
delete oldtag, if no newtag
|
delete oldtag, if no newtag
|
||||||
-j, --json Json formatted output for -p, -s, -S, --st
|
-j, --json Json formatted output for -p, -s, -S, --st
|
||||||
--noprompt do not show the prompt, run and exit
|
--noprompt do not show the prompt, run and exit
|
||||||
-o, --open N open bookmark at DB index N in web browser
|
-o, --open [N] open bookmark at DB index N in web browser
|
||||||
|
open a random index if N is omitted
|
||||||
-z, --debug show debug information and additional logs''')
|
-z, --debug show debug information and additional logs''')
|
||||||
addarg = power_grp.add_argument
|
addarg = power_grp.add_argument
|
||||||
addarg('-e', '--export', nargs=1, dest='export', metavar='file',
|
addarg('-e', '--export', nargs=1, dest='export', metavar='file',
|
||||||
@ -1758,8 +1773,8 @@ if __name__ == '__main__':
|
|||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
addarg('--noprompt', dest='noninteractive', action='store_true',
|
addarg('--noprompt', dest='noninteractive', action='store_true',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
addarg('-o', '--open', dest='openurl', type=int, metavar='N',
|
addarg('-o', '--open', nargs='?', dest='openurl', type=int, const=0,
|
||||||
help=argparse.SUPPRESS)
|
metavar='N', help=argparse.SUPPRESS)
|
||||||
addarg('-z', '--debug', dest='debug', action='store_true',
|
addarg('-z', '--debug', dest='debug', action='store_true',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
|
||||||
@ -1953,8 +1968,8 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# Open URL in browser
|
# Open URL in browser
|
||||||
if args.openurl is not None:
|
if args.openurl is not None:
|
||||||
if args.openurl < 1:
|
if args.openurl < 0:
|
||||||
logger.error('Index must be >= 1')
|
logger.error('Index must be >= 0')
|
||||||
bdb.close_quit(1)
|
bdb.close_quit(1)
|
||||||
bdb.browse_by_index(args.openurl)
|
bdb.browse_by_index(args.openurl)
|
||||||
|
|
||||||
|
4
buku.1
4
buku.1
@ -142,10 +142,10 @@ Output data formatted as json, works with -p, -s, -S, --st.
|
|||||||
.BI \--noprompt
|
.BI \--noprompt
|
||||||
Do not show the prompt, run and exit.
|
Do not show the prompt, run and exit.
|
||||||
.TP
|
.TP
|
||||||
.BI \-o " " \--open " N"
|
.BI \-o " " \--open " [N]"
|
||||||
Open URL at DB index
|
Open URL at DB index
|
||||||
.I N
|
.I N
|
||||||
in browser.
|
in browser. Open a random index if N is omitted.
|
||||||
.TP
|
.TP
|
||||||
.BI \-z " " \--debug
|
.BI \-z " " \--debug
|
||||||
Show debug information and additional logs.
|
Show debug information and additional logs.
|
||||||
|
Loading…
Reference in New Issue
Block a user