Prompt key g - support search by taglist id
This commit is contained in:
parent
348e8ec15a
commit
af9f204e8d
@ -268,11 +268,12 @@ PROMPT KEYS:
|
|||||||
r expression run a regex search
|
r expression run a regex search
|
||||||
t [...] search bookmarks by tags or show taglist
|
t [...] search bookmarks by tags or show taglist
|
||||||
list index after a tag listing shows records with the tag
|
list index after a tag listing shows records with the tag
|
||||||
|
g taglist id|range [...] [>>|>|<<] [record id|range ...]
|
||||||
|
append, set, remove (all or specific) tags
|
||||||
|
search by taglist id(s) if records are omitted
|
||||||
n show next page of search results
|
n show next page of search results
|
||||||
o id|range [...] browse bookmarks by indices and/or ranges
|
o id|range [...] browse bookmarks by indices and/or ranges
|
||||||
p id|range [...] print bookmarks by indices and/or ranges
|
p id|range [...] print bookmarks by indices and/or ranges
|
||||||
g [taglist id|range ...] [>>|>|<<] record id|range [...]
|
|
||||||
append, set, remove (all or specific) tags
|
|
||||||
w [editor|id] edit and add or update a bookmark
|
w [editor|id] edit and add or update a bookmark
|
||||||
c id copy url at search result index to clipboard
|
c id copy url at search result index to clipboard
|
||||||
O toggle try to open in a GUI browser
|
O toggle try to open in a GUI browser
|
||||||
|
6
buku.1
6
buku.1
@ -319,15 +319,15 @@ Run a regular expression search.
|
|||||||
.BI "t" " [...]"
|
.BI "t" " [...]"
|
||||||
Search bookmarks by a tag. List all tags alphabetically, if no arguments. The index of a tag from the tag list can be used to search all bookmarks having the tag. Note that multiple indices and/or ranges do not work with this key.
|
Search bookmarks by a tag. List all tags alphabetically, if no arguments. The index of a tag from the tag list can be used to search all bookmarks having the tag. Note that multiple indices and/or ranges do not work with this key.
|
||||||
.TP
|
.TP
|
||||||
|
.BI "g" " taglist id|range [...] [>>|>|<<] [record id|range ...]"
|
||||||
|
Append, set, remove specific or all tags by indices and/or ranges to bookmark indices and/or ranges (see \fBEXAMPLES\fR section below). Search by space-separated taglist id(s) and/or range if records are omitted.
|
||||||
|
.TP
|
||||||
.BI "o" " id|range [...]"
|
.BI "o" " id|range [...]"
|
||||||
Browse bookmarks by indices and/or ranges.
|
Browse bookmarks by indices and/or ranges.
|
||||||
.TP
|
.TP
|
||||||
.BI "p" " id|range [...]"
|
.BI "p" " id|range [...]"
|
||||||
Print bookmarks by indices and/or ranges.
|
Print bookmarks by indices and/or ranges.
|
||||||
.TP
|
.TP
|
||||||
.BI "g" " [taglist id|range ...] [>>|>|<<] record id|range [...]"
|
|
||||||
Append, set, remove specific or all tags by indices and/or ranges to bookmark indices and/or ranges (see \fBEXAMPLES\fR section below).
|
|
||||||
.TP
|
|
||||||
.BI "w" " [editor|id]"
|
.BI "w" " [editor|id]"
|
||||||
Edit and add or update a bookmark.
|
Edit and add or update a bookmark.
|
||||||
.TP
|
.TP
|
||||||
|
67
buku.py
67
buku.py
@ -1739,6 +1739,39 @@ class BukuDb:
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def get_tagstr_from_taglist(self, id_list, taglist):
|
||||||
|
"""Get a string of delimiter-separated (and enclosed) string
|
||||||
|
of tags from a dictionary of tags by matching ids.
|
||||||
|
|
||||||
|
The inputs are the outputs from BukuDb.get_tag_all().
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
id_list : list
|
||||||
|
List of ids.
|
||||||
|
taglist : list
|
||||||
|
List of tags.
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
str
|
||||||
|
Delimiter separated and enclosed list of tags.
|
||||||
|
"""
|
||||||
|
|
||||||
|
tags = DELIM
|
||||||
|
|
||||||
|
for id in id_list:
|
||||||
|
if is_int(id) and int(id) > 0:
|
||||||
|
tags += taglist[int(id) - 1] + DELIM
|
||||||
|
elif '-' in id:
|
||||||
|
vals = [int(x) for x in id.split('-')]
|
||||||
|
if vals[0] > vals[-1]:
|
||||||
|
vals[0], vals[-1] = vals[-1], vals[0]
|
||||||
|
|
||||||
|
for _id in range(vals[0], vals[-1] + 1):
|
||||||
|
tags += taglist[_id - 1] + DELIM
|
||||||
|
|
||||||
|
return tags
|
||||||
|
|
||||||
def set_tag(self, cmdstr, taglist):
|
def set_tag(self, cmdstr, taglist):
|
||||||
"""Append, overwrite, remove tags using the symbols >>, > and << respectively.
|
"""Append, overwrite, remove tags using the symbols >>, > and << respectively.
|
||||||
|
|
||||||
@ -1752,7 +1785,7 @@ class BukuDb:
|
|||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
int
|
int
|
||||||
Number of indices updated on success, -1 on failure.
|
Number of indices updated on success, -1 on failure, -2 on no symbol found.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not cmdstr or not taglist:
|
if not cmdstr or not taglist:
|
||||||
@ -1772,23 +1805,14 @@ class BukuDb:
|
|||||||
flag = 1
|
flag = 1
|
||||||
|
|
||||||
if not flag:
|
if not flag:
|
||||||
return -1
|
return -2
|
||||||
|
|
||||||
tags = DELIM
|
tags = DELIM
|
||||||
id_list = cmdstr[:index].split()
|
id_list = cmdstr[:index].split()
|
||||||
try:
|
try:
|
||||||
for id in id_list:
|
tags = self.get_tagstr_from_taglist(id_list, taglist)
|
||||||
if is_int(id) and int(id) > 0:
|
if tags == DELIM:
|
||||||
tags += taglist[int(id) - 1] + DELIM
|
return -1
|
||||||
elif '-' in id:
|
|
||||||
vals = [int(x) for x in id.split('-')]
|
|
||||||
if vals[0] > vals[-1]:
|
|
||||||
vals[0], vals[-1] = vals[-1], vals[0]
|
|
||||||
|
|
||||||
for _id in range(vals[0], vals[-1] + 1):
|
|
||||||
tags += taglist[_id - 1] + DELIM
|
|
||||||
else:
|
|
||||||
return -1
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
@ -2574,11 +2598,12 @@ PROMPT KEYS:
|
|||||||
r expression run a regex search
|
r expression run a regex search
|
||||||
t [...] search bookmarks by tags or show taglist
|
t [...] search bookmarks by tags or show taglist
|
||||||
list index after a tag listing shows records with the tag
|
list index after a tag listing shows records with the tag
|
||||||
|
g taglist id|range [...] [>>|>|<<] [record id|range ...]
|
||||||
|
append, set, remove (all or specific) tags
|
||||||
|
search by taglist id(s) if records are omitted
|
||||||
n show next page of search results
|
n show next page of search results
|
||||||
o id|range [...] browse bookmarks by indices and/or ranges
|
o id|range [...] browse bookmarks by indices and/or ranges
|
||||||
p id|range [...] print bookmarks by indices and/or ranges
|
p id|range [...] print bookmarks by indices and/or ranges
|
||||||
g [taglist id|range ...] [>>|>|<<] record id|range [...]
|
|
||||||
append, set, remove (all or specific) tags
|
|
||||||
w [editor|id] edit and add or update a bookmark
|
w [editor|id] edit and add or update a bookmark
|
||||||
c id copy url at search result index to clipboard
|
c id copy url at search result index to clipboard
|
||||||
O toggle try to open in a GUI browser
|
O toggle try to open in a GUI browser
|
||||||
@ -3561,6 +3586,16 @@ def prompt(obj, results, noninteractive=False, deep=False, subprompt=False, sugg
|
|||||||
_count = obj.set_tag(nav[2:], unique_tags)
|
_count = obj.set_tag(nav[2:], unique_tags)
|
||||||
if _count == -1:
|
if _count == -1:
|
||||||
print('Invalid input')
|
print('Invalid input')
|
||||||
|
elif _count == -2:
|
||||||
|
try:
|
||||||
|
tagid_list = nav[2:].split()
|
||||||
|
tagstr = obj.get_tagstr_from_taglist(tagid_list, unique_tags)
|
||||||
|
tagstr = tagstr.strip(DELIM)
|
||||||
|
results = obj.search_by_tag(tagstr)
|
||||||
|
new_results = True
|
||||||
|
cur_index = next_index = 0
|
||||||
|
except Exception:
|
||||||
|
print('Invalid input')
|
||||||
else:
|
else:
|
||||||
print('%d updated' % _count)
|
print('%d updated' % _count)
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user