You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1006 B
Bash
38 lines
1006 B
Bash
#!/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
|