Support opening multiple bookmarks.

This commit is contained in:
Arun Prakash Jana 2016-12-31 00:29:57 +05:30
parent c86fb880f9
commit 4ab1fade7e
No known key found for this signature in database
GPG Key ID: A75979F35C080412
5 changed files with 29 additions and 16 deletions

View File

@ -197,8 +197,9 @@ Shell completion scripts for Bash, Fish and Zsh can be found in respective subdi
delete oldtag, if no newtag
-j, --json Json formatted output for -p and search
--noprompt do not show the prompt, run and exit
-o, --open [N] open bookmark at DB index N in browser
open a random index if N is omitted
-o, --open [...] open bookmarks in browser by DB index
accepts indices and ranges
open a random index, if no arguments
--shorten N/URL fetch shortened url from tny.im service
accepts either a DB index or a URL
--expand N/URL expand a tny.im shortened url

View File

@ -18,7 +18,7 @@ complete -c buku -s k -l unlock --description 'decrypt database'
complete -c buku -s l -l lock --description 'encrypt database'
complete -c buku -s m -l merge -r --description 'merge another buku database'
complete -c buku -l noprompt --description 'noninteractive mode'
complete -c buku -s o -l open -r --description 'open bookmark in browser'
complete -c buku -s o -l open -r --description 'open bookmarks in browser'
complete -c buku -s p -l print --description 'show bookmark details'
complete -c buku -s r -l replace -r --description 'replace a tag'
complete -c buku -s s -l sany -r --description 'search any keyword'

View File

@ -23,7 +23,7 @@ args=(
'(--markdown)--markdown[markdown mode]'
'(--merge)--merge[merge another buku database]:buku db file'
'(--noprompt)--noprompt[noninteractive mode]'
'(-o --open)'{-o,--open}'[open bookmark in browser]:bookmark index'
'(-o --open)'{-o,--open}'[open bookmarks in browser]:bookmark index'
'(-p --print)'{-p,--print}'[show bookmark details]'
'(-r --replace)'{-r,--replace}'[replace a tag]:tag to replace'
'(-s --sany)'{-s,--sany}'[search any keyword]:keyword(s)'

6
buku.1
View File

@ -182,10 +182,8 @@ Output data formatted as json, works with --print output and search results.
.BI \--noprompt
Do not show the prompt, run and exit.
.TP
.BI \-o " " \--open " [N]"
Open URL at DB index
.I N
in browser. Open a random index if N is omitted.
.BI \-o " " \--open " [...]"
Open bookmarks by DB indices or ranges in browser. Open a random index if argument is omitted.
.TP
.BI \--shorten " N/URL"
Shorten the URL at DB index

30
buku.py
View File

@ -2366,8 +2366,9 @@ def main():
delete oldtag, if no newtag
-j, --json Json formatted output for -p and search
--noprompt do not show the prompt, run and exit
-o, --open [N] open bookmark at DB index N in browser
open a random index if N is omitted
-o, --open [...] open bookmarks in browser by DB index
accepts indices and ranges
open a random index, if no arguments
--shorten N/URL fetch shortened url from tny.im service
accepts either a DB index or a URL
--expand N/URL expand a tny.im shortened url
@ -2387,7 +2388,7 @@ def main():
addarg('-r', '--replace', nargs='+', help=HIDE)
addarg('-j', '--json', action='store_true', help=HIDE)
addarg('--noprompt', action='store_true', help=HIDE)
addarg('-o', '--open', nargs='?', type=int, const=0, help=HIDE)
addarg('-o', '--open', nargs='*', help=HIDE)
addarg('--shorten', nargs=1, help=HIDE)
addarg('--expand', nargs=1, help=HIDE)
addarg('--tacit', action='store_true', help=HIDE)
@ -2595,7 +2596,7 @@ def main():
for _id in range(lower, upper + 1):
bdb.print_rec(_id)
else:
logerr('Invalid index or range')
logerr('Invalid index or range to print')
bdb.close_quit(1)
# Replace a tag in DB
@ -2624,10 +2625,23 @@ def main():
# Open URL in browser
if args.open is not None:
if args.open < 0:
logerr('Index must be >= 0')
bdb.close_quit(1)
bdb.browse_by_index(args.open)
if len(args.open) == 0:
bdb.browse_by_index(0)
else:
for idx in args.open:
if is_int(idx):
bdb.browse_by_index(int(idx))
elif '-' in idx and is_int(idx.split('-')[0]) \
and is_int(idx.split('-')[1]):
lower = int(idx.split('-')[0])
upper = int(idx.split('-')[1])
if lower > upper:
lower, upper = upper, lower
for _id in range(lower, upper + 1):
bdb.browse_by_index(_id)
else:
logerr('Invalid index or range to open')
bdb.close_quit(1)
# Shorten URL
if args.shorten: