/
search_bookmarks
executable file
·37 lines (28 loc) · 1006 Bytes
/
search_bookmarks
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
#!/usr/bin/env sh
#TODO: make in rust
[ "$#" -gt 0 ] || exit 1
keyword="$1"
SHARED_DB=$HOME/.local/share/sioyek/shared.db
LOCAL_DB=$HOME/.local/share/sioyek/local.db
QUERY="
SELECT document_path as bk_path, desc as bk_desc FROM bookmarks WHERE bk_desc LIKE '%$keyword%'
UNION
SELECT document_path as hi_path, desc as hi_desc FROM highlights WHERE hi_desc LIKE '%$keyword%'
GROUP BY document_path;
"
QUERY="
ATTACH \"$LOCAL_DB\" as local;
SELECT document_hash.path , desc FROM
(SELECT document_path as _hash, bookmarks.desc FROM bookmarks
UNION
SELECT document_path as _hash , highlights.desc FROM highlights)
INNER JOIN document_hash ON _hash = document_hash.hash
"
results="$(sqlite3 $SHARED_DB "$QUERY")"
basenames="$(echo "$results" | awk '{FS="|"; print $1 }' | xargs -I '{}' basename '{}')"
lookup_terms="$(echo "$results" | awk '{FS="|"; print $2}') "
echo "$basenames" "$lookup_terms"
# IFS="\n"
# for line in "$results" ; do
# echo "$line" | awk "{IFS=\"|\"; print $2 }"
# done