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
master
Jonathan Hodgson 4 years ago
parent ac031344d3
commit b84cf93f4a
  1. 17
      inc/tag-management
  2. 8
      kb

@ -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}"
}

8
kb

@ -204,12 +204,14 @@ gitChange(){
listEntries(){ listEntries(){
vecho "listEntries $*" vecho "listEntries $*"
cd "$dataDir" || return cd "$dataDir" || return
local header="--header"
[ "$1" = "--noheader" ] && header=""
echo "SELECT items.id,items.filename,items.title,items.type, echo "SELECT items.id,items.filename,items.title,items.type,
GROUP_CONCAT(tags.name,',') tags GROUP_CONCAT(tags.name,',') tags
FROM items LEFT JOIN links ON items.id = links.itemID FROM items LEFT JOIN links ON items.id = links.itemID
LEFT JOIN tags ON links.tagID = tags.id LEFT JOIN tags ON links.tagID = tags.id
GROUP BY items.id;" | GROUP BY items.id;" |
sqlite3 --column --header "${sqliteFile}" sqlite3 --column $header "${sqliteFile}"
} }
fuzzySelect(){ fuzzySelect(){
@ -301,6 +303,7 @@ mainScript() {
new) newFile "${args[@]:1}"; safeExit ;; new) newFile "${args[@]:1}"; safeExit ;;
edit) editFile "${args[@]:1}"; safeExit ;; edit) editFile "${args[@]:1}"; safeExit ;;
list) listEntries "${args[@]:1}"; safeExit ;; list) listEntries "${args[@]:1}"; safeExit ;;
list-tags) listTags "${args[@]:1}"; safeExit ;;
view) viewFile "${args[@]:1}"; safeExit ;; view) viewFile "${args[@]:1}"; safeExit ;;
fuzzy) fuzzySelect "${args[@]:1}"; safeExit ;; fuzzy) fuzzySelect "${args[@]:1}"; safeExit ;;
deepsearch) deepSearch "${args[@]:1}"; safeExit ;; deepsearch) deepSearch "${args[@]:1}"; safeExit ;;
@ -341,6 +344,9 @@ usage() {
--filetype <type> Type of file ( default md) --filetype <type> Type of file ( default md)
edit [title] Edit a file edit [title] Edit a file
list List all files 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 view View a file
fuzzy [command] Fuzzy select a file fuzzy [command] Fuzzy select a file
command is what to do with the selected file command is what to do with the selected file

Loading…
Cancel
Save