From 4ab1fade7e1f392ba5a5dbf185098ea62d48208c Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sat, 31 Dec 2016 00:29:57 +0530 Subject: [PATCH] Support opening multiple bookmarks. --- README.md | 5 +++-- auto-completion/fish/buku.fish | 2 +- auto-completion/zsh/_buku | 2 +- buku.1 | 6 ++---- buku.py | 30 ++++++++++++++++++++++-------- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 5f65a84..1093343 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/auto-completion/fish/buku.fish b/auto-completion/fish/buku.fish index 901839f..bc60860 100644 --- a/auto-completion/fish/buku.fish +++ b/auto-completion/fish/buku.fish @@ -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' diff --git a/auto-completion/zsh/_buku b/auto-completion/zsh/_buku index 8ba9f8c..139817f 100644 --- a/auto-completion/zsh/_buku +++ b/auto-completion/zsh/_buku @@ -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)' diff --git a/buku.1 b/buku.1 index bdeff19..74767cf 100644 --- a/buku.1 +++ b/buku.1 @@ -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 diff --git a/buku.py b/buku.py index 15c5030..ea8ca7b 100755 --- a/buku.py +++ b/buku.py @@ -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: