Show usage count of tags in listing.
This commit is contained in:
parent
63bce1004d
commit
c6a0ec7b0d
@ -236,7 +236,7 @@ Shell completion scripts for Bash, Fish and Zsh can be found in respective subdi
|
|||||||
- --sall : match all the keywords in URL, title or tags.
|
- --sall : match all the keywords in URL, title or tags.
|
||||||
- --deep : match **substrings** (`match` matches `rematched`) in URL, title and tags.
|
- --deep : match **substrings** (`match` matches `rematched`) in URL, title and tags.
|
||||||
- --sreg : match a regular expression (ignores --deep).
|
- --sreg : match a regular expression (ignores --deep).
|
||||||
- --stag : search bookmarks by a tag, or show all tags alphabetically (if no arguments).
|
- --stag : search bookmarks by a tag, or show all tags alphabetically with usage count (if no arguments).
|
||||||
- Search results are indexed serially. This index is different from actual database index of a bookmark record which is shown in bold within `[]` after the URL.
|
- Search results are indexed serially. This index is different from actual database index of a bookmark record which is shown in bold within `[]` after the URL.
|
||||||
- **Encryption** is optional and manual. AES256 algorithm is used. To use encryption, the database file should be unlocked (-k) before using buku and locked (-l) afterwards. Between these 2 operations, the database file lies unencrypted on the disk, and NOT in memory. Also, note that the database file is *unencrypted on creation*.
|
- **Encryption** is optional and manual. AES256 algorithm is used. To use encryption, the database file should be unlocked (-k) before using buku and locked (-l) afterwards. Between these 2 operations, the database file lies unencrypted on the disk, and NOT in memory. Also, note that the database file is *unencrypted on creation*.
|
||||||
- **Proxy** support: environment variable *https_proxy*, if defined, is used to tunnel data for both http and https connections. The supported format is:
|
- **Proxy** support: environment variable *https_proxy*, if defined, is used to tunnel data for both http and https connections. The supported format is:
|
||||||
|
4
buku.1
4
buku.1
@ -53,7 +53,7 @@ Bookmarks with immutable titles are listed with bold '(L)' after the URL.
|
|||||||
- --sall : match all the keywords in URL, title or tags.
|
- --sall : match all the keywords in URL, title or tags.
|
||||||
- --deep : match \fBsubstrings\fR (`match` matches `rematched`) in URL, title and tags.
|
- --deep : match \fBsubstrings\fR (`match` matches `rematched`) in URL, title and tags.
|
||||||
- --sreg : match a regular expression (ignores --deep).
|
- --sreg : match a regular expression (ignores --deep).
|
||||||
- --stag : search bookmarks by a tag, or show all tags alphabetically (if no arguments).
|
- --stag : search bookmarks by a tag, or show all tags alphabetically with usage count (if no arguments).
|
||||||
- Search results are indexed serially. This index is different from actual database index of a bookmark record which is shown in bold within '[]' after the URL.
|
- Search results are indexed serially. This index is different from actual database index of a bookmark record which is shown in bold within '[]' after the URL.
|
||||||
.PP
|
.PP
|
||||||
\fIEncryption\fR is optional and manual. AES256 algorithm is used. To use encryption, the database file should be unlocked (-k) before using buku and locked (-l) afterwards. Between these 2 operations, the database file lies unencrypted on the disk, and NOT in memory. Also, note that the database file is \fBunencrypted on creation\fR.
|
\fIEncryption\fR is optional and manual. AES256 algorithm is used. To use encryption, the database file should be unlocked (-k) before using buku and locked (-l) afterwards. Between these 2 operations, the database file lies unencrypted on the disk, and NOT in memory. Also, note that the database file is \fBunencrypted on creation\fR.
|
||||||
@ -113,7 +113,7 @@ Scan for a regular expression match.
|
|||||||
Search modifier to match substrings. Works with --sany, --sall.
|
Search modifier to match substrings. Works with --sany, --sall.
|
||||||
.TP
|
.TP
|
||||||
.BI \--stag " [...]"
|
.BI \--stag " [...]"
|
||||||
Search bookmarks by a tag. List all tags alphabetically, if no arguments.
|
Search bookmarks by a tag. List all tags alphabetically, if no arguments. The usage count (number of bookmarks having the tag) is shown within first brackets.
|
||||||
.SH ENCRYPTION OPTIONS
|
.SH ENCRYPTION OPTIONS
|
||||||
.TP
|
.TP
|
||||||
.BI \-l " " \--lock " [N]"
|
.BI \-l " " \--lock " [N]"
|
||||||
|
23
buku.py
23
buku.py
@ -1078,26 +1078,31 @@ class BukuDb:
|
|||||||
'''Get list of tags in DB
|
'''Get list of tags in DB
|
||||||
|
|
||||||
:return: list of unique tags sorted alphabetically
|
:return: list of unique tags sorted alphabetically
|
||||||
|
:return: a dictionary of {tag:usage_count}
|
||||||
'''
|
'''
|
||||||
|
|
||||||
tags = []
|
tags = []
|
||||||
unique_tags = []
|
unique_tags = []
|
||||||
query = 'SELECT DISTINCT tags FROM bookmarks ORDER BY tags'
|
dic = {}
|
||||||
for row in self.cur.execute(query):
|
qry = 'SELECT DISTINCT tags, COUNT(tags) FROM bookmarks GROUP BY tags'
|
||||||
|
for row in self.cur.execute(qry):
|
||||||
tagset = row[0].strip(DELIM).split(DELIM)
|
tagset = row[0].strip(DELIM).split(DELIM)
|
||||||
for tag in tagset:
|
for tag in tagset:
|
||||||
if tag not in tags:
|
if tag not in tags:
|
||||||
|
dic[tag] = row[1]
|
||||||
tags += (tag,)
|
tags += (tag,)
|
||||||
|
else:
|
||||||
|
dic[tag] += row[1]
|
||||||
|
|
||||||
if len(tags) == 0:
|
if len(tags) == 0:
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
if tags[0] == '':
|
if tags[0] == '':
|
||||||
unique_tags = sorted(tags[1:], key=str.lower)
|
unique_tags = sorted(tags[1:])
|
||||||
else:
|
else:
|
||||||
unique_tags = sorted(tags, key=str.lower)
|
unique_tags = sorted(tags)
|
||||||
|
|
||||||
return unique_tags
|
return unique_tags, dic
|
||||||
|
|
||||||
def replace_tag(self, orig, new=None):
|
def replace_tag(self, orig, new=None):
|
||||||
'''Replace orig tags with new tags in DB for all records.
|
'''Replace orig tags with new tags in DB for all records.
|
||||||
@ -1642,7 +1647,7 @@ def taglist_subprompt(obj):
|
|||||||
:return: new command string
|
:return: new command string
|
||||||
'''
|
'''
|
||||||
|
|
||||||
unique_tags = obj.get_all_tags()
|
unique_tags, dic = obj.get_all_tags()
|
||||||
msg = '\x1b[7mbuku (? for help)\x1b[0m '
|
msg = '\x1b[7mbuku (? for help)\x1b[0m '
|
||||||
new_results = True
|
new_results = True
|
||||||
|
|
||||||
@ -1654,7 +1659,7 @@ def taglist_subprompt(obj):
|
|||||||
else:
|
else:
|
||||||
count = 1
|
count = 1
|
||||||
for tag in unique_tags:
|
for tag in unique_tags:
|
||||||
print('%6d. %s' % (count, tag))
|
print('%6d. %s (%d)' % (count, tag, dic[tag]))
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -2401,10 +2406,10 @@ def main():
|
|||||||
if len(args.stag) > 0:
|
if len(args.stag) > 0:
|
||||||
search_results = bdb.search_by_tag(' '.join(args.stag))
|
search_results = bdb.search_by_tag(' '.join(args.stag))
|
||||||
else:
|
else:
|
||||||
unique_tags = bdb.get_all_tags()
|
unique_tags, dic = bdb.get_all_tags()
|
||||||
count = 1
|
count = 1
|
||||||
for tag in unique_tags:
|
for tag in unique_tags:
|
||||||
print('%6d. %s' % (count, tag))
|
print('%6d. %s (%d)' % (count, tag, dic[tag]))
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
if search_results:
|
if search_results:
|
||||||
|
Loading…
Reference in New Issue
Block a user