-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
44 lines (37 loc) · 1.16 KB
/
init.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
#!/bin/bash
Attention=emblem-important-symbolic.symbolic
Collection=emblem-package
Complete=emblem-installed
Missing=emblem-ohno
Partial=emblem-ok-symbolic.symbolic
Sync=emblem-synchronizing-symbolic.symbolic
_getEmblems(){
gio info -na metadata::emblems "$(realpath -s "${1}")" | awk 'match($0, "metadata::emblems: \\[(.+)\\]",m) { print m[1] }' | sed 's/,/ /g'
}
_setEmblems() {
path="$(realpath -s "${1}")"
[ -e "${path}" ] || return
shift
gio set -nt unset "${path}" metadata::emblems
[ -n "${1}" ] && gio set -nt stringv "${path}" metadata::emblems "${@}"
# poke inotify (refresh nemo) by touching without actually changing the mtime
touch -r "${path}" "${path}"
}
addEmblem() {
declare -A a
for e in $(_getEmblems "${1}"); do a[$e]=$e; done
a[$2]=$2;
_setEmblems "${1}" "${a[@]}"
}
rmEmblem() {
declare -A a
for e in $(_getEmblems "${1}"); do a[$e]=$e; done
unset a[$2]
_setEmblems "${1}" "${a[@]}"
}
toIgnore() {
# emulate python3 glob.escape()
# [[] [?]
pattern=$(sed 's/\(\[\|\?\)/[\1]/g' <<< "$(basename "${1}")")
[ -d "${1}" ] && echo "${pattern}/*" || echo "${pattern}"
}