-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathsearch.sh
More file actions
54 lines (49 loc) · 1.55 KB
/
search.sh
File metadata and controls
54 lines (49 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
myPluginID="$(getNextPluginID)"
myPlugin="plugin$myPluginID"
myPluginCommand="search"
myPluginDescription="Searches for a specific task"
myPluginMethod="querySearch"
eval "$myPlugin=('$myPluginCommand' '$myPluginDescription' '$myPluginMethod')"
querySearch() {
[[ -z "${SEARCH_STRING:-}" ]] && echo 2>&1 "ERROR: Use '-s' to set search string first" && exit 1
sqlite3 "$THINGSDB" "$(getSearchQuery1)"
sqlite3 "$THINGSDB" "$(getSearchQuery2)"
}
getSearchQuery1() {
read -rd '' query <<-SQL || true
SELECT
T1.title as "Title",
date(T1.creationDate,"unixepoch") as "Created",
date(T1.userModificationDate,"unixepoch") as "Modified",
date(T1.deadline,"unixepoch") as "Due",
date(T1.startDate,"unixepoch") as "Start",
date(T1.stopDate,"unixepoch") as "Stopped",
T2.title as "Project",
T3.title as "Area",
"things:///show?id=" || T1.uuid
FROM $TASKTABLE T1
LEFT OUTER JOIN $TASKTABLE T2 ON T1.project = T2.uuid
LEFT OUTER JOIN $AREATABLE T3 ON T1.area = T3.uuid
WHERE T1.$ISNOTTRASHED AND T1.$ISTASK
AND (T1.title LIKE "%$SEARCH_STRING%" OR T2.title LIKE "%$SEARCH_STRING%")
LIMIT $LIMIT_BY
SQL
echo "$query"
}
getSearchQuery2() {
read -rd '' query <<-SQL || true
SELECT
T2.title as "Title",
date(T1.creationDate,"unixepoch") as "Created",
date(T1.userModificationDate,"unixepoch") as "Modified",
date(T1.stopDate,"unixepoch") as "Stopped",
T1.title as "Task"
FROM TMChecklistItem T1
LEFT OUTER JOIN $TASKTABLE T2 ON T1.task = T2.uuid
WHERE T2.$ISNOTTRASHED
AND T1.title LIKE "%$SEARCH_STRING%"
LIMIT $LIMIT_BY
SQL
echo "$query"
}