From 9b77c22011781543c1c5cdb7945068d50de7b79b Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Wed, 23 Dec 2020 12:08:09 +0000 Subject: [PATCH 1/3] Allow list command to specify which "type" to list Close #15 --- kb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/kb b/kb index b21647f..6ea3460 100755 --- a/kb +++ b/kb @@ -234,11 +234,25 @@ listEntries(){ vecho "listEntries $*" cd "$dataDir" || return local header="--header" - [ "$1" = "--noheader" ] && header="" + local typeorlist="" + while [ "$#" -gt 0 ]; do + case "$1" in + --noheader) header="" ;; + --normal) typeorlist+=" OR items.type = 'normal'" ;; + --assets) typeorlist+=" OR items.type = 'assets'" ;; + --links) typeorlist+=" OR items.type = 'links'" ;; + *) die "invalid list option: '$1'." ;; + esac + shift + done + typeorlist="$(echo "$typeorlist" | sed 's/^ OR //')" + [ -z "$typeorlist" ] && typeorlist="items.type = 'normal'" + 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 + WHERE $typeorlist GROUP BY items.id;" | sqlite3 --column $header "${sqliteFile}" } From 3f02dd3ed5601a466a03f7d5c42b15f518c261ea Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Wed, 23 Dec 2020 12:09:21 +0000 Subject: [PATCH 2/3] Remove unnecessary chunk of commented code --- inc/tag-management | 6 ------ 1 file changed, 6 deletions(-) diff --git a/inc/tag-management b/inc/tag-management index 3b1884e..0e2c006 100644 --- a/inc/tag-management +++ b/inc/tag-management @@ -74,10 +74,4 @@ listTags(){ 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}" } From b532a40f0fb49c574324e2feb6f2c55f6e63bd48 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Wed, 23 Dec 2020 12:32:36 +0000 Subject: [PATCH 3/3] Updates list help message --- kb | 1 + 1 file changed, 1 insertion(+) diff --git a/kb b/kb index 6ea3460..a9d3598 100755 --- a/kb +++ b/kb @@ -337,6 +337,7 @@ usage() { edit [title] Edit a file list List all files --noheader Don't include the header + --normal List items of type \"normal\" list-tags Lists tags with the number of times its used --noheader Don't include the header update [] Updates the database and git repo of a changed file