From 209281dcd98231be16b8c67d05597758ae64f43b Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sun, 6 Oct 2013 15:06:19 +0200 Subject: Add tags command --- lisp/commands.lisp | 14 ++++++++++++++ lisp/queries.lisp | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/lisp/commands.lisp b/lisp/commands.lisp index e92c8b2..2e406ad 100644 --- a/lisp/commands.lisp +++ b/lisp/commands.lisp @@ -128,3 +128,17 @@ remove all tags from bookmark." Print the version number and exit." (format t "clark version ~A~%" version)) + +(defcommand tags (&optional (num 0)) + "List a number of or all tags." + "Usage: clark tags [] + +Print a list of tags and the number of bookmarks tagged with it +ordered by that number. If NUM is given, only print the first NUM +tags." + (let ((num (if (integerp num) num (parse-integer num))) + (counter 1)) + (dolist (tag (tag-list)) + (format t "~30A~10D~%" (car tag) (cadr tag)) + (if (> (incf counter) num 0) + (return))))) diff --git a/lisp/queries.lisp b/lisp/queries.lisp index 0ffb302..a7bdc69 100644 --- a/lisp/queries.lisp +++ b/lisp/queries.lisp @@ -141,3 +141,12 @@ (execute-to-list *db* (sql select "url" from "bookmark")))) + +(defun tag-list () + "Get a list of all tags stored." + (execute-to-list + *db* (sql select "name, COUNT(bookmark_id)" + from "tag" + join "bookmark_tag" on ("tag_id = tag.ROWID") + group by "tag.ROWID" + order by "COUNT(bookmark_id)" desc))) -- cgit v1.2.3-54-g00ecf