From b84cf93f4a204c45fb4d94c6416362c01fb16fa3 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Sun, 20 Dec 2020 18:22:39 +0000 Subject: [PATCH] Adds list-tags option This will list the tags along with the number of number of times it is used. An optional --noheader flag can be passed after the command to prevent the header being printed. e.g. ``` $ kb list-tags name count ---------------- ----- Linux 2 Authentication 1 Pentesting 1 Enumeration 3 Network Protocol 2 ``` ``` $ kb list-tags --noheader Linux 2 Authentication 1 Pentesting 1 Enumeration 3 Network Protocol 2 ``` This --noheader flag was also added to the list command Close #10 --- inc/tag-management | 17 +++++++++++++++++ kb | 8 +++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/inc/tag-management b/inc/tag-management index 4c5921b..3b1884e 100644 --- a/inc/tag-management +++ b/inc/tag-management @@ -64,3 +64,20 @@ assignTags(){ } + +listTags(){ + vecho "listTags $*" + cd "$dataDir" || return + local header="--header" + [ "$1" = "--noheader" ] && header="" + echo "SELECT tags.name,COUNT(links.id) count + FROM tags LEFT JOIN links ON tags.id = links.tagID + GROUP BY tags.id" | + sqlite3 --column $header "${sqliteFile}" + #echo "SELECT items.id,items.filename,items.title,items.type, + #GROUP_CONCAT(tags.name,',') tags + #FROM items LEFT JOIN links ON items.id = links.itemID + #LEFT JOIN tags ON links.tagID = tags.id + #GROUP BY items.id;" | + # sqlite3 --column --header "${sqliteFile}" +} diff --git a/kb b/kb index 567a1f5..8f6d384 100755 --- a/kb +++ b/kb @@ -204,12 +204,14 @@ gitChange(){ listEntries(){ vecho "listEntries $*" cd "$dataDir" || return + local header="--header" + [ "$1" = "--noheader" ] && header="" echo "SELECT items.id,items.filename,items.title,items.type, GROUP_CONCAT(tags.name,',') tags FROM items LEFT JOIN links ON items.id = links.itemID LEFT JOIN tags ON links.tagID = tags.id GROUP BY items.id;" | - sqlite3 --column --header "${sqliteFile}" + sqlite3 --column $header "${sqliteFile}" } fuzzySelect(){ @@ -301,6 +303,7 @@ mainScript() { new) newFile "${args[@]:1}"; safeExit ;; edit) editFile "${args[@]:1}"; safeExit ;; list) listEntries "${args[@]:1}"; safeExit ;; + list-tags) listTags "${args[@]:1}"; safeExit ;; view) viewFile "${args[@]:1}"; safeExit ;; fuzzy) fuzzySelect "${args[@]:1}"; safeExit ;; deepsearch) deepSearch "${args[@]:1}"; safeExit ;; @@ -341,6 +344,9 @@ usage() { --filetype Type of file ( default md) edit [title] Edit a file list List all files + --noheader Don't include the header + list-tags Lists tags with the number of times its used + --noheader Don't include the header view View a file fuzzy [command] Fuzzy select a file command is what to do with the selected file