forked from termux/termux-x11
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtermux-x11-preference
executable file
·64 lines (58 loc) · 1.6 KB
/
termux-x11-preference
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
#!/data/data/com.termux/files/usr/bin/bash
COMMAND=("am" "broadcast" "-a" "com.termux.x11.CHANGE_PREFERENCE" "-p" "com.termux.x11")
help() {
echo "$0 [list] {key:value} [{key2:value2}]..."
exit 1
}
list() {
output="$("${COMMAND[@]}" -e list null 2>&1)"
result=$(sed -n '/result=[0-9]*/{s/.*result=\([0-9]*\).*/\1/p;q;}' <<< "$output")
if [[ "$result" == "0" ]]; then
echo "Something went wrong."
exit 1
fi
if [[ "$result" == "2" ]] || [[ "$result" == "4" ]]; then
echo "$(echo "$output" | sed -z 's/.*data="\([^"]*\)*/\1/' | sed '${s/"$//}')"
exit 0
fi
echo "list: Unexpected result $result"
echo "$output"
exit 1
}
if [ $# -eq 0 ]; then
if [ -t 0 ]; then
help
else
OLD_LENGTH="${#COMMAND[@]}"
while IFS= read -r line || [[ -n "$line" ]]; do
[ -z "$line" ] && continue
key=$(echo "$line" | sed -E 's/^"([^"]+)".*/\1/')
value=$(echo "$line" | sed -E 's/^"[^"]+"="(.*)"/\1/')
COMMAND+=("-e" "$key" "$value")
done
if [[ "$OLD_LENGTH" == "${#COMMAND[@]}" ]]; then
help
fi
fi
fi
while [[ $# -gt 0 ]]; do
case $1 in
list) list;;
*:*) COMMAND+=("-e" "${1%%:*}" "${1#*:}");;
*) echo "Unrecognised option $1"; help
esac
shift
done
output="$("${COMMAND[@]}")"
result=$(sed -n '/result=[0-9]*/{s/.*result=\([0-9]*\).*/\1/p;q;}' <<< "$output")
if [[ "$result" == "0" ]]; then
echo "Something went wrong."
exit 1
fi
if [[ "$result" == "2" ]] || [[ "$result" == "4" ]]; then
echo "$(echo "$output" | sed -z 's/.*data="\([^"]*\)*/\1/' | sed '${s/"$//}')"
exit 0
fi
echo "set: Unexpected result $result"
echo "$output"
exit 1