-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist_items.sh
executable file
·75 lines (59 loc) · 1.88 KB
/
list_items.sh
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# shellcheck disable=1090,2154
function clean() {
find "${RESULTS_DIR}" -type f -delete
}
trap clean EXIT
function q() {
SEARCH="${1}"
ICON="${2}"
RECENT="${3}"
SKIP="${4}"
log "SEARCH = ${1}, ICON = ${2}, SKIP = ${3}"
log "folderId = ${folderId}, organizationId = ${ORGANIZATION_ID}, collectionId = ${COLLECTION_ID}"
jq \
-L jq \
--rawfile {,"${DATA_DIR}"/}organizations \
--rawfile {,"${DATA_DIR}"/}collections \
--rawfile {,"${DATA_DIR}"/}folders \
--arg folderId "${folderId}" \
--arg organizationId "${ORGANIZATION_ID}" \
--arg collectionId "${COLLECTION_ID}" \
--arg search "${SEARCH}" \
--arg icon "${ICON}" \
--arg recent "${RECENT}" \
--arg skip "${SKIP}" \
-r -f jq/list_items.jq \
"${DATA_DIR}"/items 2>>"${LOG_FILE}"
}
# Refresh lists
if [ $# == 0 ]; then
[ "$(find "${SYNC_FILE}" "${DATA_DIR}" -size 0)" != "" ] && LAST_SYNC=0
[ $((NOW - LAST_SYNC)) -gt $((SyncTime * 60)) ] && saveSync
fi
mkdir -p "${RESULTS_DIR}"
# Get most recent item
getSelection
if [ $((NOW - LAST_FETCH)) -lt "${AUTO_ROTATE}" ] && [ "${old_objectId}" != "" ]; then
log "Recent item: ${old_title} - ${old_objectId} - ${old_subtitle}"
q "${*}" "./icons/Clock.png" "${old_objectId}" >> "${RESULTS_DIR}"/1
else
old_objectId=""
fi
# Get browser matches
if [ $# == 0 ] && [ "${browserURL}" != "" ]; then
log "Browser ${browserURL}"
URL=$(echo "${browserURL}" | awk 'BEGIN { FS="/" } { h = $3 } END { FS="." ; $0 = h ; print $(NF-1) "." $NF }')
q "${URL}" "./icons/${focusedapp}.png" "" "${old_objectId}">> "${RESULTS_DIR}"/2
fi
# List items
q "${*}" "" "" "${old_objectId}" >> "${RESULTS_DIR}"/3
# Check for empty list
S=$(find "${RESULTS_DIR}"/? -size +10c | wc -l)
if [[ "${S}" =~ "0" ]]; then
echo '[ { "title": "No items found", "arg": "", "valid": false,'
mods "" false
echo '} ]'
else
jq -s flatten "${RESULTS_DIR}"/?
fi